xtn-tools-pro 1.0.0.8.7__py3-none-any.whl → 1.0.0.8.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.
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+
4
+ # 说明:
5
+ # 程序说明xxxxxxxxxxxxxxxxxxx
6
+ # History:
7
+ # Date Author Version Modification
8
+ # --------------------------------------------------------------------------------------------------
9
+ # 2025/3/13 xiatn V00.01.000 新建
10
+ # --------------------------------------------------------------------------------------------------
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+
4
+ # 说明:
5
+ # 程序说明xxxxxxxxxxxxxxxxxxx
6
+ # History:
7
+ # Date Author Version Modification
8
+ # --------------------------------------------------------------------------------------------------
9
+ # 2025/3/13 xiatn V00.01.000 新建
10
+ # --------------------------------------------------------------------------------------------------
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+
4
+ from .app import Flask, JSONEncoder
5
+
6
+
7
+ def register_blueprint(app):
8
+ # 注册蓝图
9
+ from app.api.v1 import create_blueprint_v1
10
+ # url_prefix 前缀
11
+ app.register_blueprint(create_blueprint_v1(), url_prefix="/v1")
12
+
13
+
14
+ def register_mongodb(app):
15
+ return
16
+ from app.models.base import mongo_db_01
17
+ mongo_db_01.init_app(app, uri=app.config['MONGO_URI_01'])
18
+
19
+
20
+ def register_redisdb(app):
21
+ return
22
+ from app.models.base import redis_db_01,redis_db_02
23
+ redis_db.init_app(app)
24
+
25
+
26
+ def create_app():
27
+ app = Flask(__name__)
28
+ app.json_encoder = JSONEncoder
29
+ app.config.from_object('app.config.secure')
30
+ app.config.from_object('app.config.setting')
31
+
32
+ # 注册蓝图
33
+ register_blueprint(app)
34
+ # 注册 mongodb
35
+ register_mongodb(app)
36
+ # 注册 redis
37
+ register_redisdb(app)
38
+ return app
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+
4
+ from flask import Flask as _Flask
5
+ from app.libs.error_code import ServerError500
6
+ from flask.json import JSONEncoder as _JSONEncoder
7
+
8
+
9
+ class JSONEncoder(_JSONEncoder):
10
+ # 改写 flask的JSONEncoder
11
+ def default(self, o):
12
+ if hasattr(o, 'keys') and hasattr(o, '__getitem__'):
13
+ return dict(o)
14
+ raise ServerError500()
15
+
16
+
17
+ class Flask(_Flask):
18
+ # json_encoder = JSONEncoder
19
+ pass
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+
4
+ from app import create_app
5
+ from app.libs.error import APIException
6
+ from werkzeug.exceptions import HTTPException
7
+ from app.libs.error_code import ServerError500, MethodException
8
+
9
+ app = create_app()
10
+
11
+
12
+ @app.errorhandler(Exception)
13
+ def framework_error(e):
14
+ print("发生错误啦 => ", e)
15
+ if isinstance(e, APIException):
16
+ return e
17
+ elif isinstance(e, HTTPException):
18
+ if e.code == 405:
19
+ # 请求的URL不允许使用该方法
20
+ return MethodException()
21
+ else:
22
+ code = e.code
23
+ msg = e.description
24
+ error_code = 4999
25
+ return APIException(msg + "HTTP Exception 4999", code, error_code)
26
+ else:
27
+ print(e)
28
+ return ServerError500()
29
+
30
+
31
+ if __name__ == '__main__':
32
+ app.run(host="0.0.0.0", port=10089, debug=True)
33
+
@@ -0,0 +1,91 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+
4
+ # 说明:
5
+ # 程序说明xxxxxxxxxxxxxxxxxxx
6
+ # History:
7
+ # Date Author Version Modification
8
+ # --------------------------------------------------------------------------------------------------
9
+ # 2025/3/13 xiatn V00.01.000 新建
10
+ # --------------------------------------------------------------------------------------------------
11
+ import os
12
+ import shutil
13
+ import argparse
14
+
15
+
16
+ def replace_placeholders(file_path, project_name):
17
+ """
18
+ 替换文件中的占位符 {{ project_name }} 为实际的项目名称
19
+ """
20
+ with open(file_path, 'r', encoding='utf-8') as file:
21
+ content = file.read()
22
+
23
+ # 替换占位符
24
+ content = content.replace("{{ project_name }}", project_name)
25
+
26
+ with open(file_path, 'w', encoding='utf-8') as file:
27
+ file.write(content)
28
+
29
+
30
+ def create_project(args):
31
+ """
32
+ 创建 flask 常用项目结构
33
+ """
34
+ # 获取当前目录
35
+ project_name = args.obj_name
36
+ current_dir = os.getcwd()
37
+ project_dir = os.path.join(current_dir, project_name)
38
+
39
+ # 创建项目目录
40
+ os.makedirs(project_dir, exist_ok=True)
41
+
42
+ # 复制模板文件到项目目录
43
+ template_dir = os.path.join(os.path.dirname(__file__), 'templates')
44
+ print(template_dir)
45
+ for item in os.listdir(template_dir):
46
+ src = os.path.join(template_dir, item)
47
+ dst = os.path.join(project_dir, item)
48
+
49
+ if os.path.isdir(src):
50
+ shutil.copytree(src, dst) # 判断是否为目录,递归地复制整个目录树
51
+ else:
52
+ shutil.copy2(src, dst)
53
+
54
+ # 如果是文件,替换占位符
55
+ if os.path.isfile(dst):
56
+ replace_placeholders(dst, project_name)
57
+
58
+
59
+ class CustomArgumentParser(argparse.ArgumentParser):
60
+ def error(self, message):
61
+ # 自定义错误消息
62
+ # self.print_help()
63
+ print("错误:缺少必需的参数!")
64
+ print("请使用以下格式运行:xtn_tools_pro startobj <项目名称>")
65
+ self.exit(2) # 退出程序,返回状态码 2
66
+
67
+
68
+ def main():
69
+ """
70
+ 命令行入口
71
+ """
72
+ parser = CustomArgumentParser(description="创建一个常用的flask项目结构") # 创建 ArgumentParser 对象
73
+ subparsers = parser.add_subparsers(title="命令", dest="command")
74
+
75
+ parser_startobj = subparsers.add_parser('startobj', help="项目名称") # 添加位置参数
76
+ parser_startobj.add_argument("obj_name", type=str, help="项目的名称")
77
+ parser_startobj.set_defaults(func=create_project) # 绑定处理函数
78
+
79
+ args = parser.parse_args()
80
+
81
+ # 如果没有提供子命令,显示帮助信息
82
+ if not hasattr(args, "func"):
83
+ parser.print_help()
84
+ return
85
+
86
+ # 调用子命令对应的处理函数
87
+ args.func(args)
88
+
89
+
90
+ if __name__ == "__main__":
91
+ main()
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+
4
+ # 说明:
5
+ # 程序说明xxxxxxxxxxxxxxxxxxx
6
+ # History:
7
+ # Date Author Version Modification
8
+ # --------------------------------------------------------------------------------------------------
9
+ # 2025/3/13 xiatn V00.01.000 新建
10
+ # --------------------------------------------------------------------------------------------------
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+
4
+ from .app import Flask, JSONEncoder
5
+
6
+
7
+ def register_blueprint(app):
8
+ # 注册蓝图
9
+ from app.api.v1 import create_blueprint_v1
10
+ # url_prefix 前缀
11
+ app.register_blueprint(create_blueprint_v1(), url_prefix="/v1")
12
+
13
+
14
+ def register_mongodb(app):
15
+ return
16
+ from app.models.base import mongo_db_01
17
+ mongo_db_01.init_app(app, uri=app.config['MONGO_URI_01'])
18
+
19
+
20
+ def register_redisdb(app):
21
+ return
22
+ from app.models.base import redis_db_01,redis_db_02
23
+ redis_db.init_app(app)
24
+
25
+
26
+ def create_app():
27
+ app = Flask(__name__)
28
+ app.json_encoder = JSONEncoder
29
+ app.config.from_object('app.config.secure')
30
+ app.config.from_object('app.config.setting')
31
+
32
+ # 注册蓝图
33
+ register_blueprint(app)
34
+ # 注册 mongodb
35
+ register_mongodb(app)
36
+ # 注册 redis
37
+ register_redisdb(app)
38
+ return app
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+
4
+ from flask import Flask as _Flask
5
+ from app.libs.error_code import ServerError500
6
+ from flask.json import JSONEncoder as _JSONEncoder
7
+
8
+
9
+ class JSONEncoder(_JSONEncoder):
10
+ # 改写 flask的JSONEncoder
11
+ def default(self, o):
12
+ if hasattr(o, 'keys') and hasattr(o, '__getitem__'):
13
+ return dict(o)
14
+ raise ServerError500()
15
+
16
+
17
+ class Flask(_Flask):
18
+ # json_encoder = JSONEncoder
19
+ pass
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+
4
+ from app import create_app
5
+ from app.libs.error import APIException
6
+ from werkzeug.exceptions import HTTPException
7
+ from app.libs.error_code import ServerError500, MethodException
8
+
9
+ app = create_app()
10
+
11
+
12
+ @app.errorhandler(Exception)
13
+ def framework_error(e):
14
+ print("发生错误啦 => ", e)
15
+ if isinstance(e, APIException):
16
+ return e
17
+ elif isinstance(e, HTTPException):
18
+ if e.code == 405:
19
+ # 请求的URL不允许使用该方法
20
+ return MethodException()
21
+ else:
22
+ code = e.code
23
+ msg = e.description
24
+ error_code = 4999
25
+ return APIException(msg + "HTTP Exception 4999", code, error_code)
26
+ else:
27
+ print(e)
28
+ return ServerError500()
29
+
30
+
31
+ if __name__ == '__main__':
32
+ app.run(host="0.0.0.0", port=10089, debug=True)
33
+
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+
4
+ from app import create_app
5
+ from app.libs.error import APIException
6
+ from werkzeug.exceptions import HTTPException
7
+ from app.libs.error_code import ServerError500, MethodException
8
+
9
+ app = create_app()
10
+
11
+
12
+ @app.errorhandler(Exception)
13
+ def framework_error(e):
14
+ print("发生错误啦 => ", e)
15
+ if isinstance(e, APIException):
16
+ return e
17
+ elif isinstance(e, HTTPException):
18
+ if e.code == 405:
19
+ # 请求的URL不允许使用该方法
20
+ return MethodException()
21
+ else:
22
+ code = e.code
23
+ msg = e.description
24
+ error_code = 4999
25
+ return APIException(msg + "HTTP Exception 4999", code, error_code)
26
+ else:
27
+ print(e)
28
+ return ServerError500()
29
+
30
+
31
+ if __name__ == '__main__':
32
+ app.run(host="0.0.0.0", port=10089, debug=True)
33
+
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: xtn-tools-pro
3
- Version: 1.0.0.8.7
3
+ Version: 1.0.0.8.9
4
4
  Summary: xtn 开发工具
