pixelarraylib 1.0.0__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.
- arraylib/__init__.py +36 -0
- arraylib/__main__.py +126 -0
- arraylib/aliyun/__init__.py +0 -0
- arraylib/aliyun/aliyun_email.py +130 -0
- arraylib/aliyun/billing.py +477 -0
- arraylib/aliyun/content_scanner.py +253 -0
- arraylib/aliyun/domain.py +434 -0
- arraylib/aliyun/eci.py +47 -0
- arraylib/aliyun/ecs.py +68 -0
- arraylib/aliyun/fc.py +142 -0
- arraylib/aliyun/oss.py +649 -0
- arraylib/aliyun/sms.py +59 -0
- arraylib/aliyun/sts.py +124 -0
- arraylib/db_utils/mysql.py +544 -0
- arraylib/db_utils/redis.py +373 -0
- arraylib/decorators/__init__.py +13 -0
- arraylib/decorators/decorators.py +194 -0
- arraylib/gitlab/__init__.py +0 -0
- arraylib/gitlab/code_analyzer.py +344 -0
- arraylib/gitlab/pypi_package_manager.py +61 -0
- arraylib/monitor/__init__.py +0 -0
- arraylib/monitor/feishu.py +132 -0
- arraylib/net/request.py +143 -0
- arraylib/scripts/__init__.py +22 -0
- arraylib/scripts/collect_code_to_txt.py +327 -0
- arraylib/scripts/create_test_case_files.py +100 -0
- arraylib/scripts/nginx_proxy_to_ecs.py +119 -0
- arraylib/scripts/remove_empty_lines.py +120 -0
- arraylib/scripts/summary_code_count.py +430 -0
- arraylib/system/__init__.py +0 -0
- arraylib/system/common.py +390 -0
- pixelarraylib-1.0.0.dist-info/METADATA +141 -0
- pixelarraylib-1.0.0.dist-info/RECORD +37 -0
- pixelarraylib-1.0.0.dist-info/WHEEL +5 -0
- pixelarraylib-1.0.0.dist-info/entry_points.txt +2 -0
- pixelarraylib-1.0.0.dist-info/licenses/LICENSE +21 -0
- pixelarraylib-1.0.0.dist-info/top_level.txt +1 -0
arraylib/__init__.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
PixelArray Python开发工具库
|
|
6
|
+
|
|
7
|
+
这个库包含了常用的开发工具和服务集成:
|
|
8
|
+
- aliyun: 阿里云服务集成 (STS, SMS, OSS, FC, Email, ECS, 内容扫描等)
|
|
9
|
+
- db_utils: 数据库工具 (Redis, MySQL)
|
|
10
|
+
- decorators: 装饰器工具
|
|
11
|
+
- gitlab: GitLab工具 (PyPI包管理)
|
|
12
|
+
- monitor: 监控工具 (飞书通知)
|
|
13
|
+
- net: 网络请求工具
|
|
14
|
+
- system: 系统工具
|
|
15
|
+
|
|
16
|
+
使用示例:
|
|
17
|
+
from arraylib.aliyun import oss
|
|
18
|
+
from arraylib.db_utils import mysql
|
|
19
|
+
from arraylib.decorators import decorators
|
|
20
|
+
from arraylib.gitlab import pypi_package_manager
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
__version__ = "1.0.0"
|
|
24
|
+
__author__ = "PixelArray"
|
|
25
|
+
__email__ = "qi.lu@pixelarrayai.com"
|
|
26
|
+
|
|
27
|
+
# 导出主要模块
|
|
28
|
+
__all__ = [
|
|
29
|
+
'aliyun',
|
|
30
|
+
'db_utils',
|
|
31
|
+
'decorators',
|
|
32
|
+
'gitlab',
|
|
33
|
+
'monitor',
|
|
34
|
+
'net',
|
|
35
|
+
'system',
|
|
36
|
+
]
|
arraylib/__main__.py
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
ArrayLib 命令行工具入口点
|
|
4
|
+
支持的命令:
|
|
5
|
+
- arraylib create_test_case_files
|
|
6
|
+
- arraylib summary_code_count [options]
|
|
7
|
+
- arraylib collect_code_to_txt [options]
|
|
8
|
+
- arraylib nginx_proxy_to_ecs [options]
|
|
9
|
+
- arraylib remove_empty_lines <input_file> [output_file]
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
import sys
|
|
13
|
+
import argparse
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def main():
|
|
17
|
+
# 检查是否有子命令
|
|
18
|
+
if len(sys.argv) < 2:
|
|
19
|
+
parser = argparse.ArgumentParser(
|
|
20
|
+
description="ArrayLib 命令行工具",
|
|
21
|
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
22
|
+
epilog="""
|
|
23
|
+
示例用法:
|
|
24
|
+
arraylib create_test_case_files --help # 创建测试用例文件
|
|
25
|
+
arraylib summary_code_count --help # 查看统计工具帮助
|
|
26
|
+
arraylib collect_code_to_txt --help # 查看收集工具帮助
|
|
27
|
+
arraylib nginx_proxy_to_ecs --help # 查看Nginx反向代理到ECS工具帮助
|
|
28
|
+
arraylib remove_empty_lines --help # 查看去除空行工具帮助
|
|
29
|
+
""",
|
|
30
|
+
)
|
|
31
|
+
parser.print_help()
|
|
32
|
+
sys.exit(1)
|
|
33
|
+
|
|
34
|
+
command = sys.argv[1]
|
|
35
|
+
|
|
36
|
+
if command == "create_test_case_files":
|
|
37
|
+
# 导入并执行创建测试用例文件功能
|
|
38
|
+
try:
|
|
39
|
+
from arraylib.scripts.create_test_case_files import main as create_test_main
|
|
40
|
+
|
|
41
|
+
create_test_main()
|
|
42
|
+
except ImportError as e:
|
|
43
|
+
print(f"错误:无法导入 create_test_case_files 模块: {e}")
|
|
44
|
+
sys.exit(1)
|
|
45
|
+
|
|
46
|
+
elif command == "summary_code_count":
|
|
47
|
+
# 导入并执行代码统计功能
|
|
48
|
+
try:
|
|
49
|
+
from arraylib.scripts.summary_code_count import main as summary_main
|
|
50
|
+
|
|
51
|
+
# 修改sys.argv,移除第一个参数(arraylib),让summary_code_count正确处理参数
|
|
52
|
+
original_argv = sys.argv
|
|
53
|
+
sys.argv = [original_argv[0]] + original_argv[2:]
|
|
54
|
+
summary_main()
|
|
55
|
+
sys.argv = original_argv
|
|
56
|
+
except ImportError as e:
|
|
57
|
+
print(f"错误:无法导入 summary_code_count 模块: {e}")
|
|
58
|
+
sys.exit(1)
|
|
59
|
+
|
|
60
|
+
elif command == "collect_code_to_txt":
|
|
61
|
+
# 导入并执行代码收集功能
|
|
62
|
+
try:
|
|
63
|
+
from arraylib.scripts.collect_code_to_txt import main as collect_main
|
|
64
|
+
|
|
65
|
+
# 修改sys.argv,移除第一个参数(arraylib),让collect_code_to_txt正确处理参数
|
|
66
|
+
original_argv = sys.argv
|
|
67
|
+
sys.argv = [original_argv[0]] + original_argv[2:]
|
|
68
|
+
collect_main()
|
|
69
|
+
sys.argv = original_argv
|
|
70
|
+
except ImportError as e:
|
|
71
|
+
print(f"错误:无法导入 collect_code_to_txt 模块: {e}")
|
|
72
|
+
sys.exit(1)
|
|
73
|
+
|
|
74
|
+
elif command == "nginx_proxy_to_ecs":
|
|
75
|
+
# 导入并执行Nginx反向代理到ECS功能
|
|
76
|
+
try:
|
|
77
|
+
from arraylib.scripts.nginx_proxy_to_ecs import main as nginx_proxy_to_ecs
|
|
78
|
+
|
|
79
|
+
# 修改sys.argv,移除第一个参数(arraylib),让nginx_proxy_to_ecs正确处理参数
|
|
80
|
+
original_argv = sys.argv
|
|
81
|
+
sys.argv = [original_argv[0]] + original_argv[2:]
|
|
82
|
+
nginx_proxy_to_ecs()
|
|
83
|
+
sys.argv = original_argv
|
|
84
|
+
except ImportError as e:
|
|
85
|
+
print(f"错误:无法导入 nginx_proxy_to_ecs 模块: {e}")
|
|
86
|
+
sys.exit(1)
|
|
87
|
+
|
|
88
|
+
elif command == "remove_empty_lines":
|
|
89
|
+
# 导入并执行去除空行功能
|
|
90
|
+
try:
|
|
91
|
+
from arraylib.scripts.remove_empty_lines import main as remove_empty_lines_main
|
|
92
|
+
|
|
93
|
+
# 修改sys.argv,移除第一个参数(arraylib),让remove_empty_lines正确处理参数
|
|
94
|
+
original_argv = sys.argv
|
|
95
|
+
sys.argv = [original_argv[0]] + original_argv[2:]
|
|
96
|
+
remove_empty_lines_main()
|
|
97
|
+
sys.argv = original_argv
|
|
98
|
+
except ImportError as e:
|
|
99
|
+
print(f"错误:无法导入 remove_empty_lines 模块: {e}")
|
|
100
|
+
sys.exit(1)
|
|
101
|
+
|
|
102
|
+
elif command in ["-h", "--help"]:
|
|
103
|
+
parser = argparse.ArgumentParser(
|
|
104
|
+
description="ArrayLib 命令行工具",
|
|
105
|
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
106
|
+
epilog="""
|
|
107
|
+
示例用法:
|
|
108
|
+
arraylib create_test_case_files --help # 创建测试用例文件
|
|
109
|
+
arraylib summary_code_count --help # 查看统计工具帮助
|
|
110
|
+
arraylib collect_code_to_txt --help # 查看收集工具帮助
|
|
111
|
+
arraylib nginx_proxy_to_ecs --help # 查看Nginx反向代理到ECS工具帮助
|
|
112
|
+
arraylib remove_empty_lines --help # 查看去除空行工具帮助
|
|
113
|
+
""",
|
|
114
|
+
)
|
|
115
|
+
parser.print_help()
|
|
116
|
+
else:
|
|
117
|
+
print(f"错误:未知命令 '{command}'")
|
|
118
|
+
print(
|
|
119
|
+
"可用命令:create_test_case_files, summary_code_count, collect_code_to_txt, nginx_proxy_to_ecs, remove_empty_lines"
|
|
120
|
+
)
|
|
121
|
+
print("使用 'arraylib --help' 查看帮助")
|
|
122
|
+
sys.exit(1)
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
if __name__ == "__main__":
|
|
126
|
+
main()
|
|
File without changes
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import time
|
|
3
|
+
import random
|
|
4
|
+
import traceback
|
|
5
|
+
from alibabacloud_dm20151123.client import Client as Dm20151123Client
|
|
6
|
+
from alibabacloud_tea_openapi import models as open_api_models
|
|
7
|
+
from alibabacloud_dm20151123 import models as dm_20151123_models
|
|
8
|
+
from alibabacloud_tea_util import models as util_models
|
|
9
|
+
from arraylib.monitor.feishu import Feishu
|
|
10
|
+
|
|
11
|
+
feishu_alert = Feishu("devtoolkit服务报警")
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class AliyunEmailSender:
|
|
15
|
+
def __init__(self, access_key_id, access_key_secret):
|
|
16
|
+
self.client = Dm20151123Client(
|
|
17
|
+
open_api_models.Config(
|
|
18
|
+
access_key_id=access_key_id,
|
|
19
|
+
access_key_secret=access_key_secret,
|
|
20
|
+
endpoint="dm.aliyuncs.com",
|
|
21
|
+
)
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
def generate_verification_code(self, length=6):
|
|
25
|
+
"""
|
|
26
|
+
description:
|
|
27
|
+
生成数字验证码
|
|
28
|
+
parameters:
|
|
29
|
+
length(int): 验证码长度
|
|
30
|
+
return:
|
|
31
|
+
str: 验证码
|
|
32
|
+
"""
|
|
33
|
+
return "".join(str(random.randint(0, 9)) for _ in range(length))
|
|
34
|
+
|
|
35
|
+
def create_verification_email_content(
|
|
36
|
+
self, username, verification_code, email_type, validity=15
|
|
37
|
+
):
|
|
38
|
+
"""
|
|
39
|
+
description:
|
|
40
|
+
创建邮件HTML内容
|
|
41
|
+
parameters:
|
|
42
|
+
username(str): 用户名
|
|
43
|
+
validity(int): 验证码有效期
|
|
44
|
+
return:
|
|
45
|
+
str: 邮件HTML内容
|
|
46
|
+
"""
|
|
47
|
+
email_type_str = "注册" if email_type == "register" else "找回密码"
|
|
48
|
+
return f"""
|
|
49
|
+
<html>
|
|
50
|
+
<head>
|
|
51
|
+
<style>
|
|
52
|
+
body {{ font-family: Arial, sans-serif; line-height: 1.6; }}
|
|
53
|
+
.container {{ max-width: 600px; margin: 0 auto; padding: 20px; border: 1px solid #e1e8f7; border-radius: 10px; }}
|
|
54
|
+
.header {{ background: linear-gradient(to right, #1a2980, #26d0ce); color: white; padding: 15px; text-align: center; border-radius: 8px; }}
|
|
55
|
+
.code {{ font-size: 28px; font-weight: bold; text-align: center; margin: 25px 0; letter-spacing: 5px; color: #e74c3c; }}
|
|
56
|
+
.footer {{ margin-top: 30px; text-align: center; color: #777; font-size: 12px; }}
|
|
57
|
+
</style>
|
|
58
|
+
</head>
|
|
59
|
+
<body>
|
|
60
|
+
<div class="container">
|
|
61
|
+
<div class="header">
|
|
62
|
+
<h2>北京矩阵像素科技有限公司</h2>
|
|
63
|
+
</div>
|
|
64
|
+
|
|
65
|
+
<p>尊敬的 <strong>{username}</strong>:</p>
|
|
66
|
+
<p>您正在进行邮箱{email_type_str}验证,您的验证码为:</p>
|
|
67
|
+
<div class="code">{verification_code}</div>
|
|
68
|
+
<p>该验证码 <strong>{validity}分钟</strong> 内有效,请尽快完成验证。</p>
|
|
69
|
+
<p>如非本人操作,请忽略此邮件。</p>
|
|
70
|
+
|
|
71
|
+
<div class="footer">
|
|
72
|
+
<p>阿里云邮件推送服务 | 安全验证</p>
|
|
73
|
+
<p>© {time.strftime('%Y')} 企业注册系统 版权所有</p>
|
|
74
|
+
</div>
|
|
75
|
+
</div>
|
|
76
|
+
</body>
|
|
77
|
+
</html>
|
|
78
|
+
"""
|
|
79
|
+
|
|
80
|
+
def get_email_subject(self, email_type):
|
|
81
|
+
if email_type == "register":
|
|
82
|
+
return "您的注册验证码"
|
|
83
|
+
elif email_type == "forgot":
|
|
84
|
+
return "您的找回密码验证码"
|
|
85
|
+
else:
|
|
86
|
+
return "您的验证码"
|
|
87
|
+
|
|
88
|
+
def send_verification_email(
|
|
89
|
+
self, to_address, verification_code, email_type, username="用户"
|
|
90
|
+
):
|
|
91
|
+
"""
|
|
92
|
+
description:
|
|
93
|
+
发送验证邮件
|
|
94
|
+
parameters:
|
|
95
|
+
to_address(str): 收件人邮箱地址
|
|
96
|
+
email_type(str): 邮件类型
|
|
97
|
+
username(str): 用户名
|
|
98
|
+
return:
|
|
99
|
+
dict: 发送结果
|
|
100
|
+
"""
|
|
101
|
+
assert email_type in [
|
|
102
|
+
"register",
|
|
103
|
+
"forgot",
|
|
104
|
+
], "邮件类型错误,当前只有register和forgot两种类型"
|
|
105
|
+
try:
|
|
106
|
+
response = self.client.single_send_mail_with_options(
|
|
107
|
+
dm_20151123_models.SingleSendMailRequest(
|
|
108
|
+
account_name="captcha_new@captcha.pixelarrayai.com",
|
|
109
|
+
address_type=1,
|
|
110
|
+
to_address=to_address,
|
|
111
|
+
subject=self.get_email_subject(email_type),
|
|
112
|
+
html_body=self.create_verification_email_content(
|
|
113
|
+
username=username,
|
|
114
|
+
verification_code=verification_code,
|
|
115
|
+
email_type=email_type,
|
|
116
|
+
),
|
|
117
|
+
reply_to_address=False,
|
|
118
|
+
from_alias="系统验证", # 发信人昵称
|
|
119
|
+
),
|
|
120
|
+
util_models.RuntimeOptions(),
|
|
121
|
+
)
|
|
122
|
+
if response.status_code == 200:
|
|
123
|
+
return True
|
|
124
|
+
else:
|
|
125
|
+
feishu_alert.send(f"发送验证邮件失败: {response}")
|
|
126
|
+
return False
|
|
127
|
+
|
|
128
|
+
except Exception as e:
|
|
129
|
+
feishu_alert.send(traceback.format_exc())
|
|
130
|
+
return False
|