🎯 重构目标: - 将 3700+ 行单文件拆分为多个模块 - 清晰的职责分离,便于维护和扩展 📁 模块结构: - config.py: 配置常量和路径 - database.py: 数据库操作 - utils.py: 工具函数(日志、进程、cron等) - routes_cron.py: Cron管理API - routes_system.py: 系统监控API - routes_config.py: 配置管理API - routes_email.py: 邮件通知API - routes_project.py: 项目管理API - templates.py: HTML模板 - app.py: 主入口文件 ✨ 优势: - 易于维护:每个模块职责明确 - 易于扩展:新增功能只需添加对应模块 - 易于测试:模块独立,便于单元测试 - 易于理解:新人能快速上手 📝 更新 README.md,详细说明项目结构和API接口
49 lines
1.2 KiB
Python
49 lines
1.2 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
项目服务管理面板 - 主入口
|
|
模块化重构版本 v3.4.0
|
|
"""
|
|
|
|
from flask import Flask
|
|
from config import APP_NAME, APP_VERSION, APP_PORT
|
|
from database import init_db, close_db
|
|
from utils import log_message
|
|
from routes_cron import register_cron_routes
|
|
from routes_system import register_system_routes
|
|
from routes_config import register_config_routes
|
|
from routes_email import register_email_routes
|
|
from routes_project import register_project_routes
|
|
from templates import get_html_template
|
|
|
|
|
|
# 创建 Flask 应用
|
|
app = Flask(__name__)
|
|
|
|
|
|
def init_app():
|
|
"""初始化应用"""
|
|
# 注册数据库钩子
|
|
app.teardown_appcontext(close_db)
|
|
|
|
# 注册路由
|
|
register_cron_routes(app)
|
|
register_system_routes(app)
|
|
register_config_routes(app)
|
|
register_email_routes(app)
|
|
register_project_routes(app)
|
|
|
|
# 主页路由
|
|
@app.route('/')
|
|
def index():
|
|
return get_html_template()
|
|
|
|
# 初始化数据库
|
|
init_db()
|
|
|
|
log_message(f"{APP_NAME} {APP_VERSION} 初始化完成")
|
|
|
|
|
|
if __name__ == '__main__':
|
|
init_app()
|
|
log_message(f"启动 {APP_NAME},端口: {APP_PORT}")
|
|
app.run(host='0.0.0.0', port=APP_PORT, debug=False) |