toolkits 0.2.7__py3-none-any.whl → 0.2.9__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.
- toolkits/{libs_core → config_parser}/config_helper.py +1 -1
- toolkits/{libs_core → config_parser}/env_prepare.py +1 -1
- toolkits/db_query_demo.py +2 -3
- toolkits/system/shell_helper.py +53 -14
- toolkits/tookits_cli.py +1 -2
- {toolkits-0.2.7.dist-info → toolkits-0.2.9.dist-info}/METADATA +1 -1
- {toolkits-0.2.7.dist-info → toolkits-0.2.9.dist-info}/RECORD +13 -13
- {toolkits-0.2.7.dist-info → toolkits-0.2.9.dist-info}/WHEEL +1 -1
- /toolkits/{config → config_parser}/__init__.py +0 -0
- /toolkits/{config → config_parser}/config_demo.py +0 -0
- /toolkits/{libs_core → config_parser}/config_groups_helper.py +0 -0
- /toolkits/{libs_core → databases}/mysql_helper.py +0 -0
- {toolkits-0.2.7.dist-info → toolkits-0.2.9.dist-info}/entry_points.txt +0 -0
@@ -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
|
|
toolkits/db_query_demo.py
CHANGED
@@ -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.
|
10
|
-
from toolkits.
|
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
|
|
toolkits/system/shell_helper.py
CHANGED
@@ -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
|
152
|
-
|
153
|
-
|
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
|
-
|
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
|
-
|
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
|
toolkits/tookits_cli.py
CHANGED
@@ -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
|
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
|
@@ -1,30 +1,30 @@
|
|
1
|
-
toolkits-0.2.
|
2
|
-
toolkits-0.2.
|
3
|
-
toolkits-0.2.
|
1
|
+
toolkits-0.2.9.dist-info/METADATA,sha256=hOzP91GG1CrzEbDHiUrLcpF9Q7DmxZEUearWc5tPghU,1157
|
2
|
+
toolkits-0.2.9.dist-info/WHEEL,sha256=9P2ygRxDrTJz3gsagc0Z96ukrxjr-LFBGOgv3AuKlCA,90
|
3
|
+
toolkits-0.2.9.dist-info/entry_points.txt,sha256=ioUpExuekI3N4XaBZ8NKV1mx0DZnKWLkg2PoGICq6OY,72
|
4
4
|
toolkits/3des/3des.py,sha256=DWfAUGtU7U74GrpnIgA8ZEw7R-kKWyKGfv3Ycqachlw,3400
|
5
5
|
toolkits/3des/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
6
6
|
toolkits/__init__.py,sha256=CBKKalWuRi-mXuf2iwrAI5zzzGcUU5e8xhQNgqBERmg,50
|
7
7
|
toolkits/basic/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
8
8
|
toolkits/basic/list_helper.py,sha256=jvD-YFneCC-LSCgsJ4PWKhBd-hxuE8PAFXScmtbg3kc,717
|
9
|
-
toolkits/
|
10
|
-
toolkits/
|
9
|
+
toolkits/config_parser/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
10
|
+
toolkits/config_parser/config_demo.py,sha256=F9gfD5o7psX6gBXcYc4PVcavTAGECJ5U8Qv98xysJ3k,1087
|
11
|
+
toolkits/config_parser/config_groups_helper.py,sha256=k3ji_4iZVqTL5jB6xrIUKNbATM7Aoc0gAi7rJ1HyJeA,1987
|
12
|
+
toolkits/config_parser/config_helper.py,sha256=I07Zs5a9ndShtGPHMktA6OE1JOhpAG3bZdjZ9LBiYNk,512
|
13
|
+
toolkits/config_parser/env_prepare.py,sha256=SrVfLTT1hf8vOcBiSZm6352mzXuzYGRqgTSIbKPkb4Q,6121
|
11
14
|
toolkits/databases/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
12
15
|
toolkits/databases/database_client_util.py,sha256=Jy1d7xbKmbkxfUWNiz1K-BY1OB1vNgJ0WiCBfmEA8fk,4658
|
13
16
|
toolkits/databases/es_client.py,sha256=08VYRLMIKXz8FK9E_NDDdsKVrFLZdNwWLu4GzCAfQik,2904
|
14
17
|
toolkits/databases/hive_client.py,sha256=3qPpGP2nlMOCULkvwvxbVLfgE1dVKztUmsuJGQaL79w,2154
|
15
18
|
toolkits/databases/hive_cmd.py,sha256=pPr5-6z4y1Yx0J5GoCom2wBFD7x9HOSk8nDIYfZK7Pc,3652
|
16
19
|
toolkits/databases/hive_helper.py,sha256=LCt4rff5meLJ1uCozPzL_S7rpGC8wOWvpe2pk0JXlsQ,8233
|
20
|
+
toolkits/databases/mysql_helper.py,sha256=XI5b5oAkcqDQ8_r3cBDFjjHIv3ufACq22Ls9dq8XdKQ,6153
|
17
21
|
toolkits/databases/redis_mgmt.py,sha256=f02qbYNGfvNGvmVfau5QMK6R92YusbZ-XcZnaRMpgWg,3386
|
18
22
|
toolkits/databases/sql_helper.py,sha256=JHB9UtvXVhcZNVmuM9teWjsNoLYNxRn0RxQaZwi2N-8,9707
|
19
23
|
toolkits/databases/sqlalchemy_helper.py,sha256=26lgOiJDNmuJpX0YWAzZkNylBFGlmaY4jnbcQJIY4Rg,2027
|
20
24
|
toolkits/databases/status_check.py,sha256=12oeY94n5ZRnPoNSrY_P8uB6JMWMStAnuRO6gmTrm9w,6474
|
21
|
-
toolkits/db_query_demo.py,sha256=
|
25
|
+
toolkits/db_query_demo.py,sha256=WgtXGNKrWK1lG2nuqh_0nYx59MuPOqu3eO27P_0ZBjc,2569
|
22
26
|
toolkits/libs_core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
23
|
-
toolkits/libs_core/config_groups_helper.py,sha256=k3ji_4iZVqTL5jB6xrIUKNbATM7Aoc0gAi7rJ1HyJeA,1987
|
24
|
-
toolkits/libs_core/config_helper.py,sha256=t4j10aGcrOR6Zb6-qFZUgELO9tShPJs1NNIB3uVCuVg,494
|
25
|
-
toolkits/libs_core/env_prepare.py,sha256=1zrxrdKcXR9eouEXuqfH03n1z8LSJ10QZ7HEogtA1_4,6103
|
26
27
|
toolkits/libs_core/load_module.py,sha256=AAFPDx4_N6e3KdaI_LKciSqAD0zuHNfZxyu1FImk4o4,1325
|
27
|
-
toolkits/libs_core/mysql_helper.py,sha256=XI5b5oAkcqDQ8_r3cBDFjjHIv3ufACq22Ls9dq8XdKQ,6153
|
28
28
|
toolkits/network/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
29
29
|
toolkits/network/ip_helper.py,sha256=VgSnQyXOAViAZuTnXeOZXtPiL38kbf3rD3-SUxRqNsM,665
|
30
30
|
toolkits/network/pdi_helper.py,sha256=RR8Jdqyd-g1rnrf98UaZgOOks7Z1jcZFaWXzUbf4fQo,7406
|
@@ -42,7 +42,7 @@ toolkits/system/load_module.py,sha256=UXNfE9drsfz9oOBq9EGdV4gjmiIYlJQECIt3PFaLxw
|
|
42
42
|
toolkits/system/priority_tasks.py,sha256=eUtKQatAnYcV3f3V3XY4FQ0u3afX8NHuqiBRcuv0d0I,7632
|
43
43
|
toolkits/system/process_monitor/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
44
44
|
toolkits/system/process_monitor/process_monitor.py,sha256=_tXmWSOzAqAlHeGiBPrMGFU1Wjdr4zUAKNSPucqGRO8,12887
|
45
|
-
toolkits/system/shell_helper.py,sha256=
|
45
|
+
toolkits/system/shell_helper.py,sha256=sjoeVczxRyn_45bm-M95nAbEmz3ENffiWraivCxL0o4,9632
|
46
46
|
toolkits/system/str_helper.py,sha256=89qw0jF6Pf19uuMhBh7XFoCxHvEiZztPwlCDdYuPBEQ,5096
|
47
47
|
toolkits/system/tasks_deamon/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
48
48
|
toolkits/system/tasks_deamon/tasks_controller.py,sha256=aobnJ0vJmvHQs94-yXasHqyxGsBHrv8Vqd1lq6JtmOo,2380
|
@@ -52,5 +52,5 @@ toolkits/system/test_shell_helper.py,sha256=zOCe-2BER1_x8t2NtiySWcd7K-PJEqL_zcIi
|
|
52
52
|
toolkits/system/time_helper.py,sha256=_nxy97rnnagCn_m5sppZTDsx2sdn5debsTfXPEjoWzU,5644
|
53
53
|
toolkits/system/win32_env.py,sha256=KYkZ-clZYkSQnSvPvpydeOVepaCrPH0egkC-MY-Bs0w,1829
|
54
54
|
toolkits/tookits_app.py,sha256=2qz6V5XkEGc6NjxafFvFavE1hpt-tE0PoGonLAvZNXs,380
|
55
|
-
toolkits/tookits_cli.py,sha256=
|
56
|
-
toolkits-0.2.
|
55
|
+
toolkits/tookits_cli.py,sha256=PZmhHLqm8rhLOl3_Fty6WPkW4UxIHMGcswxaHrOe_Ek,5274
|
56
|
+
toolkits-0.2.9.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|