ezKit 1.10.2__py3-none-any.whl → 1.10.4__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
ezKit/utils.py CHANGED
@@ -13,7 +13,7 @@ from multiprocessing import Pool
13
13
  from multiprocessing.pool import ThreadPool
14
14
  from pathlib import Path
15
15
  from shutil import rmtree
16
- from typing import Any, Callable, List, Union
16
+ from typing import Any, Callable, List, Optional, Union
17
17
  from urllib.parse import ParseResult, urlparse
18
18
  from uuid import uuid4
19
19
 
@@ -1001,46 +1001,45 @@ def datetime_object(
1001
1001
  # --------------------------------------------------------------------------------------------------
1002
1002
 
1003
1003
 
1004
- # run_cmd = bash('echo ok', universal_newlines=True, stdout=PIPE)
1005
- #
1006
- # if run_cmd != None:
1007
- # returncode = run_cmd.returncode
1008
- # outputs = run_cmd.stdout.splitlines()
1009
- # print(returncode, type(returncode))
1010
- # print(outputs, type(outputs))
1011
- #
1012
- # # echo 'echo ok' > /tmp/ok.sh
1013
- # run_script = bash('/tmp/ok.sh', file=True, universal_newlines=True, stdout=PIPE)
1014
- #
1015
- # if run_script != None:
1016
- # returncode = run_script.returncode
1017
- # outputs = run_script.stdout.splitlines()
1018
- # print(returncode, type(returncode))
1019
- # print(outputs, type(outputs))
1020
-
1021
-
1022
1004
  def shell(
1023
1005
  command: str,
1024
1006
  isfile: bool = False,
1025
- sh_shell: str = '/bin/bash',
1026
- sh_option: str | None = None,
1007
+ sh_shell: str = "/bin/bash",
1008
+ sh_option: Optional[str] = None,
1027
1009
  **kwargs
1028
- ) -> subprocess.CompletedProcess | None:
1029
- """run shell command or script"""
1010
+ ) -> Optional[subprocess.CompletedProcess]:
1011
+ """执行 Shell 命令 脚本"""
1012
+
1013
+ # :param command: 需要执行的命令
1014
+ # :param isfile: 是否将命令视为文件路径
1015
+ # :param sh_shell: 使用的 Shell 程序路径
1016
+ # :param sh_option: Shell 执行选项,例如 '-c'
1017
+ # :param kwargs: 其他传递给 subprocess.run 的参数
1018
+ # :return: 返回 subprocess.CompletedProcess 对象,失败时返回 None
1019
+
1030
1020
  try:
1031
- match True:
1032
- case True if not check_file_type(sh_shell, 'file'):
1033
- return None
1034
- case True if isTrue(sh_shell, str) and isTrue(command, str):
1035
- if isfile is True:
1036
- if sh_option is None:
1037
- return subprocess.run([sh_shell, command], **kwargs, check=False)
1038
- return subprocess.run([sh_shell, sh_option, command], **kwargs, check=False)
1039
- if sh_option is None:
1040
- sh_option = '-c'
1041
- return subprocess.run([sh_shell, sh_option, command], **kwargs, check=False)
1042
- case _:
1043
- return None
1021
+
1022
+ # 校验 Shell 程序路径
1023
+ if not check_file_type(sh_shell, "file"):
1024
+ logger.error(f"Invalid shell path: {sh_shell}")
1025
+ return None
1026
+
1027
+ # 校验 command sh_shell 的类型
1028
+ if not (isTrue(sh_shell, str) and isTrue(command, str)):
1029
+ logger.error("Invalid shell or command input.")
1030
+ return None
1031
+
1032
+ # 构造命令
1033
+ if isfile:
1034
+ args = [sh_shell, command] if sh_option is None else [sh_shell, sh_option, command]
1035
+ else:
1036
+ sh_option = sh_option or "-c"
1037
+ args = [sh_shell, sh_option, command]
1038
+
1039
+ logger.info(f"Executing command: {args}")
1040
+
1041
+ return subprocess.run(args, **kwargs, check=False)
1042
+
1044
1043
  except Exception as e:
1045
1044
  logger.exception(e)
1046
1045
  return None
@@ -1229,7 +1228,7 @@ def processor(
1229
1228
  _data_chunks = (
1230
1229
  list_split(process_data, process_num, equally=True)
1231
1230
  if process_num > 1
1232
- else process_data
1231
+ else [process_data]
1233
1232
  )
1234
1233
 
1235
1234
  if not _data_chunks:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ezKit
3
- Version: 1.10.2
3
+ Version: 1.10.4
4
4
  Summary: Easy Kit
5
5
  Author: septvean
6
6
  Author-email: septvean@gmail.com
@@ -9,10 +9,10 @@ ezKit/qywx.py,sha256=X_H4fzP-iEqeDEbumr7D1bXi6dxczaxfO8iyutzy02s,7171
9
9
  ezKit/redis.py,sha256=g2_V4jvq0djRc20jLZkgeAeF_bYrq-Rbl_kHcCUPZcA,1965
10
10
  ezKit/sendemail.py,sha256=tRXCsJm_RfTJ9xEWe_lTQ5kOs2JxHGPXvq0oWA7prq0,7263
11
11
  ezKit/token.py,sha256=HKREyZj_T2S8-aFoFIrBXTaCKExQq4zE66OHXhGHqQg,1750
12
- ezKit/utils.py,sha256=xfubEO3tMaPp9idKst-xwdSuSTtRQfsO-k9FlipnHT4,42515
12
+ ezKit/utils.py,sha256=ILLaptYUSalERbCOhmoq4w0ZNZgj9yurpHEZwjRMZ8w,42387
13
13
  ezKit/xftp.py,sha256=XyIdr_2rxRVLqPofG6fIYWhAMVsFwTyp46dg5P9FLW4,7774
14
- ezKit-1.10.2.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
15
- ezKit-1.10.2.dist-info/METADATA,sha256=BHUZCWlCgc_I0J4s2LbKakrUWMJALLqvIGAm2g0QEww,191
16
- ezKit-1.10.2.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
17
- ezKit-1.10.2.dist-info/top_level.txt,sha256=aYLB_1WODsqNTsTFWcKP-BN0KCTKcV-HZJ4zlHkCFw8,6
18
- ezKit-1.10.2.dist-info/RECORD,,
14
+ ezKit-1.10.4.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
15
+ ezKit-1.10.4.dist-info/METADATA,sha256=uH8X29vT0V5J3nwzW7pwMvgor45UyDqw_1iGCwU_9A4,191
16
+ ezKit-1.10.4.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
17
+ ezKit-1.10.4.dist-info/top_level.txt,sha256=aYLB_1WODsqNTsTFWcKP-BN0KCTKcV-HZJ4zlHkCFw8,6
18
+ ezKit-1.10.4.dist-info/RECORD,,
File without changes