5
5
  Author: xtn
6
6
  Author-email: czw011122@gmail.com
@@ -6,6 +6,17 @@ xtn_tools_pro/db/MongoDB.py,sha256=CljtA5NnutOPL0j2ClrCE4RXW-9N_306D3PAdRANmuk,5
6
6
  xtn_tools_pro/db/MysqlDB.py,sha256=SBJrcjbZdxmtTKPGwl57NthPhs4uX8J3P6o_rK01O4k,13373
7
7
  xtn_tools_pro/db/RedisDB.py,sha256=YSWxYEPE2jp6r1ZKam2LyPgL0S2S9lGDmt36PLSwThg,6470
8
8
  xtn_tools_pro/db/__init__.py,sha256=Zg91UWS02TO0Ba_0AY56s0oabRy93xLNFkpIIL_6mMM,416
9
+ xtn_tools_pro/flask_demo/__init__.py,sha256=2hSMIjKC8-T_9aTJU35DjkwWKa1-ZzMgwfFajs69TWI,418
10
+ xtn_tools_pro/flask_demo/cli.py,sha256=ZJ4AsZmC8Kd5Lf2Vq1fbMTQnAZgBE9mRJKEflrNYcX8,2921
11
+ xtn_tools_pro/flask_demo/ai_server_api/__init__.py,sha256=2hSMIjKC8-T_9aTJU35DjkwWKa1-ZzMgwfFajs69TWI,418
12
+ xtn_tools_pro/flask_demo/ai_server_api/recognize_ai_server_pro.py,sha256=l3VGFGGSVh2PjWodwOGCWfdCQ6ERXf3ZIccURIxUYqk,896
13
+ xtn_tools_pro/flask_demo/ai_server_api/app/__init__.py,sha256=GtoReIEP40zQZUH8yzouon-YWLctoexY_DlW-eIbojw,912
14
+ xtn_tools_pro/flask_demo/ai_server_api/app/app.py,sha256=1X6pp3yD5iygTv6SRJGwEZEFTQZw-oSaO2i45T2oyKM,476
15
+ xtn_tools_pro/flask_demo/templates/__init__.py,sha256=2hSMIjKC8-T_9aTJU35DjkwWKa1-ZzMgwfFajs69TWI,418
16
+ xtn_tools_pro/flask_demo/templates/recognize_ai_server_pro.py,sha256=l3VGFGGSVh2PjWodwOGCWfdCQ6ERXf3ZIccURIxUYqk,896
17
+ xtn_tools_pro/flask_demo/templates/server_run.py,sha256=l3VGFGGSVh2PjWodwOGCWfdCQ6ERXf3ZIccURIxUYqk,896
18
+ xtn_tools_pro/flask_demo/templates/app/__init__.py,sha256=GtoReIEP40zQZUH8yzouon-YWLctoexY_DlW-eIbojw,912
19
+ xtn_tools_pro/flask_demo/templates/app/app.py,sha256=1X6pp3yD5iygTv6SRJGwEZEFTQZw-oSaO2i45T2oyKM,476
9
20
  xtn_tools_pro/proxy/XiaoXiangProxy.py,sha256=45SsMZDc-3Ta4THX38vScjaeRBJSp420AJwBeogC_-I,11049
