toolkits 0.2.6__tar.gz → 0.2.7__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.
- toolkits-0.2.7/PKG-INFO +35 -0
- toolkits-0.2.7/README.md +17 -0
- toolkits-0.2.7/pyproject.toml +35 -0
- toolkits-0.2.7/src/toolkits/3des/3des.py +93 -0
- toolkits-0.2.7/src/toolkits/config/config_demo.py +43 -0
- toolkits-0.2.7/src/toolkits/db_query_demo.py +72 -0
- toolkits-0.2.7/src/toolkits/libs_core/config_groups_helper.py +60 -0
- toolkits-0.2.7/src/toolkits/libs_core/config_helper.py +22 -0
- toolkits-0.2.7/src/toolkits/libs_core/env_prepare.py +145 -0
- toolkits-0.2.7/src/toolkits/libs_core/load_module.py +46 -0
- toolkits-0.2.7/src/toolkits/libs_core/mysql_helper.py +151 -0
- toolkits-0.2.7/src/toolkits/system/__init__.py +0 -0
- toolkits-0.2.7/src/toolkits/system/process_monitor/__init__.py +0 -0
- {toolkits-0.2.6 → toolkits-0.2.7/src}/toolkits/system/shell_helper.py +33 -0
- toolkits-0.2.7/src/toolkits/system/tasks_deamon/__init__.py +0 -0
- toolkits-0.2.7/src/toolkits/system/test_shell_helper.py +2 -0
- toolkits-0.2.7/src/toolkits/tookits_app.py +17 -0
- toolkits-0.2.7/src/toolkits/tookits_cli.py +126 -0
- toolkits-0.2.7/tests/__init__.py +0 -0
- toolkits-0.2.7/tests/test_tookits.py +19 -0
- toolkits-0.2.6/MANIFEST.in +0 -4
- toolkits-0.2.6/PKG-INFO +0 -23
- toolkits-0.2.6/README.rst +0 -4
- toolkits-0.2.6/setup.cfg +0 -4
- toolkits-0.2.6/setup.py +0 -45
- toolkits-0.2.6/toolkits.egg-info/PKG-INFO +0 -23
- toolkits-0.2.6/toolkits.egg-info/SOURCES.txt +0 -47
- toolkits-0.2.6/toolkits.egg-info/dependency_links.txt +0 -1
- toolkits-0.2.6/toolkits.egg-info/not-zip-safe +0 -1
- toolkits-0.2.6/toolkits.egg-info/requires.txt +0 -6
- toolkits-0.2.6/toolkits.egg-info/top_level.txt +0 -1
- {toolkits-0.2.6/toolkits/basic → toolkits-0.2.7/src/toolkits/3des}/__init__.py +0 -0
- {toolkits-0.2.6 → toolkits-0.2.7/src}/toolkits/__init__.py +0 -0
- {toolkits-0.2.6/toolkits/databases → toolkits-0.2.7/src/toolkits/basic}/__init__.py +0 -0
- {toolkits-0.2.6 → toolkits-0.2.7/src}/toolkits/basic/list_helper.py +0 -0
- {toolkits-0.2.6/toolkits/network → toolkits-0.2.7/src/toolkits/config}/__init__.py +0 -0
- {toolkits-0.2.6/toolkits/system → toolkits-0.2.7/src/toolkits/databases}/__init__.py +0 -0
- {toolkits-0.2.6 → toolkits-0.2.7/src}/toolkits/databases/database_client_util.py +0 -0
- {toolkits-0.2.6 → toolkits-0.2.7/src}/toolkits/databases/es_client.py +0 -0
- {toolkits-0.2.6 → toolkits-0.2.7/src}/toolkits/databases/hive_client.py +0 -0
- {toolkits-0.2.6 → toolkits-0.2.7/src}/toolkits/databases/hive_cmd.py +0 -0
- {toolkits-0.2.6 → toolkits-0.2.7/src}/toolkits/databases/hive_helper.py +0 -0
- {toolkits-0.2.6 → toolkits-0.2.7/src}/toolkits/databases/redis_mgmt.py +0 -0
- {toolkits-0.2.6 → toolkits-0.2.7/src}/toolkits/databases/sql_helper.py +0 -0
- {toolkits-0.2.6 → toolkits-0.2.7/src}/toolkits/databases/sqlalchemy_helper.py +0 -0
- {toolkits-0.2.6 → toolkits-0.2.7/src}/toolkits/databases/status_check.py +0 -0
- {toolkits-0.2.6/toolkits/system/process_monitor → toolkits-0.2.7/src/toolkits/libs_core}/__init__.py +0 -0
- {toolkits-0.2.6/toolkits/system/tasks_deamon → toolkits-0.2.7/src/toolkits/network}/__init__.py +0 -0
- {toolkits-0.2.6 → toolkits-0.2.7/src}/toolkits/network/ip_helper.py +0 -0
- {toolkits-0.2.6 → toolkits-0.2.7/src}/toolkits/network/pdi_helper.py +0 -0
- {toolkits-0.2.6 → toolkits-0.2.7/src}/toolkits/network/send_mail.py +0 -0
- {toolkits-0.2.6 → toolkits-0.2.7/src}/toolkits/system/aes_cipher.py +0 -0
- {toolkits-0.2.6 → toolkits-0.2.7/src}/toolkits/system/basic_utils.py +0 -0
- {toolkits-0.2.6 → toolkits-0.2.7/src}/toolkits/system/collections_helper.py +0 -0
- {toolkits-0.2.6 → toolkits-0.2.7/src}/toolkits/system/crpyt_helper.py +0 -0
- {toolkits-0.2.6 → toolkits-0.2.7/src}/toolkits/system/dict2xml.py +0 -0
- {toolkits-0.2.6 → toolkits-0.2.7/src}/toolkits/system/dict_helper.py +0 -0
- {toolkits-0.2.6 → toolkits-0.2.7/src}/toolkits/system/excel_helper.py +0 -0
- {toolkits-0.2.6 → toolkits-0.2.7/src}/toolkits/system/file_helper.py +0 -0
- {toolkits-0.2.6 → toolkits-0.2.7/src}/toolkits/system/load_module.py +0 -0
- {toolkits-0.2.6 → toolkits-0.2.7/src}/toolkits/system/priority_tasks.py +0 -0
- {toolkits-0.2.6 → toolkits-0.2.7/src}/toolkits/system/process_monitor/process_monitor.py +0 -0
- {toolkits-0.2.6 → toolkits-0.2.7/src}/toolkits/system/str_helper.py +0 -0
- {toolkits-0.2.6 → toolkits-0.2.7/src}/toolkits/system/tasks_deamon/tasks_controller.py +0 -0
- {toolkits-0.2.6 → toolkits-0.2.7/src}/toolkits/system/tasks_deamon/tasks_multiprocessing.py +0 -0
- {toolkits-0.2.6 → toolkits-0.2.7/src}/toolkits/system/tasks_deamon/tasks_process.py +0 -0
- {toolkits-0.2.6 → toolkits-0.2.7/src}/toolkits/system/time_helper.py +0 -0
- {toolkits-0.2.6 → toolkits-0.2.7/src}/toolkits/system/win32_env.py +0 -0
toolkits-0.2.7/PKG-INFO
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
Metadata-Version: 2.1
|
2
|
+
Name: toolkits
|
3
|
+
Version: 0.2.7
|
4
|
+
Summary: toolkits for quickly reference
|
5
|
+
Author-Email: li_jia_yue <59727816@qq.com>
|
6
|
+
License: MIT
|
7
|
+
Requires-Python: >=3.9
|
8
|
+
Requires-Dist: fire>=0.6.0
|
9
|
+
Requires-Dist: arrow>=1.3.0
|
10
|
+
Requires-Dist: pytest>=8.2.2
|
11
|
+
Requires-Dist: icecream>=2.1.3
|
12
|
+
Requires-Dist: schedule>=1.2.2
|
13
|
+
Requires-Dist: jmespath>=1.0.1
|
14
|
+
Requires-Dist: unicodecsv>=0.14.1
|
15
|
+
Requires-Dist: log4python>=1.0.11
|
16
|
+
Requires-Dist: unipath>=1.1
|
17
|
+
Description-Content-Type: text/markdown
|
18
|
+
|
19
|
+
# toolkits
|
20
|
+
## 迁移PDM项目
|
21
|
+
1, Create virtual env
|
22
|
+
pdm venv create
|
23
|
+
|
24
|
+
2, Install dependency
|
25
|
+
pdm install
|
26
|
+
|
27
|
+
3, basic python libs
|
28
|
+
pdm add arrow toolkits requests dingtalkchatbot exchangelib redis PyYAML sqlalchemy kafka-python-ng urllib3==1.26.15 wheel jmespath log4python PyMySQL pytest crython icecream
|
29
|
+
|
30
|
+
## 使用包中的Python脚本
|
31
|
+
### 设置Python环境变量
|
32
|
+
export PYTHONPATH="/home/pythonDemo/toolkits/src/:$PYTHONPATH"
|
33
|
+
### 源码目录中不要有[与包名一致的Python脚本文件]
|
34
|
+
### 直接调用Python脚本
|
35
|
+
python toolkits/db_query_demo.py --config_path="/home/pythonDemo/toolkits/src/toolkits/config/config_demo.py" worker test_01.txt
|
toolkits-0.2.7/README.md
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# toolkits
|
2
|
+
## 迁移PDM项目
|
3
|
+
1, Create virtual env
|
4
|
+
pdm venv create
|
5
|
+
|
6
|
+
2, Install dependency
|
7
|
+
pdm install
|
8
|
+
|
9
|
+
3, basic python libs
|
10
|
+
pdm add arrow toolkits requests dingtalkchatbot exchangelib redis PyYAML sqlalchemy kafka-python-ng urllib3==1.26.15 wheel jmespath log4python PyMySQL pytest crython icecream
|
11
|
+
|
12
|
+
## 使用包中的Python脚本
|
13
|
+
### 设置Python环境变量
|
14
|
+
export PYTHONPATH="/home/pythonDemo/toolkits/src/:$PYTHONPATH"
|
15
|
+
### 源码目录中不要有[与包名一致的Python脚本文件]
|
16
|
+
### 直接调用Python脚本
|
17
|
+
python toolkits/db_query_demo.py --config_path="/home/pythonDemo/toolkits/src/toolkits/config/config_demo.py" worker test_01.txt
|
@@ -0,0 +1,35 @@
|
|
1
|
+
[project]
|
2
|
+
name = "toolkits"
|
3
|
+
version = "0.2.7"
|
4
|
+
description = "toolkits for quickly reference"
|
5
|
+
authors = [
|
6
|
+
{ name = "li_jia_yue", email = "59727816@qq.com" },
|
7
|
+
]
|
8
|
+
dependencies = [
|
9
|
+
"fire>=0.6.0",
|
10
|
+
"arrow>=1.3.0",
|
11
|
+
"pytest>=8.2.2",
|
12
|
+
"icecream>=2.1.3",
|
13
|
+
"schedule>=1.2.2",
|
14
|
+
"jmespath>=1.0.1",
|
15
|
+
"unicodecsv>=0.14.1",
|
16
|
+
"log4python>=1.0.11",
|
17
|
+
"unipath>=1.1",
|
18
|
+
]
|
19
|
+
requires-python = ">=3.9"
|
20
|
+
readme = "README.md"
|
21
|
+
|
22
|
+
[project.license]
|
23
|
+
text = "MIT"
|
24
|
+
|
25
|
+
[project.scripts]
|
26
|
+
toolkits = "toolkits.toolkits_cli:main"
|
27
|
+
|
28
|
+
[build-system]
|
29
|
+
requires = [
|
30
|
+
"pdm-backend",
|
31
|
+
]
|
32
|
+
build-backend = "pdm.backend"
|
33
|
+
|
34
|
+
[tool.pdm]
|
35
|
+
distribution = true
|
@@ -0,0 +1,93 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
import pyDes
|
4
|
+
import base64
|
5
|
+
|
6
|
+
|
7
|
+
class TripleDesUtils:
|
8
|
+
des_mode = {"CBC": pyDes.CBC, "ECB": pyDes.ECB}
|
9
|
+
des_pad_mode = {"PAD_PKCS5": pyDes.PAD_PKCS5, "PAD_NORMAL": pyDes.PAD_NORMAL}
|
10
|
+
|
11
|
+
def __init__(self, mode, pad_mode, key, iv, pad=None, trans_base64=False):
|
12
|
+
"""
|
13
|
+
:param mode: des 加密模式,目前支持 CBC,ECB
|
14
|
+
:param pad_mode: 目前支持 PAD_PKCS5,PAD_NORMAL
|
15
|
+
:param trans_base64: 加密结果是否以 base64 格式输出
|
16
|
+
:param key: 密钥
|
17
|
+
:param iv: 偏移量
|
18
|
+
:param pad:
|
19
|
+
"""
|
20
|
+
self.trans_base64 = trans_base64
|
21
|
+
self.k = pyDes.triple_des(key, TripleDesUtils.des_mode.get(mode), iv, pad, TripleDesUtils.des_pad_mode.get(pad_mode))
|
22
|
+
|
23
|
+
def encryption(self, data):
|
24
|
+
"""
|
25
|
+
3des 加密
|
26
|
+
说明: 3DES数据块长度为64位,所以IV长度需要为8个字符(ECB模式不用IV),密钥长度为16或24个字符(8个字符以内则结果与DES相同
|
27
|
+
IV与密钥超过长度则截取,不足则在末尾填充'\0'补足
|
28
|
+
:param data: 待加密数据
|
29
|
+
:return:
|
30
|
+
"""
|
31
|
+
_encryption_result = self.k.encrypt(data)
|
32
|
+
if self.trans_base64:
|
33
|
+
_encryption_result = self._base64encode(_encryption_result)
|
34
|
+
return _encryption_result
|
35
|
+
|
36
|
+
def decrypt(self, data):
|
37
|
+
"""
|
38
|
+
3des 解密
|
39
|
+
:param data: 待解密数据
|
40
|
+
:return:
|
41
|
+
"""
|
42
|
+
if self.trans_base64:
|
43
|
+
data = self._base64decode(data)
|
44
|
+
_decrypt_result = self.k.decrypt(data)
|
45
|
+
return _decrypt_result
|
46
|
+
|
47
|
+
@staticmethod
|
48
|
+
def _base64encode(data):
|
49
|
+
"""
|
50
|
+
base 64 encode
|
51
|
+
:param data: encode data
|
52
|
+
:return:
|
53
|
+
"""
|
54
|
+
try:
|
55
|
+
_b64encode_result = base64.b64encode(data)
|
56
|
+
except Exception as e:
|
57
|
+
raise Exception("base64 encode error:{e}")
|
58
|
+
return _b64encode_result
|
59
|
+
|
60
|
+
@staticmethod
|
61
|
+
def _base64decode(data):
|
62
|
+
"""
|
63
|
+
base 64 decode
|
64
|
+
:param data: decode data
|
65
|
+
:return:
|
66
|
+
"""
|
67
|
+
try:
|
68
|
+
_b64decode_result = base64.b64decode(data)
|
69
|
+
except Exception as e:
|
70
|
+
raise Exception("base64 decode error:{e}")
|
71
|
+
return _b64decode_result
|
72
|
+
|
73
|
+
|
74
|
+
if __name__ == "__main__":
|
75
|
+
test_data = "12345678a"
|
76
|
+
key_a = "uusafeuusafeuusafeuusafe"
|
77
|
+
key_b = "jiayufeuusafeuusafeuusaf"
|
78
|
+
# [12345678a] 3des Result: 2yjtt0Y/c7xEOa9VGetBVA==
|
79
|
+
DesObj = TripleDesUtils(mode="CBC", pad_mode="PAD_PKCS5", key=key_a, iv="01234567", trans_base64=True)
|
80
|
+
result_a = DesObj.encryption(test_data)
|
81
|
+
print("加密结果: %s" % result_a)
|
82
|
+
DesObj = TripleDesUtils(mode="CBC", pad_mode="PAD_PKCS5", key=key_b, iv="01234567", trans_base64=True)
|
83
|
+
result_b = DesObj.encryption(result_a)
|
84
|
+
print("加密结果: %s" % result_b)
|
85
|
+
|
86
|
+
# result2 = DesObj.decrypt(result)
|
87
|
+
# print("解密结果: %s" % result2)
|
88
|
+
DesObj = TripleDesUtils(mode="CBC", pad_mode="PAD_PKCS5", key=key_b, iv="01234567", trans_base64=True)
|
89
|
+
result_a = DesObj.encryption(test_data)
|
90
|
+
print("加密结果: %s" % result_a)
|
91
|
+
DesObj = TripleDesUtils(mode="CBC", pad_mode="PAD_PKCS5", key=key_a, iv="01234567", trans_base64=True)
|
92
|
+
result_b = DesObj.encryption(result_a)
|
93
|
+
print("加密结果: %s" % result_b)
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
config_global = {
|
4
|
+
"db_list": {
|
5
|
+
'dev_ops': {
|
6
|
+
'desc': "Home 数据库",
|
7
|
+
'db_name': "dev_ops",
|
8
|
+
'user_name': 'root',
|
9
|
+
'password': '4tKTiDYr81YM',
|
10
|
+
'host': "192.168.100.155",
|
11
|
+
'port': 6606
|
12
|
+
},
|
13
|
+
'online_alarm': {
|
14
|
+
'desc': "16.15 数据库",
|
15
|
+
'user_name': 'db_admin',
|
16
|
+
'password': '123QWEas!@#',
|
17
|
+
'host': "10.83.16.15",
|
18
|
+
'port': 8012,
|
19
|
+
'db_name': "sec_admin"
|
20
|
+
}
|
21
|
+
},
|
22
|
+
"kafka_list": {
|
23
|
+
"home": {
|
24
|
+
'host': "192.168.100.155",
|
25
|
+
'port': 9092
|
26
|
+
}
|
27
|
+
},
|
28
|
+
"redis_list": {
|
29
|
+
"home": {
|
30
|
+
'password': 's1hKcWqRj9Se',
|
31
|
+
'host': '192.168.100.155',
|
32
|
+
'port': 9379,
|
33
|
+
'db': 1
|
34
|
+
}
|
35
|
+
},
|
36
|
+
"zookeeper_list": {
|
37
|
+
"home": {
|
38
|
+
"bin_path": "/usr/local/dev/kafka/kafka_2.12-2.3.0",
|
39
|
+
"ip": "192.168.100.155",
|
40
|
+
"port": "2184"
|
41
|
+
}
|
42
|
+
}
|
43
|
+
}
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
import json
|
3
|
+
import traceback
|
4
|
+
|
5
|
+
import fire
|
6
|
+
from log4python.Log4python import log
|
7
|
+
from toolkits.system.basic_utils import get_script_directory
|
8
|
+
|
9
|
+
from toolkits.libs_core.env_prepare import EnvPrepare
|
10
|
+
from toolkits.libs_core.mysql_helper import MysqlHelper
|
11
|
+
|
12
|
+
logger = log("DbQueryDemo")
|
13
|
+
|
14
|
+
|
15
|
+
class DbQueryDemo:
|
16
|
+
def __init__(self, config_path=None):
|
17
|
+
self.__base_path = get_script_directory()
|
18
|
+
self.__config_path = config_path
|
19
|
+
if config_path is None:
|
20
|
+
if tookitsApp.config_file_path is None:
|
21
|
+
self.__env = EnvPrepare(tookitsApp.app_name)
|
22
|
+
self.__env.check_env()
|
23
|
+
self.__config_path = self.__env.get_config_path("config.py")
|
24
|
+
self.__env.check_config_ready(self.__config_path, "请先初始化配置文件、在数据库创建相应的数据表")
|
25
|
+
else:
|
26
|
+
self.__config_path = tookitsApp.config_file_path
|
27
|
+
|
28
|
+
self.__env = EnvPrepare(tookitsApp.app_name, self.__config_path)
|
29
|
+
self.__mysql_config = self.__env.get_config('mysql_info_online_alarm')
|
30
|
+
self.sql_helper = MysqlHelper(self.__mysql_config)
|
31
|
+
|
32
|
+
def query_sql(self, query_where) -> list:
|
33
|
+
list_api = self.sql_helper.query("SELECT x.* FROM sec_admin.api_sec_output_send x WHERE bot_process in (%s)" % query_where)
|
34
|
+
# logger.debug("Result:[%s]" % json.dumps(list_api))
|
35
|
+
logger.debug("Len: %s" % str(len(list_api)))
|
36
|
+
return list_api
|
37
|
+
|
38
|
+
@staticmethod
|
39
|
+
def __read_all_data(file_path):
|
40
|
+
fp = open(file_path)
|
41
|
+
data_list = fp.readlines()
|
42
|
+
fp.close()
|
43
|
+
ns_list = []
|
44
|
+
for item in data_list:
|
45
|
+
ns_list.append(str(item).strip())
|
46
|
+
return ns_list
|
47
|
+
|
48
|
+
def worker(self, file_path, batch_size=10):
|
49
|
+
data_list = self.__read_all_data(file_path)
|
50
|
+
final_list = []
|
51
|
+
for i in range(0, len(data_list), batch_size):
|
52
|
+
# 获取当前批次的数据
|
53
|
+
batch_data = data_list[i:i + batch_size]
|
54
|
+
sql_where = "'%s'" % "', '".join(batch_data)
|
55
|
+
|
56
|
+
kylin_list = self.query_sql(sql_where)
|
57
|
+
final_list.extend(kylin_list)
|
58
|
+
|
59
|
+
fp = open("%s.csv" % file_path, "w+")
|
60
|
+
fp.write("source,host,name_space")
|
61
|
+
for item in list(set(final_list)):
|
62
|
+
fp.write("%s,%s,%s\r\n" % (item['source'], item['host'], item['name_space']))
|
63
|
+
fp.close()
|
64
|
+
|
65
|
+
|
66
|
+
if __name__ == '__main__':
|
67
|
+
try:
|
68
|
+
fire.Fire(DbQueryDemo)
|
69
|
+
except Exception as ex:
|
70
|
+
logger.error("Error: %s" % ex)
|
71
|
+
logger.error(traceback.format_exc())
|
72
|
+
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
|
4
|
+
class ConfigGroupsHelper:
|
5
|
+
"""
|
6
|
+
ConfigGroupsHelper
|
7
|
+
"""
|
8
|
+
def __init__(self, config_groups, config_groups_type="list"):
|
9
|
+
self.__group_config = {}
|
10
|
+
if config_groups_type == "list":
|
11
|
+
self.__init_config_list(config_groups)
|
12
|
+
elif config_groups_type == "dict":
|
13
|
+
self.__init_config_dict(config_groups)
|
14
|
+
|
15
|
+
def __init_config_dict(self, config_groups_dict, talk_groups=None):
|
16
|
+
init_groups = {}
|
17
|
+
chat_groups = dict(config_groups_dict)
|
18
|
+
if talk_groups:
|
19
|
+
if type(talk_groups) is dict:
|
20
|
+
chat_groups = {
|
21
|
+
"default": talk_groups
|
22
|
+
}
|
23
|
+
|
24
|
+
if chat_groups:
|
25
|
+
for item in chat_groups.keys():
|
26
|
+
init_groups[item] = chat_groups[item]
|
27
|
+
|
28
|
+
self.__group_config = init_groups
|
29
|
+
|
30
|
+
def __init_config_list(self, config_groups, talk_groups=None):
|
31
|
+
init_groups = {}
|
32
|
+
chat_groups = config_groups
|
33
|
+
if talk_groups:
|
34
|
+
if type(talk_groups) is dict:
|
35
|
+
chat_groups = [talk_groups]
|
36
|
+
else:
|
37
|
+
chat_groups = talk_groups
|
38
|
+
|
39
|
+
if chat_groups:
|
40
|
+
for item in chat_groups:
|
41
|
+
init_groups[item['name']] = item
|
42
|
+
|
43
|
+
self.__group_config = init_groups
|
44
|
+
|
45
|
+
def get_config_by_name(self, config_name):
|
46
|
+
config = None
|
47
|
+
if config_name not in self.__group_config.keys():
|
48
|
+
err_msg = "配置名称不存在,请检查!!"
|
49
|
+
print(err_msg)
|
50
|
+
exit(1)
|
51
|
+
else:
|
52
|
+
config = self.__group_config[config_name]
|
53
|
+
return config
|
54
|
+
|
55
|
+
def list_config_groups(self, config_name=""):
|
56
|
+
groups = self.__group_config.keys()
|
57
|
+
print("%s-配置组:\n" % config_name)
|
58
|
+
for item_group in groups:
|
59
|
+
desc = self.__group_config[item_group]['desc']
|
60
|
+
print("\tName: %s\tDesc:[%s]" % (item_group, desc))
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
from .load_module import LoadModule
|
3
|
+
|
4
|
+
|
5
|
+
class ConfigHelpers:
|
6
|
+
def __init__(self):
|
7
|
+
pass
|
8
|
+
|
9
|
+
@staticmethod
|
10
|
+
def load_config(config_file):
|
11
|
+
app = LoadModule()
|
12
|
+
config_info = app.load_from_file(config_file)
|
13
|
+
return config_info
|
14
|
+
|
15
|
+
@staticmethod
|
16
|
+
def get_config_by_name(config_data, config_name):
|
17
|
+
config_info = None
|
18
|
+
if config_data:
|
19
|
+
config_info = config_data.__dict__[config_name]
|
20
|
+
|
21
|
+
return config_info
|
22
|
+
|
@@ -0,0 +1,145 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
import os
|
3
|
+
import platform
|
4
|
+
import sys
|
5
|
+
import traceback
|
6
|
+
|
7
|
+
import fire
|
8
|
+
import jmespath
|
9
|
+
from log4python.Log4python import log
|
10
|
+
from toolkits.system.basic_utils import get_script_directory
|
11
|
+
from toolkits.system.shell_helper import exec_shell
|
12
|
+
from unipath import Path
|
13
|
+
|
14
|
+
from .config_helper import ConfigHelpers
|
15
|
+
from .mysql_helper import MysqlHelper
|
16
|
+
|
17
|
+
logger = log("EnvPrepare")
|
18
|
+
|
19
|
+
|
20
|
+
class EnvPrepare:
|
21
|
+
config_file_path = None
|
22
|
+
|
23
|
+
def __init__(self, app_name, config_full_path=None, config_global_name="config_global"):
|
24
|
+
self.__base_path = get_script_directory()
|
25
|
+
self.__config_global_name = config_global_name
|
26
|
+
self.__user_home_path = os.path.expanduser("~/.config")
|
27
|
+
self.__app_name = app_name
|
28
|
+
self.__config_full_path = None
|
29
|
+
self.__config_path = "%s/%s/" % (self.__get_workdir(), self.__app_name)
|
30
|
+
if config_full_path:
|
31
|
+
if Path(config_full_path).exists():
|
32
|
+
self.__config_full_path = config_full_path
|
33
|
+
else:
|
34
|
+
logger.error("Config was not exist:[%s]" % config_full_path)
|
35
|
+
|
36
|
+
self.__tip_message = "Initialized: finished, please change the default's config to " \
|
37
|
+
"adapt your environment! "
|
38
|
+
self.__default_path_tip = "Default config path: %s" % self.__config_path
|
39
|
+
self.__dict_config = {}
|
40
|
+
|
41
|
+
def __get_workdir(self):
|
42
|
+
app_data = self.__user_home_path
|
43
|
+
if platform.system().lower() == 'windows': # print("windows")
|
44
|
+
app_data = "%s\\.config" % os.getenv("APPDATA")
|
45
|
+
elif platform.system().lower() == 'linux': # print("linux")
|
46
|
+
app_data = self.__user_home_path
|
47
|
+
return app_data
|
48
|
+
|
49
|
+
def check_env(self):
|
50
|
+
# check env-config
|
51
|
+
if not Path(self.__config_path).exists():
|
52
|
+
Path(self.__config_path).mkdir(parents=True)
|
53
|
+
src_path = "%s/../config/" % self.__base_path
|
54
|
+
self.init_default_config("directory", src_path, self.__config_path)
|
55
|
+
print("%s\n%s" % (self.__tip_message, self.__default_path_tip))
|
56
|
+
logger.error("%s\n%s" % (self.__tip_message, self.__default_path_tip))
|
57
|
+
|
58
|
+
def check_config_ready(self, config_path, error_message):
|
59
|
+
if not Path(config_path).exists():
|
60
|
+
msg = error_message + "\n" + self.__default_path_tip
|
61
|
+
print(msg)
|
62
|
+
logger.error(msg)
|
63
|
+
# raise Exception(msg)
|
64
|
+
exit(-1)
|
65
|
+
|
66
|
+
def get_config_path(self, config_file_name):
|
67
|
+
return "%s/%s" % (self.__config_path, config_file_name)
|
68
|
+
|
69
|
+
def get_config_from_file(self, config_path: str, config_key: str, force_reload: bool = False) -> dict:
|
70
|
+
if config_path not in self.__dict_config or force_reload is True:
|
71
|
+
config_data = ConfigHelpers.load_config(config_path)
|
72
|
+
self.__dict_config[config_path] = config_data
|
73
|
+
else:
|
74
|
+
config_data = self.__dict_config[config_path]
|
75
|
+
|
76
|
+
return ConfigHelpers.get_config_by_name(config_data, config_key)
|
77
|
+
|
78
|
+
def __get_default_config_file(self):
|
79
|
+
running_app = os.path.split(os.path.realpath(sys.argv[0]))[1]
|
80
|
+
if running_app[-3:] == ".py" or running_app[-4:] == ".pyc":
|
81
|
+
path_working = os.path.split(os.path.realpath(sys.argv[0]))[0]
|
82
|
+
else:
|
83
|
+
path_working = os.getcwd()
|
84
|
+
|
85
|
+
config_path_working = "%s/config.py" % path_working
|
86
|
+
if not Path(config_path_working).exists():
|
87
|
+
config_path_working = "%s/%s/config.py" % (self.__user_home_path, self.__app_name)
|
88
|
+
return config_path_working
|
89
|
+
|
90
|
+
def get_default_config(self, config_key: str, force_reload: bool = False) -> dict:
|
91
|
+
if EnvPrepare.config_file_path:
|
92
|
+
config_path_working = EnvPrepare.config_file_path
|
93
|
+
else:
|
94
|
+
config_path_working = self.__get_default_config_file()
|
95
|
+
logger.debug("config_path_working: %s", config_path_working)
|
96
|
+
config_data = None
|
97
|
+
if Path(config_path_working).exists():
|
98
|
+
config_data = self.get_config_from_file(config_path_working, config_key, force_reload)
|
99
|
+
return config_data
|
100
|
+
|
101
|
+
def get_config(self, config_key: str, force_reload: bool = False):
|
102
|
+
if self.__config_full_path:
|
103
|
+
config_data = self.get_config_from_file(self.__config_full_path, self.__config_global_name, force_reload)
|
104
|
+
else:
|
105
|
+
config_data = self.get_default_config(self.__config_global_name, force_reload)
|
106
|
+
return jmespath.search(config_key, config_data)
|
107
|
+
|
108
|
+
@staticmethod
|
109
|
+
def init_default_config(init_type, src_path, dest_path):
|
110
|
+
init_status = False
|
111
|
+
if init_type == 'file':
|
112
|
+
if platform.system().lower() == 'windows':
|
113
|
+
cmd_copy = "XCOPY /S /-Y %s %s " % (str(src_path).replace("/", "\\"), str(dest_path).replace("/", "\\"))
|
114
|
+
elif platform.system().lower() == 'linux':
|
115
|
+
cmd_copy = "cp -arf %s %s " % (src_path, dest_path)
|
116
|
+
elif init_type == 'directory':
|
117
|
+
if platform.system().lower() == 'windows':
|
118
|
+
cmd_copy = "xcopy /S /-Y %s %s " % (str(src_path).replace("/", "\\"), str(dest_path).replace("/", "\\"))
|
119
|
+
elif platform.system().lower() == 'linux':
|
120
|
+
cmd_copy = "cp -arf %s/* %s/ " % (src_path, dest_path)
|
121
|
+
else:
|
122
|
+
return init_status
|
123
|
+
|
124
|
+
logger.info("CopyCMD: %s" % cmd_copy)
|
125
|
+
ret = exec_shell(cmd_copy)
|
126
|
+
if str(ret['exit_code']) == "0":
|
127
|
+
init_status = True
|
128
|
+
return init_status
|
129
|
+
|
130
|
+
@staticmethod
|
131
|
+
def init_db(database_config, sql_execute):
|
132
|
+
try:
|
133
|
+
mysql_conn = MysqlHelper(database_config)
|
134
|
+
mysql_conn.execute(sql_execute)
|
135
|
+
except Exception as ex:
|
136
|
+
logger.error("Error: %s" % ex)
|
137
|
+
logger.error(traceback.format_exc())
|
138
|
+
|
139
|
+
|
140
|
+
if __name__ == '__main__':
|
141
|
+
try:
|
142
|
+
fire.Fire(EnvPrepare)
|
143
|
+
except Exception as ex:
|
144
|
+
logger.error("Error: %s" % ex)
|
145
|
+
logger.error(traceback.format_exc())
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
import imp
|
3
|
+
import os
|
4
|
+
import traceback
|
5
|
+
import uuid
|
6
|
+
|
7
|
+
from log4python.Log4python import log
|
8
|
+
|
9
|
+
logger = log("LoadModule")
|
10
|
+
|
11
|
+
|
12
|
+
class LoadModule(object):
|
13
|
+
def __init__(self):
|
14
|
+
pass
|
15
|
+
|
16
|
+
@staticmethod
|
17
|
+
def load_from_file(file_path):
|
18
|
+
mod_name, file_ext = os.path.splitext(os.path.split(file_path)[-1])
|
19
|
+
py_mod = None
|
20
|
+
if file_ext.lower() == '.py':
|
21
|
+
py_mod = imp.load_source(mod_name, file_path)
|
22
|
+
elif file_ext.lower() == '.pyc':
|
23
|
+
py_mod = imp.load_compiled(mod_name, file_path)
|
24
|
+
|
25
|
+
return py_mod
|
26
|
+
|
27
|
+
@staticmethod
|
28
|
+
def __write_tmp_py(file_path, content):
|
29
|
+
fp = open(file_path, "w+")
|
30
|
+
fp.write(content)
|
31
|
+
fp.close()
|
32
|
+
|
33
|
+
def load_from_string(self, func_string, module_name=None):
|
34
|
+
modules = None
|
35
|
+
try:
|
36
|
+
str_random = str(uuid.uuid4()).replace("-", "")
|
37
|
+
if module_name:
|
38
|
+
file_path = "/tmp/dynamic_%s_%s.py" % (module_name, str_random)
|
39
|
+
else:
|
40
|
+
file_path = "/tmp/dynamic_%s.py" % str_random
|
41
|
+
self.__write_tmp_py(file_path, func_string)
|
42
|
+
modules = self.load_from_file(file_path)
|
43
|
+
except Exception as ex:
|
44
|
+
logger.debug("Error: %s" % ex)
|
45
|
+
logger.debug(traceback.format_exc())
|
46
|
+
return modules
|
@@ -0,0 +1,151 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
import importlib
|
3
|
+
import sys
|
4
|
+
import traceback
|
5
|
+
try:
|
6
|
+
from urllib import parse
|
7
|
+
except Exception as ex:
|
8
|
+
import urllib as parse
|
9
|
+
|
10
|
+
from log4python.Log4python import log
|
11
|
+
from sqlalchemy import Engine
|
12
|
+
from sqlalchemy import create_engine
|
13
|
+
from sqlalchemy.sql import text
|
14
|
+
|
15
|
+
importlib.reload(sys)
|
16
|
+
logger = log("MysqlHelper")
|
17
|
+
import pymysql
|
18
|
+
|
19
|
+
pymysql.version_info = (1, 4, 13, "final", 0)
|
20
|
+
pymysql.install_as_MySQLdb()
|
21
|
+
|
22
|
+
|
23
|
+
class MysqlHelper:
|
24
|
+
def __init__(self, database_config=None):
|
25
|
+
self.mysql_config = database_config
|
26
|
+
self.__engine = None
|
27
|
+
|
28
|
+
def get_mysql_client(self, config_user=None) -> Engine:
|
29
|
+
'''
|
30
|
+
mysql_db = 'mysql://root:***@10.89.189.48:8027/log_etl'
|
31
|
+
'''
|
32
|
+
engine = None
|
33
|
+
try:
|
34
|
+
if self.__engine is None:
|
35
|
+
if config_user:
|
36
|
+
config_init = config_user
|
37
|
+
else:
|
38
|
+
config_init = self.mysql_config
|
39
|
+
mysql_db = 'mysql://%s:%s@%s:%s/%s?charset=utf8' % (config_init['user_name'],
|
40
|
+
parse.quote_plus(config_init['password']),
|
41
|
+
config_init['host'],
|
42
|
+
config_init['port'],
|
43
|
+
config_init['db_name']
|
44
|
+
)
|
45
|
+
engine = create_engine(mysql_db, echo=False, pool_recycle=3600, pool_pre_ping=True)
|
46
|
+
self.__engine = engine
|
47
|
+
else:
|
48
|
+
engine = self.__engine
|
49
|
+
except Exception as ex:
|
50
|
+
logger.error(traceback.format_exc())
|
51
|
+
logger.error('deal_msg error: %s' % ex)
|
52
|
+
return engine
|
53
|
+
|
54
|
+
def execute(self, sql):
|
55
|
+
try:
|
56
|
+
# 创建数据库引擎
|
57
|
+
engine = self.get_mysql_client()
|
58
|
+
# 定义SQL查询语句
|
59
|
+
execute_stmt = text(sql)
|
60
|
+
with engine.connect() as connection:
|
61
|
+
try:
|
62
|
+
result = connection.execute(execute_stmt)
|
63
|
+
connection.commit()
|
64
|
+
except Exception as e:
|
65
|
+
logger.error(traceback.format_exc())
|
66
|
+
logger.error('deal_msg error: %s' % e)
|
67
|
+
connection.rollback()
|
68
|
+
except Exception as ex:
|
69
|
+
logger.error(traceback.format_exc())
|
70
|
+
logger.error('deal_msg error: %s' % ex)
|
71
|
+
|
72
|
+
def query(self, sql) -> list[dict]:
|
73
|
+
try:
|
74
|
+
# 创建数据库引擎
|
75
|
+
engine = self.get_mysql_client()
|
76
|
+
|
77
|
+
# 定义SQL查询语句
|
78
|
+
select_stmt = text(sql)
|
79
|
+
|
80
|
+
# 使用连接执行查询
|
81
|
+
result_list = []
|
82
|
+
with engine.connect() as connection:
|
83
|
+
result = connection.execute(select_stmt)
|
84
|
+
|
85
|
+
# 将查询结果转换为字典列表
|
86
|
+
# 使用fetchall()获取所有结果行,每行是一个元组
|
87
|
+
# 使用namedtuple来获取列名和数据的对应关系
|
88
|
+
columns = result.keys()
|
89
|
+
result_list = [dict(zip(columns, row)) for row in result]
|
90
|
+
except Exception as ex:
|
91
|
+
logger.error(traceback.format_exc())
|
92
|
+
logger.error('deal_msg error: %s' % ex)
|
93
|
+
return result_list
|
94
|
+
|
95
|
+
@staticmethod
|
96
|
+
def get_insert_schema(filed_names_list):
|
97
|
+
schema_final = ""
|
98
|
+
val_data = ""
|
99
|
+
for item in filed_names_list:
|
100
|
+
schema_final = schema_final + "%s, " % item.strip()
|
101
|
+
val_data = val_data + ":%s, " % item.strip()
|
102
|
+
schema_final = schema_final.strip(" ,")
|
103
|
+
val_data = val_data.strip(" ,")
|
104
|
+
return schema_final, val_data
|
105
|
+
|
106
|
+
def bulk_insert(self, table_name: str, columns: list, data_list: list, batch_size=20000, columns_on_duplicate=[]):
|
107
|
+
"""
|
108
|
+
执行分批批量插入操作的通用函数。
|
109
|
+
|
110
|
+
:param columns_on_duplicate: 唯一键冲突时覆盖
|
111
|
+
:param table_name: 要插入数据的表名
|
112
|
+
:param columns: 表的列名列表
|
113
|
+
:param data_list: 要插入的数据列表,其中每个元素是一个包含列值的元组
|
114
|
+
:param batch_size: 每批插入的数据量
|
115
|
+
"""
|
116
|
+
# 创建数据库引擎
|
117
|
+
engine = self.get_mysql_client()
|
118
|
+
|
119
|
+
on_duplicate_sql = ""
|
120
|
+
if columns_on_duplicate:
|
121
|
+
tmp_list = []
|
122
|
+
for item in columns_on_duplicate:
|
123
|
+
tmp_list.append("%s=VALUES(%s)" % (item, item))
|
124
|
+
if tmp_list:
|
125
|
+
on_duplicate_sql = "ON DUPLICATE KEY UPDATE %s" % ", ".join(tmp_list)
|
126
|
+
|
127
|
+
# 准备批量插入的SQL语句模板
|
128
|
+
schema_final, placeholders = self.get_insert_schema(columns)
|
129
|
+
insert_stmt = text(f"INSERT INTO {table_name} ({schema_final}) VALUES ({placeholders}) {on_duplicate_sql}")
|
130
|
+
logger.info("BulkInsert:[%s]" % str(insert_stmt))
|
131
|
+
|
132
|
+
try:
|
133
|
+
# 使用连接执行分批批量插入
|
134
|
+
with engine.connect() as connection:
|
135
|
+
try:
|
136
|
+
for i in range(0, len(data_list), batch_size):
|
137
|
+
# 获取当前批次的数据
|
138
|
+
batch_data = data_list[i:i + batch_size]
|
139
|
+
# 执行批量插入
|
140
|
+
connection.execute(insert_stmt, batch_data)
|
141
|
+
logger.info(f"Batch inserted {len(batch_data)} records.")
|
142
|
+
|
143
|
+
connection.commit()
|
144
|
+
logger.debug(f"Successfully inserted all data into {table_name},inserted {len(batch_data)} records.")
|
145
|
+
except Exception as e:
|
146
|
+
logger.error(traceback.format_exc())
|
147
|
+
logger.error('deal_msg error: %s' % e)
|
148
|
+
connection.rollback()
|
149
|
+
except Exception as ex:
|
150
|
+
logger.error(traceback.format_exc())
|
151
|
+
logger.error('deal_msg error: %s' % ex)
|
File without changes
|
File without changes
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
import _thread
|
3
3
|
import argparse
|
4
|
+
import asyncio
|
4
5
|
import importlib
|
5
6
|
import os
|
6
7
|
import pprint
|
@@ -120,6 +121,38 @@ return-val
|
|
120
121
|
return result
|
121
122
|
|
122
123
|
|
124
|
+
async def run_command_async(command, timeout=5):
|
125
|
+
process = None
|
126
|
+
try:
|
127
|
+
process = await asyncio.create_subprocess_shell(
|
128
|
+
command,
|
129
|
+
|
130
|
+
stdout=asyncio.subprocess.PIPE,
|
131
|
+
stderr=asyncio.subprocess.PIPE
|
132
|
+
)
|
133
|
+
stdout, stderr = await asyncio.wait_for(process.communicate(), timeout=timeout)
|
134
|
+
ret = {
|
135
|
+
"exit_code": process.returncode,
|
136
|
+
"stdout": stdout,
|
137
|
+
"stderr": stderr
|
138
|
+
}
|
139
|
+
return ret
|
140
|
+
except asyncio.TimeoutError:
|
141
|
+
if process and process.returncode is None:
|
142
|
+
process.terminate()
|
143
|
+
ret = {
|
144
|
+
"exit_code": -1,
|
145
|
+
"stdout": None,
|
146
|
+
"stderr": f"Command timed out after {timeout} seconds."
|
147
|
+
}
|
148
|
+
return ret
|
149
|
+
|
150
|
+
|
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))
|
154
|
+
|
155
|
+
|
123
156
|
def exec_shell(cmd, timeout=0, bufsize=0, executable=None,
|
124
157
|
stdin=None, stdout=None, stderr=None,
|
125
158
|
preexec_fn=None, close_fds=False, shell=False,
|
File without changes
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
from log4python.Log4python import log
|
3
|
+
from toolkits.system.basic_utils import get_script_directory, add_relative_search_path
|
4
|
+
|
5
|
+
logger = log("tookitsApp")
|
6
|
+
|
7
|
+
|
8
|
+
class tookitsApp:
|
9
|
+
app_name = 'tookits'
|
10
|
+
config_file_path = None
|
11
|
+
|
12
|
+
def __init__(self):
|
13
|
+
self.__base_path = get_script_directory()
|
14
|
+
|
15
|
+
|
16
|
+
if __name__ == '__main__':
|
17
|
+
pass
|
@@ -0,0 +1,126 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
import sys
|
3
|
+
import traceback
|
4
|
+
|
5
|
+
import fire
|
6
|
+
from log4python.Log4python import log
|
7
|
+
from toolkits.system.basic_utils import get_script_directory
|
8
|
+
|
9
|
+
from libs_core.env_prepare import EnvPrepare
|
10
|
+
from tookits_app import tookitsApp
|
11
|
+
from libs_core.process_admin import ProcessAdmin
|
12
|
+
from db_query_demo import DbQueryDemo
|
13
|
+
|
14
|
+
logger = log("tookits")
|
15
|
+
|
16
|
+
|
17
|
+
class tookits:
|
18
|
+
def __init__(self, config_path=None):
|
19
|
+
self.__base_path = get_script_directory()
|
20
|
+
if config_path is None:
|
21
|
+
self.__env = EnvPrepare(tookitsApp.app_name)
|
22
|
+
self.__env.check_env()
|
23
|
+
self.__config_path = self.__env.get_config_path("config.py")
|
24
|
+
self.__env.check_config_ready(self.__config_path, "请先初始化配置文件、在数据库创建相应的数据表")
|
25
|
+
else:
|
26
|
+
tookitsApp.config_file_path = config_path
|
27
|
+
self.db_query = DbQueryDemo
|
28
|
+
self.__db_list = self.__env.get_config("db_list")
|
29
|
+
# self.auto_stat_stock = AutoStatStock(self.__db_list['dev_ops'])
|
30
|
+
self.__configChatGroups = ConfigGroupsHelper(self.__env.get_config('db_list'), 'dict')
|
31
|
+
self.__process_admin = ProcessAdmin()
|
32
|
+
|
33
|
+
def show_db_list(self):
|
34
|
+
"""
|
35
|
+
列表查看数据库信息
|
36
|
+
:return:
|
37
|
+
"""
|
38
|
+
self.__configChatGroups.list_config_groups("RDS-连接")
|
39
|
+
|
40
|
+
def init_config(self, path_target):
|
41
|
+
src_path = "%s/config/" % self.__base_path
|
42
|
+
self.__env.init_default_config("directory", src_path, path_target)
|
43
|
+
|
44
|
+
def init_database(self):
|
45
|
+
ddl_sql_list = self.__get_db_ddl_list("policy_status_monitor")
|
46
|
+
for ddl_sql in ddl_sql_list:
|
47
|
+
database_config = self.__env.get_config(self.__config_path, "database_config")
|
48
|
+
self.__env.init_db(database_config['mysql'], ddl_sql)
|
49
|
+
|
50
|
+
def __schedule_tasks(self):
|
51
|
+
self.__process_admin.loop_check_exit()
|
52
|
+
# self.auto_stat_stock.schedule_start()
|
53
|
+
|
54
|
+
def __recall_tasks(self):
|
55
|
+
self.__process_admin.loop_check_exit()
|
56
|
+
logger.info("DBinfo: %s", json.dumps(self.__db_list['dev_ops'], ensure_ascii=True))
|
57
|
+
# app = StrategyRecall(mysql_conn_info=self.__db_list['dev_ops'])
|
58
|
+
# app.process_buy_sale_data("stock_buy_sale_data", "group_test_01")
|
59
|
+
|
60
|
+
def start_all_tasks(self):
|
61
|
+
tasks_list = [
|
62
|
+
self.__schedule_tasks,
|
63
|
+
self.__recall_tasks
|
64
|
+
]
|
65
|
+
self.__process_admin.processes_start(tasks_list)
|
66
|
+
|
67
|
+
@staticmethod
|
68
|
+
def __get_db_ddl_list(table_name):
|
69
|
+
ddl_sql = ["""CREATE TABLE `%s` (
|
70
|
+
`task_id` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL,
|
71
|
+
`task_name` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
|
72
|
+
`task_status` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '0:关闭,1:启用,8:暂停',
|
73
|
+
`desc` varchar(500) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
|
74
|
+
`task_type` varchar(30) COLLATE utf8mb4_unicode_ci NOT NULL,
|
75
|
+
`task_params` text COLLATE utf8mb4_unicode_ci NOT NULL,
|
76
|
+
`task_crontab` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
|
77
|
+
`action_type` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
|
78
|
+
`action_params` text COLLATE utf8mb4_unicode_ci NOT NULL,
|
79
|
+
`event_id` varchar(32) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
|
80
|
+
`check_condition` varchar(1000) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
|
81
|
+
`db_config` varchar(1000) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
|
82
|
+
`extra_data` varchar(1000) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
|
83
|
+
PRIMARY KEY (`task_id`)
|
84
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;""" % table_name,
|
85
|
+
"""INSERT INTO """ + table_name + """
|
86
|
+
(task_id, task_name, task_status, `desc`, task_type, task_params, task_crontab, action_type, action_params, event_id, check_condition, db_config, extra_data)
|
87
|
+
VALUES('00065df8eb99442db2808ee19592000x', 'task_50031_dlp_dchat', '0', '策略产出监控-DLP-Dchat安装状态监控', 'sql', 'select mc_rule as event_id, FROM_UNIXTIME(occur_ts/1000,''%%Y-%%m-%%d'') as event_time, count(*) as event_value, "" as event_detail
|
88
|
+
from online_alarm oa
|
89
|
+
where occur_ts >= unix_timestamp(concat(CURDATE(), " 00:00:00")) * 1000
|
90
|
+
and occur_ts < unix_timestamp(concat(ADDDATE(CURDATE(), 1), " 00:00:00")) * 1000
|
91
|
+
and mc_rule = ''20071''
|
92
|
+
group by FROM_UNIXTIME(occur_ts/1000,''%%Y-%%m-%%d''),mc_rule
|
93
|
+
limit 1', '15 20 * * *', 'email', '{
|
94
|
+
"event_id": "50031",
|
95
|
+
"event_action": {
|
96
|
+
"ding_talk": {
|
97
|
+
"group_info": {
|
98
|
+
"name": "long_term_query_talk",
|
99
|
+
"desc": "长期查询监控群",
|
100
|
+
"web_hook": "https://oapi.dingtalk.com/robot/send?access_token=69b8e2bae810c9f392b197072699a8241e0a25552291789128cbe5c805cfd5da"
|
101
|
+
},
|
102
|
+
"group_target": "long_term_query_talk"
|
103
|
+
}
|
104
|
+
}
|
105
|
+
}', '50031', 'event_value < 5000', '{
|
106
|
+
"user": "db_admin",
|
107
|
+
"pwd": "gYrmHFNOpkIb/UNM5zCuiDScMdCPwsneOoV38RbEYOs=",
|
108
|
+
"host": "10.83.16.15",
|
109
|
+
"port": 8012,
|
110
|
+
"db_name": "sec_admin"
|
111
|
+
}', NULL);
|
112
|
+
;"""
|
113
|
+
]
|
114
|
+
return ddl_sql
|
115
|
+
|
116
|
+
|
117
|
+
def main():
|
118
|
+
try:
|
119
|
+
fire.Fire(tookits)
|
120
|
+
except Exception as ex:
|
121
|
+
logger.error("Error: %s" % ex)
|
122
|
+
logger.error(traceback.format_exc())
|
123
|
+
|
124
|
+
|
125
|
+
if __name__ == '__main__':
|
126
|
+
main()
|
File without changes
|
@@ -0,0 +1,19 @@
|
|
1
|
+
"""
|
2
|
+
Tests for `tookits` module.
|
3
|
+
"""
|
4
|
+
import pytest
|
5
|
+
from toolkits import tookits
|
6
|
+
|
7
|
+
|
8
|
+
class TestTookits(object):
|
9
|
+
|
10
|
+
@classmethod
|
11
|
+
def setup_class(cls):
|
12
|
+
pass
|
13
|
+
|
14
|
+
def test_something(self):
|
15
|
+
pass
|
16
|
+
|
17
|
+
@classmethod
|
18
|
+
def teardown_class(cls):
|
19
|
+
pass
|
toolkits-0.2.6/MANIFEST.in
DELETED
toolkits-0.2.6/PKG-INFO
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
Metadata-Version: 2.1
|
2
|
-
Name: toolkits
|
3
|
-
Version: 0.2.6
|
4
|
-
Summary: toolkits for quickly reference
|
5
|
-
Home-page: https://github.com/starwithmoon/toolkits
|
6
|
-
Author: li_jia_yue
|
7
|
-
Author-email: 59727816@qq.com
|
8
|
-
License: BSD
|
9
|
-
Keywords: toolkits tools
|
10
|
-
Classifier: Development Status :: 3 - Alpha
|
11
|
-
Classifier: Framework :: Django
|
12
|
-
Classifier: Intended Audience :: Developers
|
13
|
-
Classifier: License :: OSI Approved :: BSD License
|
14
|
-
Classifier: Natural Language :: English
|
15
|
-
Classifier: Programming Language :: Python :: 2
|
16
|
-
Classifier: Programming Language :: Python :: 2.6
|
17
|
-
Classifier: Programming Language :: Python :: 2.7
|
18
|
-
Classifier: Programming Language :: Python :: 3.9
|
19
|
-
|
20
|
-
# toolkits
|
21
|
-
toolkits for quickly reference
|
22
|
-
|
23
|
-
|
toolkits-0.2.6/README.rst
DELETED
toolkits-0.2.6/setup.cfg
DELETED
toolkits-0.2.6/setup.py
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
import sys
|
2
|
-
from distutils.core import setup
|
3
|
-
from distutils.command.install import INSTALL_SCHEMES
|
4
|
-
|
5
|
-
from setuptools import find_packages
|
6
|
-
|
7
|
-
PACKAGE = "toolkits"
|
8
|
-
NAME = "toolkits"
|
9
|
-
DESCRIPTION = "toolkits for quickly reference"
|
10
|
-
AUTHOR = "li_jia_yue"
|
11
|
-
AUTHOR_EMAIL = "59727816@qq.com"
|
12
|
-
URL = "https://github.com/starwithmoon/toolkits"
|
13
|
-
VERSION = __import__(PACKAGE).__version__
|
14
|
-
|
15
|
-
setup(
|
16
|
-
name=NAME,
|
17
|
-
version=VERSION,
|
18
|
-
description=DESCRIPTION,
|
19
|
-
long_description=open("README.rst").read(),
|
20
|
-
author=AUTHOR,
|
21
|
-
author_email=AUTHOR_EMAIL,
|
22
|
-
license="BSD",
|
23
|
-
url=URL,
|
24
|
-
packages=find_packages(),
|
25
|
-
package_data={
|
26
|
-
# If any package contains *.txt files, include them:
|
27
|
-
'': ['*.dat']},
|
28
|
-
keywords='toolkits tools',
|
29
|
-
classifiers=[
|
30
|
-
'Development Status :: 3 - Alpha',
|
31
|
-
'Framework :: Django',
|
32
|
-
'Intended Audience :: Developers',
|
33
|
-
'License :: OSI Approved :: BSD License',
|
34
|
-
'Natural Language :: English',
|
35
|
-
"Programming Language :: Python :: 2",
|
36
|
-
'Programming Language :: Python :: 2.6',
|
37
|
-
'Programming Language :: Python :: 2.7',
|
38
|
-
'Programming Language :: Python :: 3.9',
|
39
|
-
],
|
40
|
-
install_requires=[
|
41
|
-
'schedule',
|
42
|
-
'unicodecsv', 'log4python', 'unipath', 'arrow', 'fire'
|
43
|
-
],
|
44
|
-
zip_safe=False,
|
45
|
-
)
|
@@ -1,23 +0,0 @@
|
|
1
|
-
Metadata-Version: 2.1
|
2
|
-
Name: toolkits
|
3
|
-
Version: 0.2.6
|
4
|
-
Summary: toolkits for quickly reference
|
5
|
-
Home-page: https://github.com/starwithmoon/toolkits
|
6
|
-
Author: li_jia_yue
|
7
|
-
Author-email: 59727816@qq.com
|
8
|
-
License: BSD
|
9
|
-
Keywords: toolkits tools
|
10
|
-
Classifier: Development Status :: 3 - Alpha
|
11
|
-
Classifier: Framework :: Django
|
12
|
-
Classifier: Intended Audience :: Developers
|
13
|
-
Classifier: License :: OSI Approved :: BSD License
|
14
|
-
Classifier: Natural Language :: English
|
15
|
-
Classifier: Programming Language :: Python :: 2
|
16
|
-
Classifier: Programming Language :: Python :: 2.6
|
17
|
-
Classifier: Programming Language :: Python :: 2.7
|
18
|
-
Classifier: Programming Language :: Python :: 3.9
|
19
|
-
|
20
|
-
# toolkits
|
21
|
-
toolkits for quickly reference
|
22
|
-
|
23
|
-
|
@@ -1,47 +0,0 @@
|
|
1
|
-
MANIFEST.in
|
2
|
-
README.rst
|
3
|
-
setup.py
|
4
|
-
toolkits/__init__.py
|
5
|
-
toolkits.egg-info/PKG-INFO
|
6
|
-
toolkits.egg-info/SOURCES.txt
|
7
|
-
toolkits.egg-info/dependency_links.txt
|
8
|
-
toolkits.egg-info/not-zip-safe
|
9
|
-
toolkits.egg-info/requires.txt
|
10
|
-
toolkits.egg-info/top_level.txt
|
11
|
-
toolkits/basic/__init__.py
|
12
|
-
toolkits/basic/list_helper.py
|
13
|
-
toolkits/databases/__init__.py
|
14
|
-
toolkits/databases/database_client_util.py
|
15
|
-
toolkits/databases/es_client.py
|
16
|
-
toolkits/databases/hive_client.py
|
17
|
-
toolkits/databases/hive_cmd.py
|
18
|
-
toolkits/databases/hive_helper.py
|
19
|
-
toolkits/databases/redis_mgmt.py
|
20
|
-
toolkits/databases/sql_helper.py
|
21
|
-
toolkits/databases/sqlalchemy_helper.py
|
22
|
-
toolkits/databases/status_check.py
|
23
|
-
toolkits/network/__init__.py
|
24
|
-
toolkits/network/ip_helper.py
|
25
|
-
toolkits/network/pdi_helper.py
|
26
|
-
toolkits/network/send_mail.py
|
27
|
-
toolkits/system/__init__.py
|
28
|
-
toolkits/system/aes_cipher.py
|
29
|
-
toolkits/system/basic_utils.py
|
30
|
-
toolkits/system/collections_helper.py
|
31
|
-
toolkits/system/crpyt_helper.py
|
32
|
-
toolkits/system/dict2xml.py
|
33
|
-
toolkits/system/dict_helper.py
|
34
|
-
toolkits/system/excel_helper.py
|
35
|
-
toolkits/system/file_helper.py
|
36
|
-
toolkits/system/load_module.py
|
37
|
-
toolkits/system/priority_tasks.py
|
38
|
-
toolkits/system/shell_helper.py
|
39
|
-
toolkits/system/str_helper.py
|
40
|
-
toolkits/system/time_helper.py
|
41
|
-
toolkits/system/win32_env.py
|
42
|
-
toolkits/system/process_monitor/__init__.py
|
43
|
-
toolkits/system/process_monitor/process_monitor.py
|
44
|
-
toolkits/system/tasks_deamon/__init__.py
|
45
|
-
toolkits/system/tasks_deamon/tasks_controller.py
|
46
|
-
toolkits/system/tasks_deamon/tasks_multiprocessing.py
|
47
|
-
toolkits/system/tasks_deamon/tasks_process.py
|
@@ -1 +0,0 @@
|
|
1
|
-
|
@@ -1 +0,0 @@
|
|
1
|
-
|
@@ -1 +0,0 @@
|
|
1
|
-
toolkits
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{toolkits-0.2.6/toolkits/system/process_monitor → toolkits-0.2.7/src/toolkits/libs_core}/__init__.py
RENAMED
File without changes
|
{toolkits-0.2.6/toolkits/system/tasks_deamon → toolkits-0.2.7/src/toolkits/network}/__init__.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|