first commit
This commit is contained in:
68
app/main.py
Normal file
68
app/main.py
Normal file
@@ -0,0 +1,68 @@
|
||||
# -*- coding: UTF-8 -*-
|
||||
'''
|
||||
@Project :domainScanDemo
|
||||
@File :main.py
|
||||
@IDE :PyCharm
|
||||
@Author :梦伴
|
||||
@Date :2026/4/9 0:09
|
||||
@explain : 系统主入口
|
||||
'''
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
||||
# 添加项目根目录到 sys.path
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
from loguru import logger
|
||||
from PySide6.QtWidgets import QApplication
|
||||
from app.ui.main_window import MainWindow
|
||||
from app.utils.database import Database
|
||||
from app.config import config
|
||||
|
||||
# 配置日志
|
||||
logger.add(
|
||||
os.path.join(config.LOG_DIR, config.LOG_FILE),
|
||||
level=config.LOG_LEVEL,
|
||||
rotation="10 MB",
|
||||
compression="zip"
|
||||
)
|
||||
|
||||
|
||||
def main():
|
||||
"""
|
||||
主函数
|
||||
"""
|
||||
try:
|
||||
# 初始化数据库连接
|
||||
db = Database(
|
||||
host=config.DB_HOST,
|
||||
port=config.DB_PORT,
|
||||
database=config.DB_DATABASE,
|
||||
user=config.DB_USER,
|
||||
password=config.DB_PASSWORD
|
||||
)
|
||||
|
||||
# 测试数据库连接
|
||||
db.execute("SELECT 1")
|
||||
logger.info("数据库连接成功")
|
||||
|
||||
# 初始化应用程序
|
||||
app = QApplication(sys.argv)
|
||||
window = MainWindow()
|
||||
window.show()
|
||||
|
||||
# 运行应用程序
|
||||
sys.exit(app.exec())
|
||||
except Exception as e:
|
||||
logger.error(f"启动应用程序失败: {e}")
|
||||
sys.exit(1)
|
||||
finally:
|
||||
# 关闭数据库连接
|
||||
if 'db' in locals():
|
||||
db.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user