toolkits 0.2.7__tar.gz → 0.2.9__tar.gz

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.
Files changed (58) hide show
  1. {toolkits-0.2.7 → toolkits-0.2.9}/PKG-INFO +1 -1
  2. {toolkits-0.2.7 → toolkits-0.2.9}/pyproject.toml +1 -1
  3. {toolkits-0.2.7/src/toolkits/libs_core → toolkits-0.2.9/src/toolkits/config_parser}/config_helper.py +1 -1
  4. {toolkits-0.2.7/src/toolkits/libs_core → toolkits-0.2.9/src/toolkits/config_parser}/env_prepare.py +1 -1
  5. {toolkits-0.2.7 → toolkits-0.2.9}/src/toolkits/db_query_demo.py +2 -3
  6. {toolkits-0.2.7 → toolkits-0.2.9}/src/toolkits/system/shell_helper.py +53 -14
  7. {toolkits-0.2.7 → toolkits-0.2.9}/src/toolkits/tookits_cli.py +1 -2
  8. toolkits-0.2.9/tests/test_shell_helper.py +6 -0
  9. {toolkits-0.2.7 → toolkits-0.2.9}/tests/test_tookits.py +1 -1
  10. {toolkits-0.2.7 → toolkits-0.2.9}/README.md +0 -0
  11. {toolkits-0.2.7 → toolkits-0.2.9}/src/toolkits/3des/3des.py +0 -0
  12. {toolkits-0.2.7 → toolkits-0.2.9}/src/toolkits/3des/__init__.py +0 -0
  13. {toolkits-0.2.7 → toolkits-0.2.9}/src/toolkits/__init__.py +0 -0
  14. {toolkits-0.2.7 → toolkits-0.2.9}/src/toolkits/basic/__init__.py +0 -0
  15. {toolkits-0.2.7 → toolkits-0.2.9}/src/toolkits/basic/list_helper.py +0 -0
  16. {toolkits-0.2.7/src/toolkits/config → toolkits-0.2.9/src/toolkits/config_parser}/__init__.py +0 -0
  17. {toolkits-0.2.7/src/toolkits/config → toolkits-0.2.9/src/toolkits/config_parser}/config_demo.py +0 -0
  18. {toolkits-0.2.7/src/toolkits/libs_core → toolkits-0.2.9/src/toolkits/config_parser}/config_groups_helper.py +0 -0
  19. {toolkits-0.2.7 → toolkits-0.2.9}/src/toolkits/databases/__init__.py +0 -0
  20. {toolkits-0.2.7 → toolkits-0.2.9}/src/toolkits/databases/database_client_util.py +0 -0
  21. {toolkits-0.2.7 → toolkits-0.2.9}/src/toolkits/databases/es_client.py +0 -0
  22. {toolkits-0.2.7 → toolkits-0.2.9}/src/toolkits/databases/hive_client.py +0 -0
  23. {toolkits-0.2.7 → toolkits-0.2.9}/src/toolkits/databases/hive_cmd.py +0 -0
  24. {toolkits-0.2.7 → toolkits-0.2.9}/src/toolkits/databases/hive_helper.py +0 -0
  25. {toolkits-0.2.7/src/toolkits/libs_core → toolkits-0.2.9/src/toolkits/databases}/mysql_helper.py +0 -0
  26. {toolkits-0.2.7 → toolkits-0.2.9}/src/toolkits/databases/redis_mgmt.py +0 -0
  27. {toolkits-0.2.7 → toolkits-0.2.9}/src/toolkits/databases/sql_helper.py +0 -0
  28. {toolkits-0.2.7 → toolkits-0.2.9}/src/toolkits/databases/sqlalchemy_helper.py +0 -0
  29. {toolkits-0.2.7 → toolkits-0.2.9}/src/toolkits/databases/status_check.py +0 -0
  30. {toolkits-0.2.7 → toolkits-0.2.9}/src/toolkits/libs_core/__init__.py +0 -0
  31. {toolkits-0.2.7 → toolkits-0.2.9}/src/toolkits/libs_core/load_module.py +0 -0
  32. {toolkits-0.2.7 → toolkits-0.2.9}/src/toolkits/network/__init__.py +0 -0
  33. {toolkits-0.2.7 → toolkits-0.2.9}/src/toolkits/network/ip_helper.py +0 -0
  34. {toolkits-0.2.7 → toolkits-0.2.9}/src/toolkits/network/pdi_helper.py +0 -0
  35. {toolkits-0.2.7 → toolkits-0.2.9}/src/toolkits/network/send_mail.py +0 -0
  36. {toolkits-0.2.7 → toolkits-0.2.9}/src/toolkits/system/__init__.py +0 -0
  37. {toolkits-0.2.7 → toolkits-0.2.9}/src/toolkits/system/aes_cipher.py +0 -0
  38. {toolkits-0.2.7 → toolkits-0.2.9}/src/toolkits/system/basic_utils.py +0 -0
  39. {toolkits-0.2.7 → toolkits-0.2.9}/src/toolkits/system/collections_helper.py +0 -0
  40. {toolkits-0.2.7 → toolkits-0.2.9}/src/toolkits/system/crpyt_helper.py +0 -0
  41. {toolkits-0.2.7 → toolkits-0.2.9}/src/toolkits/system/dict2xml.py +0 -0
  42. {toolkits-0.2.7 → toolkits-0.2.9}/src/toolkits/system/dict_helper.py +0 -0
  43. {toolkits-0.2.7 → toolkits-0.2.9}/src/toolkits/system/excel_helper.py +0 -0
  44. {toolkits-0.2.7 → toolkits-0.2.9}/src/toolkits/system/file_helper.py +0 -0
  45. {toolkits-0.2.7 → toolkits-0.2.9}/src/toolkits/system/load_module.py +0 -0
  46. {toolkits-0.2.7 → toolkits-0.2.9}/src/toolkits/system/priority_tasks.py +0 -0
  47. {toolkits-0.2.7 → toolkits-0.2.9}/src/toolkits/system/process_monitor/__init__.py +0 -0
  48. {toolkits-0.2.7 → toolkits-0.2.9}/src/toolkits/system/process_monitor/process_monitor.py +0 -0
  49. {toolkits-0.2.7 → toolkits-0.2.9}/src/toolkits/system/str_helper.py +0 -0
  50. {toolkits-0.2.7 → toolkits-0.2.9}/src/toolkits/system/tasks_deamon/__init__.py +0 -0
  51. {toolkits-0.2.7 → toolkits-0.2.9}/src/toolkits/system/tasks_deamon/tasks_controller.py +0 -0
  52. {toolkits-0.2.7 → toolkits-0.2.9}/src/toolkits/system/tasks_deamon/tasks_multiprocessing.py +0 -0
  53. {toolkits-0.2.7 → toolkits-0.2.9}/src/toolkits/system/tasks_deamon/tasks_process.py +0 -0
  54. {toolkits-0.2.7 → toolkits-0.2.9}/src/toolkits/system/test_shell_helper.py +0 -0
  55. {toolkits-0.2.7 → toolkits-0.2.9}/src/toolkits/system/time_helper.py +0 -0
  56. {toolkits-0.2.7 → toolkits-0.2.9}/src/toolkits/system/win32_env.py +0 -0
  57. {toolkits-0.2.7 → toolkits-0.2.9}/src/toolkits/tookits_app.py +0 -0
  58. {toolkits-0.2.7 → toolkits-0.2.9}/tests/__init__.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: toolkits
