pixelarraylib 1.1.5__tar.gz → 1.1.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.
- {pixelarraylib-1.1.5/pixelarraylib.egg-info → pixelarraylib-1.1.7}/PKG-INFO +6 -4
- {pixelarraylib-1.1.5 → pixelarraylib-1.1.7}/pixelarraylib/__init__.py +1 -1
- {pixelarraylib-1.1.5 → pixelarraylib-1.1.7}/pixelarraylib/__main__.py +4 -0
- {pixelarraylib-1.1.5 → pixelarraylib-1.1.7}/pixelarraylib/aliyun/acr.py +14 -0
- {pixelarraylib-1.1.5 → pixelarraylib-1.1.7}/pixelarraylib/aliyun/aliyun_email.py +7 -0
- {pixelarraylib-1.1.5 → pixelarraylib-1.1.7}/pixelarraylib/aliyun/billing.py +17 -1
- {pixelarraylib-1.1.5 → pixelarraylib-1.1.7}/pixelarraylib/aliyun/content_scanner.py +8 -0
- {pixelarraylib-1.1.5 → pixelarraylib-1.1.7}/pixelarraylib/aliyun/domain.py +17 -0
- {pixelarraylib-1.1.5 → pixelarraylib-1.1.7}/pixelarraylib/aliyun/ecs.py +8 -0
- {pixelarraylib-1.1.5 → pixelarraylib-1.1.7}/pixelarraylib/aliyun/eip.py +14 -0
- {pixelarraylib-1.1.5 → pixelarraylib-1.1.7}/pixelarraylib/aliyun/fc.py +31 -0
- {pixelarraylib-1.1.5 → pixelarraylib-1.1.7}/pixelarraylib/aliyun/oss.py +10 -0
- {pixelarraylib-1.1.5 → pixelarraylib-1.1.7}/pixelarraylib/aliyun/sms.py +17 -3
- {pixelarraylib-1.1.5 → pixelarraylib-1.1.7}/pixelarraylib/aliyun/sts.py +11 -0
- {pixelarraylib-1.1.5 → pixelarraylib-1.1.7}/pixelarraylib/db_utils/mysql.py +96 -14
- {pixelarraylib-1.1.5 → pixelarraylib-1.1.7}/pixelarraylib/db_utils/redis.py +29 -1
- {pixelarraylib-1.1.5 → pixelarraylib-1.1.7}/pixelarraylib/decorators/decorators.py +97 -0
- {pixelarraylib-1.1.5 → pixelarraylib-1.1.7}/pixelarraylib/gitlab/code_analyzer.py +31 -4
- {pixelarraylib-1.1.5 → pixelarraylib-1.1.7}/pixelarraylib/gitlab/pypi_package_manager.py +8 -0
- {pixelarraylib-1.1.5 → pixelarraylib-1.1.7}/pixelarraylib/monitor/feishu.py +8 -0
- {pixelarraylib-1.1.5 → pixelarraylib-1.1.7}/pixelarraylib/scripts/__init__.py +1 -1
- {pixelarraylib-1.1.5 → pixelarraylib-1.1.7}/pixelarraylib/scripts/build_website.py +34 -0
- {pixelarraylib-1.1.5 → pixelarraylib-1.1.7}/pixelarraylib/scripts/collect_code_to_txt.py +96 -10
- {pixelarraylib-1.1.5 → pixelarraylib-1.1.7}/pixelarraylib/scripts/create_test_case_files.py +12 -0
- {pixelarraylib-1.1.5 → pixelarraylib-1.1.7}/pixelarraylib/scripts/nginx_proxy_to_ecs.py +33 -0
- {pixelarraylib-1.1.5 → pixelarraylib-1.1.7}/pixelarraylib/scripts/remove_empty_lines.py +4 -1
- pixelarraylib-1.1.7/pixelarraylib/system/cron_manager.py +535 -0
- {pixelarraylib-1.1.5 → pixelarraylib-1.1.7}/pixelarraylib/system/tson.py +4 -0
- pixelarraylib-1.1.7/pixelarraylib/utils/name_generator.py +144 -0
- {pixelarraylib-1.1.5 → pixelarraylib-1.1.7/pixelarraylib.egg-info}/PKG-INFO +6 -4
- {pixelarraylib-1.1.5 → pixelarraylib-1.1.7}/pixelarraylib.egg-info/SOURCES.txt +3 -2
- {pixelarraylib-1.1.5 → pixelarraylib-1.1.7}/pixelarraylib.egg-info/requires.txt +6 -4
- {pixelarraylib-1.1.5 → pixelarraylib-1.1.7}/pyproject.toml +7 -5
- {pixelarraylib-1.1.5 → pixelarraylib-1.1.7}/requirements.txt +3 -1
- pixelarraylib-1.1.5/pixelarraylib/net/request.py +0 -143
- {pixelarraylib-1.1.5 → pixelarraylib-1.1.7}/LICENSE +0 -0
- {pixelarraylib-1.1.5 → pixelarraylib-1.1.7}/MANIFEST.in +0 -0
- {pixelarraylib-1.1.5 → pixelarraylib-1.1.7}/README.md +0 -0
- {pixelarraylib-1.1.5 → pixelarraylib-1.1.7}/pixelarraylib/aliyun/__init__.py +0 -0
- {pixelarraylib-1.1.5 → pixelarraylib-1.1.7}/pixelarraylib/aliyun/eci.py +0 -0
- {pixelarraylib-1.1.5 → pixelarraylib-1.1.7}/pixelarraylib/decorators/__init__.py +0 -0
- {pixelarraylib-1.1.5 → pixelarraylib-1.1.7}/pixelarraylib/gitlab/__init__.py +0 -0
- {pixelarraylib-1.1.5 → pixelarraylib-1.1.7}/pixelarraylib/monitor/__init__.py +0 -0
- {pixelarraylib-1.1.5 → pixelarraylib-1.1.7}/pixelarraylib/scripts/tson_convert.py +0 -0
- {pixelarraylib-1.1.5 → pixelarraylib-1.1.7}/pixelarraylib/system/__init__.py +0 -0
- {pixelarraylib-1.1.5 → pixelarraylib-1.1.7}/pixelarraylib/system/common.py +0 -0
- {pixelarraylib-1.1.5 → pixelarraylib-1.1.7}/pixelarraylib.egg-info/dependency_links.txt +0 -0
- {pixelarraylib-1.1.5 → pixelarraylib-1.1.7}/pixelarraylib.egg-info/entry_points.txt +0 -0
- {pixelarraylib-1.1.5 → pixelarraylib-1.1.7}/pixelarraylib.egg-info/top_level.txt +0 -0
- {pixelarraylib-1.1.5 → pixelarraylib-1.1.7}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pixelarraylib
|
|
3
|
-
Version: 1.1.
|
|
3
|
+
Version: 1.1.7
|
|
4
4
|
Summary: PixelArray Python开发工具库 - 包含阿里云服务、数据库工具、装饰器、监控等功能
|
|
5
5
|
Author-email: Lu qi <qi.lu@pixelarrayai.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -29,6 +29,9 @@ Provides-Extra: system
|
|
|
29
29
|
Requires-Dist: cryptography; extra == "system"
|
|
30
30
|
Requires-Dist: paramiko; extra == "system"
|
|
31
31
|
Requires-Dist: requests; extra == "system"
|
|
32
|
+
Provides-Extra: utils
|
|
33
|
+
Requires-Dist: names; extra == "utils"
|
|
34
|
+
Requires-Dist: Faker; extra == "utils"
|
|
32
35
|
Provides-Extra: mysql
|
|
33
36
|
Requires-Dist: pymysql; extra == "mysql"
|
|
34
37
|
Requires-Dist: aiomysql; extra == "mysql"
|
|
@@ -36,9 +39,6 @@ Requires-Dist: requests; extra == "mysql"
|
|
|
36
39
|
Provides-Extra: redis
|
|
37
40
|
Requires-Dist: redis; extra == "redis"
|
|
38
41
|
Requires-Dist: requests; extra == "redis"
|
|
39
|
-
Provides-Extra: net
|
|
40
|
-
Requires-Dist: requests; extra == "net"
|
|
41
|
-
Requires-Dist: aiohttp; extra == "net"
|
|
42
42
|
Provides-Extra: gitlab
|
|
43
43
|
Requires-Dist: requests; extra == "gitlab"
|
|
44
44
|
Requires-Dist: aiohttp; extra == "gitlab"
|
|
@@ -161,6 +161,8 @@ Requires-Dist: requests; extra == "all"
|
|
|
161
161
|
Requires-Dist: aiohttp; extra == "all"
|
|
162
162
|
Requires-Dist: aiofiles; extra == "all"
|
|
163
163
|
Requires-Dist: pandas; extra == "all"
|
|
164
|
+
Requires-Dist: names; extra == "all"
|
|
165
|
+
Requires-Dist: Faker; extra == "all"
|
|
164
166
|
Dynamic: license-file
|
|
165
167
|
|
|
166
168
|
# PixelArrayLib - PixelArray Python开发工具库
|
|
@@ -18,12 +18,26 @@ feishu_alert = Feishu("devtoolkit服务报警")
|
|
|
18
18
|
|
|
19
19
|
class ACRUtils:
|
|
20
20
|
def __init__(self, region_id: str, access_key_id: str, access_key_secret: str):
|
|
21
|
+
"""
|
|
22
|
+
description:
|
|
23
|
+
初始化ACR(容器镜像服务)工具类
|
|
24
|
+
parameters:
|
|
25
|
+
region_id(str): 阿里云区域ID
|
|
26
|
+
access_key_id(str): 阿里云访问密钥ID
|
|
27
|
+
access_key_secret(str): 阿里云访问密钥Secret
|
|
28
|
+
"""
|
|
21
29
|
self.region_id = region_id
|
|
22
30
|
self.access_key_id = access_key_id
|
|
23
31
|
self.access_key_secret = access_key_secret
|
|
24
32
|
self.client = self._create_client()
|
|
25
33
|
|
|
26
34
|
def _create_client(self):
|
|
35
|
+
"""
|
|
36
|
+
description:
|
|
37
|
+
创建ACR客户端
|
|
38
|
+
return:
|
|
39
|
+
client(cr20181201Client): ACR客户端对象
|
|
40
|
+
"""
|
|
27
41
|
credential = CredentialClient()
|
|
28
42
|
config = open_api_models.Config(
|
|
29
43
|
credential=credential,
|
|
@@ -14,6 +14,13 @@ feishu_alert = Feishu("devtoolkit服务报警")
|
|
|
14
14
|
|
|
15
15
|
class AliyunEmailSender:
|
|
16
16
|
def __init__(self, access_key_id, access_key_secret):
|
|
17
|
+
"""
|
|
18
|
+
description:
|
|
19
|
+
初始化阿里云邮件发送工具类
|
|
20
|
+
parameters:
|
|
21
|
+
access_key_id(str): 阿里云访问密钥ID
|
|
22
|
+
access_key_secret(str): 阿里云访问密钥Secret
|
|
23
|
+
"""
|
|
17
24
|
self.client = Dm20151123Client(
|
|
18
25
|
open_api_models.Config(
|
|
19
26
|
access_key_id=access_key_id,
|
|
@@ -87,7 +87,15 @@ class BillingUtils:
|
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
def add_comment(value, field_name):
|
|
90
|
-
"""
|
|
90
|
+
"""
|
|
91
|
+
description:
|
|
92
|
+
为字段值添加注释
|
|
93
|
+
parameters:
|
|
94
|
+
value(Any): 字段值
|
|
95
|
+
field_name(str): 字段名称
|
|
96
|
+
return:
|
|
97
|
+
value_with_comment(str): 带注释的字段值
|
|
98
|
+
"""
|
|
91
99
|
if with_comments and field_name in field_comments:
|
|
92
100
|
return f"{value} # {field_comments[field_name]}"
|
|
93
101
|
return value
|
|
@@ -391,6 +399,14 @@ class BillingUtils:
|
|
|
391
399
|
# 2) 去除首尾空白,并将内部连续空白压缩为一个空格
|
|
392
400
|
# 3) 去除常见的不可见空白字符(如不间断空格、零宽空格)
|
|
393
401
|
def _clean_string(value):
|
|
402
|
+
"""
|
|
403
|
+
description:
|
|
404
|
+
清洗字符串,去除注释、不可见字符并规范化空白
|
|
405
|
+
parameters:
|
|
406
|
+
value(Any): 需要清洗的值
|
|
407
|
+
return:
|
|
408
|
+
cleaned_value(Any): 清洗后的值
|
|
409
|
+
"""
|
|
394
410
|
if not isinstance(value, str):
|
|
395
411
|
return value
|
|
396
412
|
# 去注释
|
|
@@ -18,6 +18,14 @@ feishu_alert = Feishu("devtoolkit服务报警")
|
|
|
18
18
|
|
|
19
19
|
class ContentScanner:
|
|
20
20
|
def __init__(self, access_key_id, access_key_secret, region_id):
|
|
21
|
+
"""
|
|
22
|
+
description:
|
|
23
|
+
初始化内容安全扫描工具类
|
|
24
|
+
parameters:
|
|
25
|
+
access_key_id(str): 阿里云访问密钥ID
|
|
26
|
+
access_key_secret(str): 阿里云访问密钥Secret
|
|
27
|
+
region_id(str): 阿里云区域ID
|
|
28
|
+
"""
|
|
21
29
|
self.client = Client(
|
|
22
30
|
Config(
|
|
23
31
|
access_key_id=access_key_id,
|
|
@@ -7,12 +7,29 @@ from typing import Optional, Dict, Any
|
|
|
7
7
|
|
|
8
8
|
class DomainUtils:
|
|
9
9
|
def __init__(self, access_key_id: str, access_key_secret: str, domain_name: str):
|
|
10
|
+
"""
|
|
11
|
+
description:
|
|
12
|
+
初始化域名服务工具类
|
|
13
|
+
parameters:
|
|
14
|
+
access_key_id(str): 阿里云访问密钥ID
|
|
15
|
+
access_key_secret(str): 阿里云访问密钥Secret
|
|
16
|
+
domain_name(str): 域名名称
|
|
17
|
+
"""
|
|
10
18
|
self.domain_name = domain_name
|
|
11
19
|
self.client = self._create_client(access_key_id, access_key_secret)
|
|
12
20
|
|
|
13
21
|
def _create_client(
|
|
14
22
|
self, access_key_id: str, access_key_secret: str
|
|
15
23
|
) -> Alidns20150109Client:
|
|
24
|
+
"""
|
|
25
|
+
description:
|
|
26
|
+
创建阿里云DNS客户端
|
|
27
|
+
parameters:
|
|
28
|
+
access_key_id(str): 阿里云访问密钥ID
|
|
29
|
+
access_key_secret(str): 阿里云访问密钥Secret
|
|
30
|
+
return:
|
|
31
|
+
client(Alidns20150109Client): DNS客户端对象
|
|
32
|
+
"""
|
|
16
33
|
config = open_api_models.Config(
|
|
17
34
|
access_key_id=access_key_id,
|
|
18
35
|
access_key_secret=access_key_secret,
|
|
@@ -8,6 +8,14 @@ from alibabacloud_tea_util import models as util_models
|
|
|
8
8
|
|
|
9
9
|
class ECSUtils:
|
|
10
10
|
def __init__(self, access_key_id: str, access_key_secret: str, region_id: str):
|
|
11
|
+
"""
|
|
12
|
+
description:
|
|
13
|
+
初始化ECS(弹性计算服务)工具类
|
|
14
|
+
parameters:
|
|
15
|
+
access_key_id(str): 阿里云访问密钥ID
|
|
16
|
+
access_key_secret(str): 阿里云访问密钥Secret
|
|
17
|
+
region_id(str): 阿里云区域ID
|
|
18
|
+
"""
|
|
11
19
|
self.cms_client = Cms20190101Client(
|
|
12
20
|
open_api_models.Config(
|
|
13
21
|
type="access_key",
|
|
@@ -15,12 +15,26 @@ feishu_alert = Feishu("devtoolkit服务报警")
|
|
|
15
15
|
|
|
16
16
|
class EIPUtils:
|
|
17
17
|
def __init__(self, region_id: str, access_key_id: str, access_key_secret: str):
|
|
18
|
+
"""
|
|
19
|
+
description:
|
|
20
|
+
初始化EIP工具类
|
|
21
|
+
parameters:
|
|
22
|
+
region_id(str): 地域ID
|
|
23
|
+
access_key_id(str): 访问密钥ID
|
|
24
|
+
access_key_secret(str): 访问密钥Secret
|
|
25
|
+
"""
|
|
18
26
|
self.region_id = region_id
|
|
19
27
|
self.access_key_id = access_key_id
|
|
20
28
|
self.access_key_secret = access_key_secret
|
|
21
29
|
self.client = self._create_client()
|
|
22
30
|
|
|
23
31
|
def _create_client(self) -> Vpc20160428Client:
|
|
32
|
+
"""
|
|
33
|
+
description:
|
|
34
|
+
创建EIP客户端
|
|
35
|
+
return:
|
|
36
|
+
Vpc20160428Client: EIP客户端实例
|
|
37
|
+
"""
|
|
24
38
|
config = open_api_models.Config(
|
|
25
39
|
access_key_id=self.access_key_id,
|
|
26
40
|
access_key_secret=self.access_key_secret,
|
|
@@ -16,6 +16,15 @@ feishu_alert = Feishu("devtoolkit服务报警")
|
|
|
16
16
|
|
|
17
17
|
class FCUtils:
|
|
18
18
|
def __init__(self, access_key_id, access_key_secret, account_id, region_id):
|
|
19
|
+
"""
|
|
20
|
+
description:
|
|
21
|
+
初始化函数计算(FC)工具类
|
|
22
|
+
parameters:
|
|
23
|
+
access_key_id(str): 阿里云访问密钥ID
|
|
24
|
+
access_key_secret(str): 阿里云访问密钥Secret
|
|
25
|
+
account_id(str): 阿里云账号ID
|
|
26
|
+
region_id(str): 阿里云区域ID
|
|
27
|
+
"""
|
|
19
28
|
self.client = FC20230330Client(
|
|
20
29
|
open_api_models.Config(
|
|
21
30
|
access_key_id=access_key_id,
|
|
@@ -31,6 +40,18 @@ class FCUtils:
|
|
|
31
40
|
retry: int = 5,
|
|
32
41
|
timeout: int = 6000 * 1000,
|
|
33
42
|
) -> tuple[str, bool]:
|
|
43
|
+
"""
|
|
44
|
+
description:
|
|
45
|
+
调用函数计算服务中的函数
|
|
46
|
+
parameters:
|
|
47
|
+
function_name(str): 函数名称
|
|
48
|
+
params(dict): 函数参数
|
|
49
|
+
retry(int): 重试次数,默认为5
|
|
50
|
+
timeout(int): 超时时间(毫秒),默认为6000秒
|
|
51
|
+
return:
|
|
52
|
+
result(str): 函数执行结果
|
|
53
|
+
success(bool): 是否调用成功
|
|
54
|
+
"""
|
|
34
55
|
last_exception = None
|
|
35
56
|
for i in range(retry):
|
|
36
57
|
try:
|
|
@@ -80,6 +101,16 @@ class FCUtils:
|
|
|
80
101
|
dir_path: str,
|
|
81
102
|
retry: int = 5,
|
|
82
103
|
) -> tuple[str, bool]:
|
|
104
|
+
"""
|
|
105
|
+
description:
|
|
106
|
+
更新函数计算服务中的函数代码
|
|
107
|
+
parameters:
|
|
108
|
+
function_name(str): 函数名称
|
|
109
|
+
dir_path(str): 代码目录路径
|
|
110
|
+
retry(int): 重试次数,默认为5
|
|
111
|
+
return:
|
|
112
|
+
success(bool): 是否更新成功
|
|
113
|
+
"""
|
|
83
114
|
last_exception = None
|
|
84
115
|
for i in range(retry):
|
|
85
116
|
try:
|
|
@@ -29,6 +29,16 @@ class OSSUtils:
|
|
|
29
29
|
bucket_name,
|
|
30
30
|
use_vpc=False,
|
|
31
31
|
):
|
|
32
|
+
"""
|
|
33
|
+
description:
|
|
34
|
+
初始化OSS工具类
|
|
35
|
+
parameters:
|
|
36
|
+
access_key_id(str): 阿里云访问密钥ID
|
|
37
|
+
access_key_secret(str): 阿里云访问密钥Secret
|
|
38
|
+
region_id(str): 阿里云区域ID
|
|
39
|
+
bucket_name(str): OSS存储桶名称
|
|
40
|
+
use_vpc(bool): 是否使用VPC内网端点,默认为False
|
|
41
|
+
"""
|
|
32
42
|
self.bucket_name = bucket_name
|
|
33
43
|
if use_vpc:
|
|
34
44
|
self.endpoint = f"https://oss-{region_id}-internal.aliyuncs.com"
|
|
@@ -12,6 +12,13 @@ feishu_alert = Feishu("devtoolkit服务报警")
|
|
|
12
12
|
|
|
13
13
|
class SMSUtils:
|
|
14
14
|
def __init__(self, access_key_id, access_key_secret):
|
|
15
|
+
"""
|
|
16
|
+
description:
|
|
17
|
+
初始化短信服务工具类
|
|
18
|
+
parameters:
|
|
19
|
+
access_key_id(str): 阿里云访问密钥ID
|
|
20
|
+
access_key_secret(str): 阿里云访问密钥Secret
|
|
21
|
+
"""
|
|
15
22
|
self.sms_cilent = Dysmsapi20170525Client(
|
|
16
23
|
open_api_models.Config(
|
|
17
24
|
type="access_key",
|
|
@@ -36,9 +43,9 @@ class SMSUtils:
|
|
|
36
43
|
"""
|
|
37
44
|
description:
|
|
38
45
|
发送验证码给指定手机号
|
|
39
|
-
|
|
40
|
-
phone_numbers: 手机号
|
|
41
|
-
verification_code: 验证码(6位数字)
|
|
46
|
+
parameters:
|
|
47
|
+
phone_numbers(str): 手机号
|
|
48
|
+
verification_code(str): 验证码(6位数字)
|
|
42
49
|
return:
|
|
43
50
|
flag(bool): 是否发送成功
|
|
44
51
|
"""
|
|
@@ -64,6 +71,13 @@ class SMSUtils:
|
|
|
64
71
|
|
|
65
72
|
class SMSUtilsAsync:
|
|
66
73
|
def __init__(self, access_key_id, access_key_secret):
|
|
74
|
+
"""
|
|
75
|
+
description:
|
|
76
|
+
初始化异步短信服务工具类
|
|
77
|
+
parameters:
|
|
78
|
+
access_key_id(str): 阿里云访问密钥ID
|
|
79
|
+
access_key_secret(str): 阿里云访问密钥Secret
|
|
80
|
+
"""
|
|
67
81
|
self.sms_cilent = Dysmsapi20170525Client(
|
|
68
82
|
open_api_models.Config(
|
|
69
83
|
type="access_key",
|
|
@@ -15,6 +15,17 @@ class STSUtils:
|
|
|
15
15
|
def __init__(
|
|
16
16
|
self, access_key_id, access_key_secret, role_arn, region_id, bucket_name, redis_utils
|
|
17
17
|
):
|
|
18
|
+
"""
|
|
19
|
+
description:
|
|
20
|
+
初始化STS(安全令牌服务)工具类
|
|
21
|
+
parameters:
|
|
22
|
+
access_key_id(str): 阿里云访问密钥ID
|
|
23
|
+
access_key_secret(str): 阿里云访问密钥Secret
|
|
24
|
+
role_arn(str): 角色ARN
|
|
25
|
+
region_id(str): 阿里云区域ID
|
|
26
|
+
bucket_name(str): OSS存储桶名称
|
|
27
|
+
redis_utils(RedisUtils): Redis工具类实例,用于缓存STS令牌
|
|
28
|
+
"""
|
|
18
29
|
assert isinstance(redis_utils, RedisUtils), "redis_utils must be a RedisUtils instance"
|
|
19
30
|
self.access_key_id = access_key_id
|
|
20
31
|
self.access_key_secret = access_key_secret
|
|
@@ -19,6 +19,17 @@ class MysqlUtils:
|
|
|
19
19
|
port,
|
|
20
20
|
max_retries=3,
|
|
21
21
|
):
|
|
22
|
+
"""
|
|
23
|
+
description:
|
|
24
|
+
初始化MySQL工具类
|
|
25
|
+
parameters:
|
|
26
|
+
host(str): 数据库主机地址
|
|
27
|
+
database(str): 数据库名称
|
|
28
|
+
user(str): 数据库用户名
|
|
29
|
+
password(str): 数据库密码
|
|
30
|
+
port(int): 数据库端口
|
|
31
|
+
max_retries(int): 最大重试次数,默认为3
|
|
32
|
+
"""
|
|
22
33
|
self.host = host
|
|
23
34
|
self.database = database
|
|
24
35
|
self.user = user
|
|
@@ -29,7 +40,10 @@ class MysqlUtils:
|
|
|
29
40
|
self._connect()
|
|
30
41
|
|
|
31
42
|
def _connect(self):
|
|
32
|
-
"""
|
|
43
|
+
"""
|
|
44
|
+
description:
|
|
45
|
+
建立数据库连接,支持重试机制
|
|
46
|
+
"""
|
|
33
47
|
for attempt in range(self.max_retries):
|
|
34
48
|
try:
|
|
35
49
|
self.mysql = pymysql.connect(
|
|
@@ -55,10 +69,19 @@ class MysqlUtils:
|
|
|
55
69
|
raise
|
|
56
70
|
|
|
57
71
|
def get_conn(self):
|
|
72
|
+
"""
|
|
73
|
+
description:
|
|
74
|
+
获取MySQL连接对象
|
|
75
|
+
return:
|
|
76
|
+
mysql_conn(pymysql.Connection): MySQL连接对象
|
|
77
|
+
"""
|
|
58
78
|
return self.mysql
|
|
59
79
|
|
|
60
80
|
def _ensure_connection(self):
|
|
61
|
-
"""
|
|
81
|
+
"""
|
|
82
|
+
description:
|
|
83
|
+
确保连接有效,如果断开则重新连接
|
|
84
|
+
"""
|
|
62
85
|
try:
|
|
63
86
|
self.mysql.ping(reconnect=True)
|
|
64
87
|
except Exception:
|
|
@@ -77,12 +100,13 @@ class MysqlUtils:
|
|
|
77
100
|
|
|
78
101
|
def create_table(self, table_name, columns):
|
|
79
102
|
"""
|
|
80
|
-
|
|
103
|
+
description:
|
|
104
|
+
创建数据表
|
|
81
105
|
parameters:
|
|
82
106
|
table_name(str): 表名
|
|
83
|
-
columns(list(tuple)):
|
|
84
|
-
|
|
85
|
-
flag(bool):
|
|
107
|
+
columns(list(tuple)): 列名和类型的元组列表
|
|
108
|
+
return:
|
|
109
|
+
flag(bool): 是否创建成功
|
|
86
110
|
"""
|
|
87
111
|
sql = f"""
|
|
88
112
|
CREATE TABLE {table_name} (
|
|
@@ -253,12 +277,28 @@ class MysqlUtils:
|
|
|
253
277
|
cursor.close()
|
|
254
278
|
|
|
255
279
|
def clear_table(self, table_name):
|
|
280
|
+
"""
|
|
281
|
+
description:
|
|
282
|
+
清空数据表
|
|
283
|
+
parameters:
|
|
284
|
+
table_name(str): 表名
|
|
285
|
+
return:
|
|
286
|
+
flag(bool): 是否清空成功
|
|
287
|
+
"""
|
|
256
288
|
sql = f"""
|
|
257
289
|
TRUNCATE TABLE {table_name};
|
|
258
290
|
"""
|
|
259
291
|
return self.execute_sql(sql)
|
|
260
292
|
|
|
261
293
|
def delete_table(self, table_name):
|
|
294
|
+
"""
|
|
295
|
+
description:
|
|
296
|
+
删除数据表
|
|
297
|
+
parameters:
|
|
298
|
+
table_name(str): 表名
|
|
299
|
+
return:
|
|
300
|
+
flag(bool): 是否删除成功
|
|
301
|
+
"""
|
|
262
302
|
sql = f"""
|
|
263
303
|
DROP TABLE {table_name};
|
|
264
304
|
"""
|
|
@@ -275,6 +315,17 @@ class MysqlUtilsAsync:
|
|
|
275
315
|
port,
|
|
276
316
|
max_retries=3,
|
|
277
317
|
):
|
|
318
|
+
"""
|
|
319
|
+
description:
|
|
320
|
+
初始化异步MySQL工具类
|
|
321
|
+
parameters:
|
|
322
|
+
host(str): 数据库主机地址
|
|
323
|
+
database(str): 数据库名称
|
|
324
|
+
user(str): 数据库用户名
|
|
325
|
+
password(str): 数据库密码
|
|
326
|
+
port(int): 数据库端口
|
|
327
|
+
max_retries(int): 最大重试次数,默认为3
|
|
328
|
+
"""
|
|
278
329
|
self.host = host
|
|
279
330
|
self.database = database
|
|
280
331
|
self.user = user
|
|
@@ -284,13 +335,21 @@ class MysqlUtilsAsync:
|
|
|
284
335
|
self.async_mysql = None
|
|
285
336
|
|
|
286
337
|
async def get_async_conn(self):
|
|
287
|
-
"""
|
|
338
|
+
"""
|
|
339
|
+
description:
|
|
340
|
+
获取异步MySQL连接对象
|
|
341
|
+
return:
|
|
342
|
+
async_mysql_conn(aiomysql.Connection): 异步MySQL连接对象
|
|
343
|
+
"""
|
|
288
344
|
if self.async_mysql is None:
|
|
289
345
|
await self._async_connect()
|
|
290
346
|
return self.async_mysql
|
|
291
347
|
|
|
292
348
|
async def _async_connect(self):
|
|
293
|
-
"""
|
|
349
|
+
"""
|
|
350
|
+
description:
|
|
351
|
+
建立异步数据库连接,支持重试机制
|
|
352
|
+
"""
|
|
294
353
|
for attempt in range(self.max_retries):
|
|
295
354
|
try:
|
|
296
355
|
self.async_mysql = await aiomysql.connect(
|
|
@@ -316,7 +375,10 @@ class MysqlUtilsAsync:
|
|
|
316
375
|
raise
|
|
317
376
|
|
|
318
377
|
async def _async_ensure_connection(self):
|
|
319
|
-
"""
|
|
378
|
+
"""
|
|
379
|
+
description:
|
|
380
|
+
确保异步连接有效,如果断开则重新连接
|
|
381
|
+
"""
|
|
320
382
|
try:
|
|
321
383
|
if self.async_mysql is None:
|
|
322
384
|
await self._async_connect()
|
|
@@ -341,12 +403,13 @@ class MysqlUtilsAsync:
|
|
|
341
403
|
|
|
342
404
|
async def create_table(self, table_name, columns):
|
|
343
405
|
"""
|
|
344
|
-
|
|
406
|
+
description:
|
|
407
|
+
异步创建数据表
|
|
345
408
|
parameters:
|
|
346
409
|
table_name(str): 表名
|
|
347
|
-
columns(list(tuple)):
|
|
348
|
-
|
|
349
|
-
flag(bool):
|
|
410
|
+
columns(list(tuple)): 列名和类型的元组列表
|
|
411
|
+
return:
|
|
412
|
+
flag(bool): 是否创建成功
|
|
350
413
|
"""
|
|
351
414
|
sql = f"""
|
|
352
415
|
CREATE TABLE {table_name} (
|
|
@@ -526,19 +589,38 @@ class MysqlUtilsAsync:
|
|
|
526
589
|
await cursor.close()
|
|
527
590
|
|
|
528
591
|
async def clear_table(self, table_name):
|
|
592
|
+
"""
|
|
593
|
+
description:
|
|
594
|
+
异步清空数据表
|
|
595
|
+
parameters:
|
|
596
|
+
table_name(str): 表名
|
|
597
|
+
return:
|
|
598
|
+
flag(bool): 是否清空成功
|
|
599
|
+
"""
|
|
529
600
|
sql = f"""
|
|
530
601
|
TRUNCATE TABLE {table_name};
|
|
531
602
|
"""
|
|
532
603
|
return await self.execute_sql(sql)
|
|
533
604
|
|
|
534
605
|
async def delete_table(self, table_name):
|
|
606
|
+
"""
|
|
607
|
+
description:
|
|
608
|
+
异步删除数据表
|
|
609
|
+
parameters:
|
|
610
|
+
table_name(str): 表名
|
|
611
|
+
return:
|
|
612
|
+
flag(bool): 是否删除成功
|
|
613
|
+
"""
|
|
535
614
|
sql = f"""
|
|
536
615
|
DROP TABLE {table_name};
|
|
537
616
|
"""
|
|
538
617
|
return await self.execute_sql(sql)
|
|
539
618
|
|
|
540
619
|
async def close(self):
|
|
541
|
-
"""
|
|
620
|
+
"""
|
|
621
|
+
description:
|
|
622
|
+
关闭异步MySQL连接
|
|
623
|
+
"""
|
|
542
624
|
if self.async_mysql:
|
|
543
625
|
self.async_mysql.close()
|
|
544
626
|
await self.async_mysql.wait_closed()
|
|
@@ -9,6 +9,15 @@ feishu_alert = Feishu("devtoolkit服务报警")
|
|
|
9
9
|
|
|
10
10
|
class RedisUtils:
|
|
11
11
|
def __init__(self, host, port, password, db):
|
|
12
|
+
"""
|
|
13
|
+
description:
|
|
14
|
+
初始化Redis工具类
|
|
15
|
+
parameters:
|
|
16
|
+
host(str): Redis主机地址
|
|
17
|
+
port(int): Redis端口
|
|
18
|
+
password(str): Redis密码
|
|
19
|
+
db(int): Redis数据库编号
|
|
20
|
+
"""
|
|
12
21
|
self.redis_client = redis.Redis(
|
|
13
22
|
host=host,
|
|
14
23
|
port=port,
|
|
@@ -17,6 +26,12 @@ class RedisUtils:
|
|
|
17
26
|
)
|
|
18
27
|
|
|
19
28
|
def get_redis_client(self):
|
|
29
|
+
"""
|
|
30
|
+
description:
|
|
31
|
+
获取Redis客户端对象
|
|
32
|
+
return:
|
|
33
|
+
redis_client(redis.Redis): Redis客户端对象
|
|
34
|
+
"""
|
|
20
35
|
return self.redis_client
|
|
21
36
|
|
|
22
37
|
def set(self, key, value, expire_seconds=None):
|
|
@@ -187,6 +202,10 @@ class RedisUtils:
|
|
|
187
202
|
return []
|
|
188
203
|
|
|
189
204
|
def __del__(self):
|
|
205
|
+
"""
|
|
206
|
+
description:
|
|
207
|
+
析构函数,关闭Redis连接
|
|
208
|
+
"""
|
|
190
209
|
self.redis_client.close()
|
|
191
210
|
|
|
192
211
|
|
|
@@ -197,6 +216,12 @@ class RedisUtilsAsync:
|
|
|
197
216
|
)
|
|
198
217
|
|
|
199
218
|
async def get_async_redis_client(self):
|
|
219
|
+
"""
|
|
220
|
+
description:
|
|
221
|
+
获取异步Redis客户端对象
|
|
222
|
+
return:
|
|
223
|
+
async_redis_client(aioredis.Redis): 异步Redis客户端对象
|
|
224
|
+
"""
|
|
200
225
|
return self.async_redis_client
|
|
201
226
|
|
|
202
227
|
async def set(self, key, value, expire_seconds=None):
|
|
@@ -368,6 +393,9 @@ class RedisUtilsAsync:
|
|
|
368
393
|
return []
|
|
369
394
|
|
|
370
395
|
async def close(self):
|
|
371
|
-
"""
|
|
396
|
+
"""
|
|
397
|
+
description:
|
|
398
|
+
关闭异步Redis连接
|
|
399
|
+
"""
|
|
372
400
|
if self.async_redis_client:
|
|
373
401
|
await self.async_redis_client.close()
|