10
21
  xtn_tools_pro/proxy/__init__.py,sha256=WRwh6s2lruMu5buh0ejo9EK54kWT_VQhCsFGNFAmcyo,418
11
22
  xtn_tools_pro/proxy/proxy.py,sha256=No6E1pFY5yx2F4976pXPrLtq-QEVp79KupzcufjSN58,8703
@@ -22,8 +33,9 @@ xtn_tools_pro/utils/retry.py,sha256=0wjHsR5DBBKpv4naMfxiky8kprrZes4WURIfFQ4H708,
22
33
  xtn_tools_pro/utils/set_data.py,sha256=IthfAclck7AbaxOIKOgJZ2wdcfEmlvC-C63Tywcr4bA,11180
23
34
  xtn_tools_pro/utils/sql.py,sha256=EAKzbkZP7Q09j15Gm6o0_uq0qgQmcCQT6EAawbpp4v0,6263
24
35
  xtn_tools_pro/utils/time_utils.py,sha256=TUtzG61PeVYXhaQd6pBrXAdlz7tBispNIRQRcGhE2No,4859
25
- xtn_tools_pro-1.0.0.8.7.dist-info/LICENSE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
26
- xtn_tools_pro-1.0.0.8.7.dist-info/METADATA,sha256=XY2-Dd1UtiY0A28H-6-mTTgWAkbxSV02i67iem6774E,498
27
- xtn_tools_pro-1.0.0.8.7.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
28
- xtn_tools_pro-1.0.0.8.7.dist-info/top_level.txt,sha256=jyB3FLDEr8zE1U7wHczTgIbvUpALhR-ULF7RVEO7O2U,14
29
- xtn_tools_pro-1.0.0.8.7.dist-info/RECORD,,
36
+ xtn_tools_pro-1.0.0.8.9.dist-info/LICENSE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
37
+ xtn_tools_pro-1.0.0.8.9.dist-info/METADATA,sha256=vALJb-9P5bCUelJ3qEbDgfCGcXUi2QlBbjNjfGzpcnQ,498
38
+ xtn_tools_pro-1.0.0.8.9.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
39
+ xtn_tools_pro-1.0.0.8.9.dist-info/entry_points.txt,sha256=t8CtXWOgw7nRDW3XNlZh8MT_P4l8EzsFnyWi5b3ovrc,68
40
+ xtn_tools_pro-1.0.0.8.9.dist-info/top_level.txt,sha256=jyB3FLDEr8zE1U7wHczTgIbvUpALhR-ULF7RVEO7O2U,14
41
+ xtn_tools_pro-1.0.0.8.9.dist-info/RECORD,,
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ xtn_tools_pro = xtn_tools_pro.flask_demo.cli:main