3
- Version: 0.2.7
3
+ Version: 0.2.9
4
4
  Summary: toolkits for quickly reference
5
5
  Author-Email: li_jia_yue <59727816@qq.com>
6
6
  License: MIT
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "toolkits"
3
- version = "0.2.7"
3
+ version = "0.2.9"
4
4
  description = "toolkits for quickly reference"
5
5
  authors = [
6
6
  { name = "li_jia_yue", email = "59727816@qq.com" },
@@ -1,5 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
- from .load_module import LoadModule
2
+ from toolkits.libs_core.load_module import LoadModule
3
3
 
4
4
 
5
5
  class ConfigHelpers:
@@ -12,7 +12,7 @@ from toolkits.system.shell_helper import exec_shell
12
12
  from unipath import Path
13
13
 
14
14
  from .config_helper import ConfigHelpers
15
- from .mysql_helper import MysqlHelper
15
+ from toolkits.databases.mysql_helper import MysqlHelper
16
16
 
17
17
  logger = log("EnvPrepare")
18
18
 
@@ -1,13 +1,12 @@
1
1
  # -*- coding: utf-8 -*-
2
- import json
3
2
  import traceback
4
3
 
5
4
  import fire
6
5
  from log4python.Log4python import log
7
6
  from toolkits.system.basic_utils import get_script_directory
8
7
 
9
- from toolkits.libs_core.env_prepare import EnvPrepare
10
- from toolkits.libs_core.mysql_helper import MysqlHelper
8
+ from toolkits.config_parser.env_prepare import EnvPrepare
9
+ from toolkits.databases.mysql_helper import MysqlHelper
11
10
 
12
11
  logger = log("DbQueryDemo")
13
12
 
@@ -121,20 +121,22 @@ return-val
121
121
  return result
122
122
 
123
123
 
124
- async def run_command_async(command, timeout=5):
124
+ async def run_command_async(command, timeout=5, encoding="utf-8", shell=False, cwd=None, env=None):
125
125
  process = None
126
126
  try:
127
127
  process = await asyncio.create_subprocess_shell(
128
128
  command,
129
-
130
129
  stdout=asyncio.subprocess.PIPE,
131
- stderr=asyncio.subprocess.PIPE
130
+ stderr=asyncio.subprocess.PIPE,
131
+ shell=shell,
132
+ cwd=cwd,
133
+ env=env
132
134
  )
133
135
  stdout, stderr = await asyncio.wait_for(process.communicate(), timeout=timeout)
134
136
  ret = {
135
137
  "exit_code": process.returncode,
136
- "stdout": stdout,
137
- "stderr": stderr
138
+ "stdout": str(stdout.decode(encoding)).splitlines(False),
139
+ "stderr": str(stderr.decode(encoding)).splitlines(False)
138
140
  }
139
141
  return ret
140
142
  except asyncio.TimeoutError:
@@ -148,15 +150,47 @@ async def run_command_async(command, timeout=5):
148
150
  return ret
149
151
 
150
152
 
151
- def exec_shell_async(command, timeout=5):
152
- loop = asyncio.get_event_loop()
153
- return loop.run_until_complete(run_command_async(command, timeout=timeout))
153
+ def get_loop_obj():
154
+ try:
155
+ # 尝试获取当前线程的事件循环(可能会失败)
156
+ loop = asyncio.get_event_loop()
157
+ except RuntimeError as e:
158
+ # 如果报错 "There is no current event loop...",则创建新的事件循环
159
+ if "There is no current event loop" in str(e):
160
+ loop = asyncio.new_event_loop()
161
+ asyncio.set_event_loop(loop)
162
+ else:
163
+ # 其他 RuntimeError 直接抛出
164
+ raise
165
+ return loop
166
+
167
+
168
+ def exec_shell_async(command, timeout=60 * 10, encoding="utf-8", cwd=None, env=None):
169
+ """
170
+ 异常执行命令,检测执行时间超时
171
+ :param command: 要执行的命令
172
+ :param timeout: 等待的超时时间,超时后,返回: exit_code=-1
173
+ :param encoding: 解析命令行返回数据的编码格式,默认为:utf-8, 中文Windows环境可指定为:GBK
174
+ :param env:
175
+ :param cwd:
176
+ :param shell:
177
+ :return: {'exit_code': 0, 'stdout': '\r\n正在 Ping 127.0.0.1 具有 32 字节的数据:\r\n来自 127.0.0.1 的回复: 字节=32 时间<1ms TTL=128\r\n\r\n', 'stderr': ''}
178
+ """
179
+ if command == "" or command is None:
180
+ ret = {
181
+ "exit_code": -1,
182
+ "stdout": "",
183
+ "stderr": "No cmd was found"
184
+ }
185
+ return ret
186
+
187
+ # asyncio.get_event_loop()
188
+ loop = get_loop_obj()
189
+ return loop.run_until_complete(run_command_async(command, timeout=timeout, encoding=encoding, cwd=cwd, env=env))
154
190
 
155
191
 
156
- def exec_shell(cmd, timeout=0, bufsize=0, executable=None,
157
- stdin=None, stdout=None, stderr=None,
158
- preexec_fn=None, close_fds=False, shell=False,
159
- cwd=None, env=None, universal_newlines=False,
192
+ def exec_shell(cmd, timeout=0, bufsize=0, executable=None, stdin=None, stdout=None, stderr=None,
193
+ preexec_fn=None, close_fds=False, shell=False, cwd=None, env=None, universal_newlines=False,
160
194
  startupinfo=None, creationflags=0):
161
195
  """exec_shell("grep 'processor' /proc/cpuinfo | sort -u | wc -l")
162
196
 
@@ -170,17 +204,22 @@ return-code::
170
204
  }
171
205
  code-end
172
206
 
207
+ :param cmd: exec command
173
208
  :param preexec_fn:
174
209
  :type stdin: object
175
210
  :param executable:
176
211
  :param cwd:
177
212
  :param timeout:
178
- :param cmd: exec command
179
213
  :return: return a dict to caller
180
214
 
181
215
  """
182
216
  if cmd == "" or cmd is None:
183
- return "No Cmd Input"
217
+ ret = {
218
+ "exit_code": -1,
219
+ "stdout": "",
220
+ "stderr": "No cmd was found"
221
+ }
222
+ return ret
184
223
 
185
224
  fp_out = subprocess.PIPE
186
225
  fp_err = subprocess.PIPE
@@ -1,12 +1,11 @@
1
1
  # -*- coding: utf-8 -*-
2
- import sys
3
2
  import traceback
4
3
 
5
4
  import fire
6
5
  from log4python.Log4python import log
7
6
  from toolkits.system.basic_utils import get_script_directory
8
7
 
9
- from libs_core.env_prepare import EnvPrepare
8
+ from toolkits.config_parser.env_prepare import EnvPrepare
10
9
  from tookits_app import tookitsApp
11
10
  from libs_core.process_admin import ProcessAdmin
12
11
  from db_query_demo import DbQueryDemo
@@ -0,0 +1,6 @@
1
+ from toolkits.system.shell_helper import exec_shell_async
2
+
3
+
4
+ def test_exec_shell_async():
5
+ ret = exec_shell_async("ping -n 11 127.0.0.1", 5, encoding='GBK', cwd="C:\\")
6
+ assert ret['exit_code'] != 0
@@ -2,7 +2,7 @@
2
2
  Tests for `tookits` module.
3
3
  """
4
4
  import pytest
5
- from toolkits import tookits
5
+ from toolkits import toolkits
6
6
 
7
7
 
8
8
  class TestTookits(object):
File without changes
File without changes