cmdbox 0.5.1.1__py3-none-any.whl → 0.5.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of cmdbox might be problematic. Click here for more details.
- cmdbox/app/app.py +4 -2
- cmdbox/app/auth/signin.py +633 -631
- cmdbox/app/client.py +10 -10
- cmdbox/app/common.py +50 -6
- cmdbox/app/commons/convert.py +9 -0
- cmdbox/app/commons/module.py +113 -113
- cmdbox/app/commons/redis_client.py +40 -29
- cmdbox/app/edge.py +4 -4
- cmdbox/app/features/cli/audit_base.py +135 -0
- cmdbox/app/features/cli/cmdbox_audit_createdb.py +224 -0
- cmdbox/app/features/cli/cmdbox_audit_delete.py +299 -0
- cmdbox/app/features/cli/cmdbox_audit_search.py +350 -0
- cmdbox/app/features/cli/cmdbox_audit_write.py +240 -0
- cmdbox/app/features/cli/cmdbox_client_file_copy.py +207 -207
- cmdbox/app/features/cli/cmdbox_client_file_download.py +207 -207
- cmdbox/app/features/cli/cmdbox_client_file_list.py +193 -193
- cmdbox/app/features/cli/cmdbox_client_file_mkdir.py +191 -191
- cmdbox/app/features/cli/cmdbox_client_file_move.py +199 -199
- cmdbox/app/features/cli/cmdbox_client_file_remove.py +190 -190
- cmdbox/app/features/cli/cmdbox_client_file_rmdir.py +190 -190
- cmdbox/app/features/cli/cmdbox_client_file_upload.py +212 -212
- cmdbox/app/features/cli/cmdbox_client_server_info.py +166 -166
- cmdbox/app/features/cli/cmdbox_server_list.py +88 -88
- cmdbox/app/features/cli/cmdbox_server_stop.py +138 -138
- cmdbox/app/features/web/cmdbox_web_del_cmd.py +2 -0
- cmdbox/app/features/web/cmdbox_web_del_pipe.py +1 -0
- cmdbox/app/features/web/cmdbox_web_do_signin.py +12 -2
- cmdbox/app/features/web/cmdbox_web_do_signout.py +1 -0
- cmdbox/app/features/web/cmdbox_web_exec_cmd.py +25 -1
- cmdbox/app/features/web/cmdbox_web_exec_pipe.py +1 -0
- cmdbox/app/features/web/cmdbox_web_filer download.py +43 -42
- cmdbox/app/features/web/cmdbox_web_filer.py +1 -0
- cmdbox/app/features/web/cmdbox_web_filer_upload.py +65 -64
- cmdbox/app/features/web/cmdbox_web_gui.py +166 -165
- cmdbox/app/features/web/cmdbox_web_load_pin.py +43 -43
- cmdbox/app/features/web/cmdbox_web_raw_pipe.py +87 -87
- cmdbox/app/features/web/cmdbox_web_save_cmd.py +1 -0
- cmdbox/app/features/web/cmdbox_web_save_pin.py +42 -42
- cmdbox/app/features/web/cmdbox_web_save_pipe.py +1 -0
- cmdbox/app/features/web/cmdbox_web_users.py +12 -0
- cmdbox/app/options.py +767 -601
- cmdbox/extensions/features.yml +20 -0
- cmdbox/extensions/sample_project/sample/app/features/cli/sample_client_time.py +82 -82
- cmdbox/extensions/sample_project/sample/app/features/cli/sample_server_time.py +145 -145
- cmdbox/licenses/{LICENSE.Sphinx.8.1.3(BSD License).txt → LICENSE.Sphinx.8.2.3(UNKNOWN).txt} +1 -1
- cmdbox/licenses/{LICENSE.babel.2.16.0(BSD License).txt → LICENSE.babel.2.17.0(BSD License).txt } +1 -1
- cmdbox/licenses/{LICENSE.pkginfo.1.10.0(MIT License).txt → LICENSE.charset-normalizer.3.4.1(MIT License).txt } +1 -1
- cmdbox/licenses/LICENSE.gunicorn.23.0.0(MIT License).txt +23 -0
- cmdbox/licenses/LICENSE.importlib_metadata.8.6.1(Apache Software License).txt +202 -0
- cmdbox/licenses/LICENSE.nh3.0.2.21(MIT).txt +21 -0
- cmdbox/licenses/{LICENSE.pillow.11.0.0(CMU License (MIT-CMU)).txt → LICENSE.pillow.11.1.0(CMU License (MIT-CMU)).txt } +27 -40
- cmdbox/licenses/LICENSE.plyer.2.1.0(MIT License).txt +19 -0
- cmdbox/licenses/LICENSE.prompt_toolkit.3.0.50(BSD License).txt +27 -0
- cmdbox/licenses/LICENSE.psycopg-binary.3.2.6(GNU Lesser General Public License v3 (LGPLv3)).txt +165 -0
- cmdbox/licenses/LICENSE.psycopg-pool.3.2.6(GNU Lesser General Public License v3 (LGPLv3)).txt +165 -0
- cmdbox/licenses/LICENSE.psycopg.3.2.6(GNU Lesser General Public License v3 (LGPLv3)).txt +165 -0
- cmdbox/licenses/LICENSE.pycryptodome.3.22.0(BSD License; Public Domain).txt +61 -0
- cmdbox/licenses/LICENSE.pystray.0.19.5(GNU Lesser General Public License v3 (LGPLv3)).txt +674 -0
- cmdbox/licenses/LICENSE.questionary.2.1.0(MIT License).txt +19 -0
- cmdbox/licenses/LICENSE.roman-numerals-py.3.1.0(CC0 1.0 Universal (CC0 1.0) Public Domain Dedication; Zero-Clause BSD (0BSD)).txt +146 -0
- cmdbox/licenses/{LICENSE.six.1.16.0(MIT License).txt → LICENSE.six.1.17.0(MIT License).txt } +1 -1
- cmdbox/licenses/{LICENSE.charset-normalizer.3.4.0(MIT License).txt → LICENSE.typing-inspection.0.4.0(MIT License).txt } +2 -2
- cmdbox/licenses/LICENSE.tzdata.2025.2(Apache Software License).txt +15 -0
- cmdbox/licenses/files.txt +48 -36
- cmdbox/logconf_audit.yml +30 -0
- cmdbox/logconf_cmdbox.yml +30 -0
- cmdbox/version.py +2 -2
- cmdbox/web/assets/cmdbox/color_mode.css +516 -0
- cmdbox/web/assets/cmdbox/common.js +19 -0
- cmdbox/web/assets/cmdbox/list_cmd.js +89 -43
- cmdbox/web/assets/cmdbox/list_pipe.js +2 -1
- cmdbox/web/assets/cmdbox/main.js +2 -2
- cmdbox/web/assets/cmdbox/result.js +2 -2
- cmdbox/web/assets/cmdbox/signin.js +2 -2
- cmdbox/web/assets/cmdbox/users.js +2 -3
- cmdbox/web/assets/cmdbox/view_result.js +1 -1
- cmdbox/web/assets/filer/main.js +2 -2
- cmdbox/web/filer.html +16 -2
- cmdbox/web/gui.html +21 -2
- cmdbox/web/result.html +15 -1
- cmdbox/web/signin.html +35 -14
- cmdbox/web/users.html +15 -1
- {cmdbox-0.5.1.1.dist-info → cmdbox-0.5.2.dist-info}/METADATA +25 -5
- {cmdbox-0.5.1.1.dist-info → cmdbox-0.5.2.dist-info}/RECORD +117 -97
- {cmdbox-0.5.1.1.dist-info → cmdbox-0.5.2.dist-info}/entry_points.txt +0 -1
- cmdbox/licenses/LICENSE.nh3.0.2.18(MIT).txt +0 -1
- /cmdbox/licenses/{LICENSE.Jinja2.3.1.4(BSD License).txt → LICENSE.Jinja2.3.1.6(BSD License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.Pygments.2.18.0(BSD License).txt → LICENSE.Pygments.2.19.1(BSD License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.anyio.4.6.2.post1(MIT License).txt → LICENSE.anyio.4.9.0(MIT License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.argcomplete.3.5.1(Apache Software License).txt → LICENSE.argcomplete.3.6.1(Apache Software License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.certifi.2024.8.30(Mozilla Public License 2.0 (MPL 2.0)).txt → LICENSE.certifi.2025.1.31(Mozilla Public License 2.0 (MPL 2.0)).txt} +0 -0
- /cmdbox/licenses/{LICENSE.click.8.1.7(BSD License).txt → LICENSE.click.8.1.8(BSD License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.cryptography.43.0.3(Apache Software License; BSD License).txt → LICENSE.cryptography.44.0.2(Apache Software License; BSD License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.fastapi.0.115.5(MIT License).txt → LICENSE.fastapi.0.115.12(MIT License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.importlib_metadata.8.5.0(Apache Software License).txt → LICENSE.id.1.5.0(Apache Software License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.keyring.25.5.0(MIT License).txt → LICENSE.keyring.25.6.0(MIT License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.more-itertools.10.5.0(MIT License).txt → LICENSE.more-itertools.10.6.0(MIT License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.numpy.2.1.3(BSD License).txt → LICENSE.numpy.2.2.4(BSD License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.prettytable.3.12.0(BSD License).txt → LICENSE.prettytable.3.16.0(UNKNOWN).txt} +0 -0
- /cmdbox/licenses/{LICENSE.pydantic.2.10.2(MIT License).txt → LICENSE.pydantic.2.11.1(MIT License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.pydantic_core.2.27.1(MIT License).txt → LICENSE.pydantic_core.2.33.0(MIT License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.python-dotenv.1.0.1(BSD License).txt → LICENSE.python-dotenv.1.1.0(BSD License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.python-multipart.0.0.17(Apache Software License).txt → LICENSE.python-multipart.0.0.20(Apache Software License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.redis.5.2.0(MIT License).txt → LICENSE.redis.5.2.1(MIT License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.rich.13.9.4(MIT License).txt → LICENSE.rich.14.0.0(MIT License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.sphinx-intl.2.3.0(BSD License).txt → LICENSE.sphinx-intl.2.3.1(BSD License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.starlette.0.41.3(BSD License).txt → LICENSE.starlette.0.46.1(BSD License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.tomli.2.1.0(MIT License).txt → LICENSE.tomli.2.2.1(MIT License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.twine.5.1.1(Apache Software License).txt → LICENSE.twine.6.1.0(Apache Software License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.typing_extensions.4.12.2(Python Software Foundation License).txt → LICENSE.typing_extensions.4.13.0(UNKNOWN).txt} +0 -0
- /cmdbox/licenses/{LICENSE.urllib3.2.2.3(MIT License).txt → LICENSE.urllib3.2.3.0(MIT License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.uvicorn.0.32.1(BSD License).txt → LICENSE.uvicorn.0.34.0(BSD License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.watchfiles.1.0.0(MIT License).txt → LICENSE.watchfiles.1.0.4(MIT License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.websockets.14.1(BSD License).txt → LICENSE.websockets.15.0.1(BSD License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.zope.interface.7.1.1(Zope Public License).txt → LICENSE.zope.interface.7.2(Zope Public License).txt} +0 -0
- {cmdbox-0.5.1.1.dist-info → cmdbox-0.5.2.dist-info}/LICENSE +0 -0
- {cmdbox-0.5.1.1.dist-info → cmdbox-0.5.2.dist-info}/WHEEL +0 -0
- {cmdbox-0.5.1.1.dist-info → cmdbox-0.5.2.dist-info}/top_level.txt +0 -0
|
@@ -1,212 +1,212 @@
|
|
|
1
|
-
from cmdbox.app import common, client, feature, filer
|
|
2
|
-
from cmdbox.app.commons import convert, redis_client
|
|
3
|
-
from cmdbox.app.options import Options
|
|
4
|
-
from pathlib import Path
|
|
5
|
-
from typing import Dict, Any, Tuple, List, Union
|
|
6
|
-
import argparse
|
|
7
|
-
import logging
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
class ClientFileUpload(feature.UnsupportEdgeFeature):
|
|
11
|
-
def get_mode(self) -> Union[str, List[str]]:
|
|
12
|
-
"""
|
|
13
|
-
この機能のモードを返します
|
|
14
|
-
|
|
15
|
-
Returns:
|
|
16
|
-
Union[str, List[str]]: モード
|
|
17
|
-
"""
|
|
18
|
-
return 'client'
|
|
19
|
-
|
|
20
|
-
def get_cmd(self):
|
|
21
|
-
"""
|
|
22
|
-
この機能のコマンドを返します
|
|
23
|
-
|
|
24
|
-
Returns:
|
|
25
|
-
str: コマンド
|
|
26
|
-
"""
|
|
27
|
-
return 'file_upload'
|
|
28
|
-
|
|
29
|
-
def get_option(self):
|
|
30
|
-
"""
|
|
31
|
-
この機能のオプションを返します
|
|
32
|
-
|
|
33
|
-
Returns:
|
|
34
|
-
Dict[str, Any]: オプション
|
|
35
|
-
"""
|
|
36
|
-
return dict(
|
|
37
|
-
use_redis=self.USE_REDIS_MEIGHT, nouse_webmode=False,
|
|
38
|
-
discription_ja="データフォルダ配下にファイルをアップロードします。",
|
|
39
|
-
discription_en="Upload a file under the data folder.",
|
|
40
|
-
choice=[
|
|
41
|
-
dict(opt="host", type=Options.T_STR, default=self.default_host, required=True, multi=False, hide=True, choice=None, web="mask",
|
|
42
|
-
discription_ja="Redisサーバーのサービスホストを指定します。",
|
|
43
|
-
discription_en="Specify the service host of the Redis server."),
|
|
44
|
-
dict(opt="port", type=Options.T_INT, default=self.default_port, required=True, multi=False, hide=True, choice=None, web="mask",
|
|
45
|
-
discription_ja="Redisサーバーのサービスポートを指定します。",
|
|
46
|
-
discription_en="Specify the service port of the Redis server."),
|
|
47
|
-
dict(opt="password", type=Options.T_STR, default=self.default_pass, required=True, multi=False, hide=True, choice=None, web="mask",
|
|
48
|
-
discription_ja="Redisサーバーのアクセスパスワード(任意)を指定します。省略時は `password` を使用します。",
|
|
49
|
-
discription_en="Specify the access password of the Redis server (optional). If omitted, `password` is used."),
|
|
50
|
-
dict(opt="svname", type=Options.T_STR, default="server", required=True, multi=False, hide=True, choice=None, web="readonly",
|
|
51
|
-
discription_ja="サーバーのサービス名を指定します。省略時は `server` を使用します。",
|
|
52
|
-
discription_en="Specify the service name of the inference server. If omitted, `server` is used."),
|
|
53
|
-
dict(opt="svpath", type=Options.T_STR, default="/", required=True, multi=False, hide=False, choice=None,
|
|
54
|
-
discription_ja="サーバーのデータフォルダ以下のパスを指定します。",
|
|
55
|
-
discription_en="Specify the directory path to get the list of files.",
|
|
56
|
-
test_true={"server":"/file_server/upload",
|
|
57
|
-
"client":"/file_client/upload",
|
|
58
|
-
"current":"/file_current/upload"}),
|
|
59
|
-
dict(opt="scope", type=Options.T_STR, default="client", required=True, multi=False, hide=False, choice=["client", "current", "server"],
|
|
60
|
-
discription_ja="参照先スコープを指定します。指定可能な画像タイプは `client` , `current` , `server` です。",
|
|
61
|
-
discription_en="Specifies the scope to be referenced. When omitted, 'client' is used.",
|
|
62
|
-
choice_show=dict(client=["client_data"]),
|
|
63
|
-
test_true={"server":"server",
|
|
64
|
-
"client":"client",
|
|
65
|
-
"current":"current"}),
|
|
66
|
-
dict(opt="upload_file", type=Options.T_FILE, default=None, required=False, multi=False, hide=False, choice=None, fileio="out",
|
|
67
|
-
discription_ja="クライアントのアップロード元パスを指定します。",
|
|
68
|
-
discription_en="Specify the source path of the client.",
|
|
69
|
-
test_true={"server":"tests/dog.jpg"}),
|
|
70
|
-
dict(opt="client_data", type=Options.T_STR, default=None, required=False, multi=False, hide=False, choice=None,
|
|
71
|
-
discription_ja="ローカルを参照させる場合のデータフォルダのパスを指定します。",
|
|
72
|
-
discription_en="Specify the path of the data folder when local is referenced.",
|
|
73
|
-
test_true={"server":None,
|
|
74
|
-
"client":common.HOME_DIR / f".{self.ver.__appid__}",
|
|
75
|
-
"current":None}),
|
|
76
|
-
dict(opt="mkdir", type=Options.T_BOOL, default=False, required=False, multi=False, hide=True, choice=[True, False],
|
|
77
|
-
discription_ja="中間フォルダがない場合作成します。",
|
|
78
|
-
discription_en="If there is no in between folder, create one.",
|
|
79
|
-
test_true={"server":True}),
|
|
80
|
-
dict(opt="orverwrite", type=Options.T_BOOL, default=False, required=False, multi=False, hide=True, choice=[True, False],
|
|
81
|
-
discription_ja="アップロード先に存在していても上書きします。",
|
|
82
|
-
discription_en="Overwrites the file even if it exists at the upload destination."),
|
|
83
|
-
dict(opt="retry_count", type=Options.T_INT, default=3, required=False, multi=False, hide=True, choice=None,
|
|
84
|
-
discription_ja="Redisサーバーへの再接続回数を指定します。0以下を指定すると永遠に再接続を行います。",
|
|
85
|
-
discription_en="Specifies the number of reconnections to the Redis server.If less than 0 is specified, reconnection is forever."),
|
|
86
|
-
dict(opt="retry_interval", type=Options.T_INT, default=5, required=False, multi=False, hide=True, choice=None,
|
|
87
|
-
discription_ja="Redisサーバーに再接続までの秒数を指定します。",
|
|
88
|
-
discription_en="Specifies the number of seconds before reconnecting to the Redis server."),
|
|
89
|
-
dict(opt="timeout", type=Options.T_INT, default="15", required=False, multi=False, hide=True, choice=None,
|
|
90
|
-
discription_ja="サーバーの応答が返ってくるまでの最大待ち時間を指定。",
|
|
91
|
-
discription_en="Specify the maximum waiting time until the server responds."),
|
|
92
|
-
dict(opt="output_json", short="o", type=Options.T_FILE, default=None, required=False, multi=False, hide=True, choice=None, fileio="out",
|
|
93
|
-
discription_ja="処理結果jsonの保存先ファイルを指定。",
|
|
94
|
-
discription_en="Specify the destination file for saving the processing result json."),
|
|
95
|
-
dict(opt="output_json_append", short="a", type=Options.T_BOOL, default=False, required=False, multi=False, hide=True, choice=[True, False],
|
|
96
|
-
discription_ja="処理結果jsonファイルを追記保存します。",
|
|
97
|
-
discription_en="Save the processing result json file by appending."),
|
|
98
|
-
dict(opt="stdout_log", type=Options.T_BOOL, default=True, required=False, multi=False, hide=True, choice=[True, False],
|
|
99
|
-
discription_ja="GUIモードでのみ使用可能です。コマンド実行時の標準出力をConsole logに出力します。",
|
|
100
|
-
discription_en="Available only in GUI mode. Outputs standard output during command execution to Console log."),
|
|
101
|
-
dict(opt="capture_stdout", type=Options.T_BOOL, default=True, required=False, multi=False, hide=True, choice=[True, False],
|
|
102
|
-
discription_ja="GUIモードでのみ使用可能です。コマンド実行時の標準出力をキャプチャーし、実行結果画面に表示します。",
|
|
103
|
-
discription_en="Available only in GUI mode. Captures standard output during command execution and displays it on the execution result screen."),
|
|
104
|
-
dict(opt="capture_maxsize", type=Options.T_INT, default=self.DEFAULT_CAPTURE_MAXSIZE, required=False, multi=False, hide=True, choice=None,
|
|
105
|
-
discription_ja="GUIモードでのみ使用可能です。コマンド実行時の標準出力の最大キャプチャーサイズを指定します。",
|
|
106
|
-
discription_en="Available only in GUI mode. Specifies the maximum capture size of standard output when executing commands."),
|
|
107
|
-
]
|
|
108
|
-
)
|
|
109
|
-
|
|
110
|
-
def get_svcmd(self):
|
|
111
|
-
"""
|
|
112
|
-
この機能のサーバー側のコマンドを返します
|
|
113
|
-
|
|
114
|
-
Returns:
|
|
115
|
-
str: サーバー側のコマンド
|
|
116
|
-
"""
|
|
117
|
-
return 'file_upload'
|
|
118
|
-
|
|
119
|
-
def apprun(self, logger:logging.Logger, args:argparse.Namespace, tm:float, pf:List[Dict[str, float]]=[]) -> Tuple[int, Dict[str, Any], Any]:
|
|
120
|
-
"""
|
|
121
|
-
この機能の実行を行います
|
|
122
|
-
|
|
123
|
-
Args:
|
|
124
|
-
logger (logging.Logger): ロガー
|
|
125
|
-
args (argparse.Namespace): 引数
|
|
126
|
-
tm (float): 実行開始時間
|
|
127
|
-
pf (List[Dict[str, float]]): 呼出元のパフォーマンス情報
|
|
128
|
-
|
|
129
|
-
Returns:
|
|
130
|
-
Tuple[int, Dict[str, Any], Any]: 終了コード, 結果, オブジェクト
|
|
131
|
-
"""
|
|
132
|
-
if args.svname is None:
|
|
133
|
-
msg = dict(warn=f"Please specify the --svname option.")
|
|
134
|
-
common.print_format(msg, args.format, tm, args.output_json, args.output_json_append, pf=pf)
|
|
135
|
-
return 1, msg, None
|
|
136
|
-
cl = client.Client(logger, redis_host=args.host, redis_port=args.port, redis_password=args.password, svname=args.svname)
|
|
137
|
-
|
|
138
|
-
client_data = Path(args.client_data.replace('"','')) if args.client_data is not None else None
|
|
139
|
-
upload_file = Path(args.upload_file.replace('"','')) if args.upload_file is not None else None
|
|
140
|
-
ret = cl.file_upload(args.svpath.replace('"',''), upload_file, scope=args.scope, client_data=client_data,
|
|
141
|
-
mkdir=args.mkdir, orverwrite=args.orverwrite,
|
|
142
|
-
retry_count=args.retry_count, retry_interval=args.retry_interval, timeout=args.timeout)
|
|
143
|
-
common.print_format(ret, args.format, tm, args.output_json, args.output_json_append, pf=pf)
|
|
144
|
-
|
|
145
|
-
if 'success' not in ret:
|
|
146
|
-
return 1, ret, cl
|
|
147
|
-
|
|
148
|
-
return 0, ret, cl
|
|
149
|
-
|
|
150
|
-
def is_cluster_redirect(self):
|
|
151
|
-
"""
|
|
152
|
-
クラスター宛のメッセージの場合、メッセージを転送するかどうかを返します
|
|
153
|
-
|
|
154
|
-
Returns:
|
|
155
|
-
bool: メッセージを転送する場合はTrue
|
|
156
|
-
"""
|
|
157
|
-
return True
|
|
158
|
-
|
|
159
|
-
def svrun(self, data_dir:Path, logger:logging.Logger, redis_cli:redis_client.RedisClient, msg:List[str],
|
|
160
|
-
sessions:Dict[str, Dict[str, Any]]) -> int:
|
|
161
|
-
"""
|
|
162
|
-
この機能のサーバー側の実行を行います
|
|
163
|
-
|
|
164
|
-
Args:
|
|
165
|
-
data_dir (Path): データディレクトリ
|
|
166
|
-
logger (logging.Logger): ロガー
|
|
167
|
-
redis_cli (redis_client.RedisClient): Redisクライアント
|
|
168
|
-
msg (List[str]): 受信メッセージ
|
|
169
|
-
sessions (Dict[str, Dict[str, Any]]): セッション情報
|
|
170
|
-
|
|
171
|
-
Returns:
|
|
172
|
-
int: 終了コード
|
|
173
|
-
"""
|
|
174
|
-
svpath = convert.b64str2str(msg[2])
|
|
175
|
-
file_name = convert.b64str2str(msg[3])
|
|
176
|
-
file_data = convert.b64str2bytes(msg[4])
|
|
177
|
-
mkdir = msg[5]=='True'
|
|
178
|
-
orverwrite = msg[6]=='True'
|
|
179
|
-
st = self.file_upload(msg[1], svpath, file_name, file_data, mkdir, orverwrite, data_dir, logger, redis_cli, sessions)
|
|
180
|
-
return st
|
|
181
|
-
|
|
182
|
-
def file_upload(self, reskey:str, current_path:str, file_name:str, file_data:bytes, mkdir:bool, orverwrite:bool,
|
|
183
|
-
data_dir:Path, logger:logging.Logger, redis_cli:redis_client.RedisClient, sessions:Dict[str, Dict[str, Any]]) -> int:
|
|
184
|
-
"""
|
|
185
|
-
ファイルをアップロードする
|
|
186
|
-
|
|
187
|
-
Args:
|
|
188
|
-
reskey (str): レスポンスキー
|
|
189
|
-
current_path (str): ファイルパス
|
|
190
|
-
file_name (str): ファイル名
|
|
191
|
-
file_data (bytes): ファイルデータ
|
|
192
|
-
mkdir (bool): ディレクトリを作成するかどうか
|
|
193
|
-
orverwrite (bool): 上書きするかどうか
|
|
194
|
-
data_dir (Path): データディレクトリ
|
|
195
|
-
logger (logging.Logger): ロガー
|
|
196
|
-
redis_cli (redis_client.RedisClient): Redisクライアント
|
|
197
|
-
sessions (Dict[str, Dict[str, Any]]): セッション情報
|
|
198
|
-
|
|
199
|
-
Returns:
|
|
200
|
-
int: レスポンスコード
|
|
201
|
-
"""
|
|
202
|
-
try:
|
|
203
|
-
f = filer.Filer(data_dir, logger)
|
|
204
|
-
rescode, msg = f.file_upload(current_path, file_name, file_data, mkdir, orverwrite)
|
|
205
|
-
redis_cli.rpush(reskey, msg)
|
|
206
|
-
return rescode
|
|
207
|
-
except Exception as e:
|
|
208
|
-
logger.warning(f"Failed to upload file: {e}", exc_info=True)
|
|
209
|
-
redis_cli.rpush(reskey, dict(warn=f"Failed to upload file: {e}"))
|
|
210
|
-
return self.RESP_WARN
|
|
211
|
-
|
|
212
|
-
|
|
1
|
+
from cmdbox.app import common, client, feature, filer
|
|
2
|
+
from cmdbox.app.commons import convert, redis_client
|
|
3
|
+
from cmdbox.app.options import Options
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import Dict, Any, Tuple, List, Union
|
|
6
|
+
import argparse
|
|
7
|
+
import logging
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class ClientFileUpload(feature.UnsupportEdgeFeature):
|
|
11
|
+
def get_mode(self) -> Union[str, List[str]]:
|
|
12
|
+
"""
|
|
13
|
+
この機能のモードを返します
|
|
14
|
+
|
|
15
|
+
Returns:
|
|
16
|
+
Union[str, List[str]]: モード
|
|
17
|
+
"""
|
|
18
|
+
return 'client'
|
|
19
|
+
|
|
20
|
+
def get_cmd(self):
|
|
21
|
+
"""
|
|
22
|
+
この機能のコマンドを返します
|
|
23
|
+
|
|
24
|
+
Returns:
|
|
25
|
+
str: コマンド
|
|
26
|
+
"""
|
|
27
|
+
return 'file_upload'
|
|
28
|
+
|
|
29
|
+
def get_option(self):
|
|
30
|
+
"""
|
|
31
|
+
この機能のオプションを返します
|
|
32
|
+
|
|
33
|
+
Returns:
|
|
34
|
+
Dict[str, Any]: オプション
|
|
35
|
+
"""
|
|
36
|
+
return dict(
|
|
37
|
+
use_redis=self.USE_REDIS_MEIGHT, nouse_webmode=False,
|
|
38
|
+
discription_ja="データフォルダ配下にファイルをアップロードします。",
|
|
39
|
+
discription_en="Upload a file under the data folder.",
|
|
40
|
+
choice=[
|
|
41
|
+
dict(opt="host", type=Options.T_STR, default=self.default_host, required=True, multi=False, hide=True, choice=None, web="mask",
|
|
42
|
+
discription_ja="Redisサーバーのサービスホストを指定します。",
|
|
43
|
+
discription_en="Specify the service host of the Redis server."),
|
|
44
|
+
dict(opt="port", type=Options.T_INT, default=self.default_port, required=True, multi=False, hide=True, choice=None, web="mask",
|
|
45
|
+
discription_ja="Redisサーバーのサービスポートを指定します。",
|
|
46
|
+
discription_en="Specify the service port of the Redis server."),
|
|
47
|
+
dict(opt="password", type=Options.T_STR, default=self.default_pass, required=True, multi=False, hide=True, choice=None, web="mask",
|
|
48
|
+
discription_ja="Redisサーバーのアクセスパスワード(任意)を指定します。省略時は `password` を使用します。",
|
|
49
|
+
discription_en="Specify the access password of the Redis server (optional). If omitted, `password` is used."),
|
|
50
|
+
dict(opt="svname", type=Options.T_STR, default="server", required=True, multi=False, hide=True, choice=None, web="readonly",
|
|
51
|
+
discription_ja="サーバーのサービス名を指定します。省略時は `server` を使用します。",
|
|
52
|
+
discription_en="Specify the service name of the inference server. If omitted, `server` is used."),
|
|
53
|
+
dict(opt="svpath", type=Options.T_STR, default="/", required=True, multi=False, hide=False, choice=None,
|
|
54
|
+
discription_ja="サーバーのデータフォルダ以下のパスを指定します。",
|
|
55
|
+
discription_en="Specify the directory path to get the list of files.",
|
|
56
|
+
test_true={"server":"/file_server/upload",
|
|
57
|
+
"client":"/file_client/upload",
|
|
58
|
+
"current":"/file_current/upload"}),
|
|
59
|
+
dict(opt="scope", type=Options.T_STR, default="client", required=True, multi=False, hide=False, choice=["client", "current", "server"],
|
|
60
|
+
discription_ja="参照先スコープを指定します。指定可能な画像タイプは `client` , `current` , `server` です。",
|
|
61
|
+
discription_en="Specifies the scope to be referenced. When omitted, 'client' is used.",
|
|
62
|
+
choice_show=dict(client=["client_data"]),
|
|
63
|
+
test_true={"server":"server",
|
|
64
|
+
"client":"client",
|
|
65
|
+
"current":"current"}),
|
|
66
|
+
dict(opt="upload_file", type=Options.T_FILE, default=None, required=False, multi=False, hide=False, choice=None, fileio="out",
|
|
67
|
+
discription_ja="クライアントのアップロード元パスを指定します。",
|
|
68
|
+
discription_en="Specify the source path of the client.",
|
|
69
|
+
test_true={"server":"tests/dog.jpg"}),
|
|
70
|
+
dict(opt="client_data", type=Options.T_STR, default=None, required=False, multi=False, hide=False, choice=None,
|
|
71
|
+
discription_ja="ローカルを参照させる場合のデータフォルダのパスを指定します。",
|
|
72
|
+
discription_en="Specify the path of the data folder when local is referenced.",
|
|
73
|
+
test_true={"server":None,
|
|
74
|
+
"client":common.HOME_DIR / f".{self.ver.__appid__}",
|
|
75
|
+
"current":None}),
|
|
76
|
+
dict(opt="mkdir", type=Options.T_BOOL, default=False, required=False, multi=False, hide=True, choice=[True, False],
|
|
77
|
+
discription_ja="中間フォルダがない場合作成します。",
|
|
78
|
+
discription_en="If there is no in between folder, create one.",
|
|
79
|
+
test_true={"server":True}),
|
|
80
|
+
dict(opt="orverwrite", type=Options.T_BOOL, default=False, required=False, multi=False, hide=True, choice=[True, False],
|
|
81
|
+
discription_ja="アップロード先に存在していても上書きします。",
|
|
82
|
+
discription_en="Overwrites the file even if it exists at the upload destination."),
|
|
83
|
+
dict(opt="retry_count", type=Options.T_INT, default=3, required=False, multi=False, hide=True, choice=None,
|
|
84
|
+
discription_ja="Redisサーバーへの再接続回数を指定します。0以下を指定すると永遠に再接続を行います。",
|
|
85
|
+
discription_en="Specifies the number of reconnections to the Redis server.If less than 0 is specified, reconnection is forever."),
|
|
86
|
+
dict(opt="retry_interval", type=Options.T_INT, default=5, required=False, multi=False, hide=True, choice=None,
|
|
87
|
+
discription_ja="Redisサーバーに再接続までの秒数を指定します。",
|
|
88
|
+
discription_en="Specifies the number of seconds before reconnecting to the Redis server."),
|
|
89
|
+
dict(opt="timeout", type=Options.T_INT, default="15", required=False, multi=False, hide=True, choice=None,
|
|
90
|
+
discription_ja="サーバーの応答が返ってくるまでの最大待ち時間を指定。",
|
|
91
|
+
discription_en="Specify the maximum waiting time until the server responds."),
|
|
92
|
+
dict(opt="output_json", short="o", type=Options.T_FILE, default=None, required=False, multi=False, hide=True, choice=None, fileio="out",
|
|
93
|
+
discription_ja="処理結果jsonの保存先ファイルを指定。",
|
|
94
|
+
discription_en="Specify the destination file for saving the processing result json."),
|
|
95
|
+
dict(opt="output_json_append", short="a", type=Options.T_BOOL, default=False, required=False, multi=False, hide=True, choice=[True, False],
|
|
96
|
+
discription_ja="処理結果jsonファイルを追記保存します。",
|
|
97
|
+
discription_en="Save the processing result json file by appending."),
|
|
98
|
+
dict(opt="stdout_log", type=Options.T_BOOL, default=True, required=False, multi=False, hide=True, choice=[True, False],
|
|
99
|
+
discription_ja="GUIモードでのみ使用可能です。コマンド実行時の標準出力をConsole logに出力します。",
|
|
100
|
+
discription_en="Available only in GUI mode. Outputs standard output during command execution to Console log."),
|
|
101
|
+
dict(opt="capture_stdout", type=Options.T_BOOL, default=True, required=False, multi=False, hide=True, choice=[True, False],
|
|
102
|
+
discription_ja="GUIモードでのみ使用可能です。コマンド実行時の標準出力をキャプチャーし、実行結果画面に表示します。",
|
|
103
|
+
discription_en="Available only in GUI mode. Captures standard output during command execution and displays it on the execution result screen."),
|
|
104
|
+
dict(opt="capture_maxsize", type=Options.T_INT, default=self.DEFAULT_CAPTURE_MAXSIZE, required=False, multi=False, hide=True, choice=None,
|
|
105
|
+
discription_ja="GUIモードでのみ使用可能です。コマンド実行時の標準出力の最大キャプチャーサイズを指定します。",
|
|
106
|
+
discription_en="Available only in GUI mode. Specifies the maximum capture size of standard output when executing commands."),
|
|
107
|
+
]
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
def get_svcmd(self):
|
|
111
|
+
"""
|
|
112
|
+
この機能のサーバー側のコマンドを返します
|
|
113
|
+
|
|
114
|
+
Returns:
|
|
115
|
+
str: サーバー側のコマンド
|
|
116
|
+
"""
|
|
117
|
+
return 'file_upload'
|
|
118
|
+
|
|
119
|
+
def apprun(self, logger:logging.Logger, args:argparse.Namespace, tm:float, pf:List[Dict[str, float]]=[]) -> Tuple[int, Dict[str, Any], Any]:
|
|
120
|
+
"""
|
|
121
|
+
この機能の実行を行います
|
|
122
|
+
|
|
123
|
+
Args:
|
|
124
|
+
logger (logging.Logger): ロガー
|
|
125
|
+
args (argparse.Namespace): 引数
|
|
126
|
+
tm (float): 実行開始時間
|
|
127
|
+
pf (List[Dict[str, float]]): 呼出元のパフォーマンス情報
|
|
128
|
+
|
|
129
|
+
Returns:
|
|
130
|
+
Tuple[int, Dict[str, Any], Any]: 終了コード, 結果, オブジェクト
|
|
131
|
+
"""
|
|
132
|
+
if args.svname is None:
|
|
133
|
+
msg = dict(warn=f"Please specify the --svname option.")
|
|
134
|
+
common.print_format(msg, args.format, tm, args.output_json, args.output_json_append, pf=pf)
|
|
135
|
+
return 1, msg, None
|
|
136
|
+
cl = client.Client(logger, redis_host=args.host, redis_port=args.port, redis_password=args.password, svname=args.svname)
|
|
137
|
+
|
|
138
|
+
client_data = Path(args.client_data.replace('"','')) if args.client_data is not None else None
|
|
139
|
+
upload_file = Path(args.upload_file.replace('"','')) if args.upload_file is not None else None
|
|
140
|
+
ret = cl.file_upload(args.svpath.replace('"',''), upload_file, scope=args.scope, client_data=client_data,
|
|
141
|
+
mkdir=args.mkdir, orverwrite=args.orverwrite,
|
|
142
|
+
retry_count=args.retry_count, retry_interval=args.retry_interval, timeout=args.timeout)
|
|
143
|
+
common.print_format(ret, args.format, tm, args.output_json, args.output_json_append, pf=pf)
|
|
144
|
+
|
|
145
|
+
if 'success' not in ret:
|
|
146
|
+
return 1, ret, cl
|
|
147
|
+
|
|
148
|
+
return 0, ret, cl
|
|
149
|
+
|
|
150
|
+
def is_cluster_redirect(self):
|
|
151
|
+
"""
|
|
152
|
+
クラスター宛のメッセージの場合、メッセージを転送するかどうかを返します
|
|
153
|
+
|
|
154
|
+
Returns:
|
|
155
|
+
bool: メッセージを転送する場合はTrue
|
|
156
|
+
"""
|
|
157
|
+
return True
|
|
158
|
+
|
|
159
|
+
def svrun(self, data_dir:Path, logger:logging.Logger, redis_cli:redis_client.RedisClient, msg:List[str],
|
|
160
|
+
sessions:Dict[str, Dict[str, Any]]) -> int:
|
|
161
|
+
"""
|
|
162
|
+
この機能のサーバー側の実行を行います
|
|
163
|
+
|
|
164
|
+
Args:
|
|
165
|
+
data_dir (Path): データディレクトリ
|
|
166
|
+
logger (logging.Logger): ロガー
|
|
167
|
+
redis_cli (redis_client.RedisClient): Redisクライアント
|
|
168
|
+
msg (List[str]): 受信メッセージ
|
|
169
|
+
sessions (Dict[str, Dict[str, Any]]): セッション情報
|
|
170
|
+
|
|
171
|
+
Returns:
|
|
172
|
+
int: 終了コード
|
|
173
|
+
"""
|
|
174
|
+
svpath = convert.b64str2str(msg[2])
|
|
175
|
+
file_name = convert.b64str2str(msg[3])
|
|
176
|
+
file_data = convert.b64str2bytes(msg[4])
|
|
177
|
+
mkdir = msg[5]=='True'
|
|
178
|
+
orverwrite = msg[6]=='True'
|
|
179
|
+
st = self.file_upload(msg[1], svpath, file_name, file_data, mkdir, orverwrite, data_dir, logger, redis_cli, sessions)
|
|
180
|
+
return st
|
|
181
|
+
|
|
182
|
+
def file_upload(self, reskey:str, current_path:str, file_name:str, file_data:bytes, mkdir:bool, orverwrite:bool,
|
|
183
|
+
data_dir:Path, logger:logging.Logger, redis_cli:redis_client.RedisClient, sessions:Dict[str, Dict[str, Any]]) -> int:
|
|
184
|
+
"""
|
|
185
|
+
ファイルをアップロードする
|
|
186
|
+
|
|
187
|
+
Args:
|
|
188
|
+
reskey (str): レスポンスキー
|
|
189
|
+
current_path (str): ファイルパス
|
|
190
|
+
file_name (str): ファイル名
|
|
191
|
+
file_data (bytes): ファイルデータ
|
|
192
|
+
mkdir (bool): ディレクトリを作成するかどうか
|
|
193
|
+
orverwrite (bool): 上書きするかどうか
|
|
194
|
+
data_dir (Path): データディレクトリ
|
|
195
|
+
logger (logging.Logger): ロガー
|
|
196
|
+
redis_cli (redis_client.RedisClient): Redisクライアント
|
|
197
|
+
sessions (Dict[str, Dict[str, Any]]): セッション情報
|
|
198
|
+
|
|
199
|
+
Returns:
|
|
200
|
+
int: レスポンスコード
|
|
201
|
+
"""
|
|
202
|
+
try:
|
|
203
|
+
f = filer.Filer(data_dir, logger)
|
|
204
|
+
rescode, msg = f.file_upload(current_path, file_name, file_data, mkdir, orverwrite)
|
|
205
|
+
redis_cli.rpush(reskey, msg)
|
|
206
|
+
return rescode
|
|
207
|
+
except Exception as e:
|
|
208
|
+
logger.warning(f"Failed to upload file: {e}", exc_info=True)
|
|
209
|
+
redis_cli.rpush(reskey, dict(warn=f"Failed to upload file: {e}"))
|
|
210
|
+
return self.RESP_WARN
|
|
211
|
+
|
|
212
|
+
|