mirror of
https://github.com/KenanZhu/AutoLibrary.git
synced 2026-06-17 23:13:03 +08:00
chore(*): 重构项目结构
- 新增 src/boot 目录,用于存放启动时需要初始化的模块 - 新增 src/managers 目录,用于存放项目中的管理模块 - 新增 src/managers/config 目录,用于存放配置管理模块 - 新增 src/managers/log 目录,用于存放日志管理模块 - 新增 src/managers/driver 目录,用于存放浏览器驱动管理模块 - 修改对应文件中 import 导入路径
This commit is contained in:
+1
-1
@@ -15,7 +15,7 @@ from PySide6.QtWidgets import QApplication
|
||||
from gui.ALMainWindow import ALMainWindow
|
||||
from gui.resources import ALResource
|
||||
|
||||
from utils.AppInitializer import initializeApp
|
||||
from boot.AppInitializer import initializeApp
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ import logging
|
||||
import queue
|
||||
import datetime
|
||||
|
||||
from utils.LogManager import getLogger
|
||||
from managers.log.LogManager import getLogger
|
||||
|
||||
|
||||
class MsgBase:
|
||||
|
||||
@@ -11,10 +11,22 @@ import os
|
||||
|
||||
from PySide6.QtCore import QStandardPaths, QDir
|
||||
|
||||
from utils.ConfigManager import instance as configInstance
|
||||
from utils.LogManager import instance as logInstance
|
||||
from managers.log.LogManager import instance as logInstance
|
||||
from managers.config.ConfigManager import instance as configInstance
|
||||
from managers.driver.WebDriverManager import instance as webdriverInstance
|
||||
|
||||
|
||||
def initializeLogManager(
|
||||
) -> bool:
|
||||
|
||||
app_dir = QStandardPaths.writableLocation(QStandardPaths.StandardLocation.AppDataLocation)
|
||||
log_dir = os.path.join(app_dir, "logs")
|
||||
if not QDir(log_dir).exists():
|
||||
if not QDir().mkpath(log_dir):
|
||||
return False
|
||||
logInstance(log_dir)
|
||||
return True
|
||||
|
||||
def initializeConfigManager(
|
||||
) -> bool:
|
||||
|
||||
@@ -37,15 +49,20 @@ def initializeConfigManager(
|
||||
configInstance(new_config_dir)
|
||||
return True
|
||||
|
||||
def initializeLogManager(
|
||||
def initializeWebDriverManager(
|
||||
) -> bool:
|
||||
|
||||
logger = logInstance().getLogger("AppInitializer")
|
||||
|
||||
app_dir = QStandardPaths.writableLocation(QStandardPaths.StandardLocation.AppDataLocation)
|
||||
log_dir = os.path.join(app_dir, "logs")
|
||||
if not QDir(log_dir).exists():
|
||||
if not QDir().mkpath(log_dir):
|
||||
driver_dir = os.path.join(app_dir, "drivers")
|
||||
logger.info("初始化驱动目录 %s", driver_dir)
|
||||
if not QDir(driver_dir).exists():
|
||||
logger.error("创建驱动目录 %s 失败", driver_dir)
|
||||
if not QDir().mkpath(driver_dir):
|
||||
logger.error("创建驱动目录 %s 失败", driver_dir)
|
||||
return False
|
||||
logInstance(log_dir)
|
||||
webdriverInstance(driver_dir)
|
||||
return True
|
||||
|
||||
def initializeApp(
|
||||
@@ -55,4 +72,6 @@ def initializeApp(
|
||||
return False
|
||||
if not initializeConfigManager():
|
||||
return False
|
||||
if not initializeWebDriverManager():
|
||||
return False
|
||||
return True
|
||||
@@ -0,0 +1,6 @@
|
||||
"""
|
||||
Boot module for the AutoLibrary project.
|
||||
|
||||
Here are the classes and modules in this package:
|
||||
- AppInitializer: Application initializer class.
|
||||
"""
|
||||
@@ -20,7 +20,7 @@ from PySide6.QtGui import (
|
||||
QCloseEvent, QAction
|
||||
)
|
||||
|
||||
import utils.ConfigManager as ConfigManager
|
||||
import managers.config.ConfigManager as ConfigManager
|
||||
|
||||
from utils.JSONReader import JSONReader
|
||||
from utils.JSONWriter import JSONWriter
|
||||
|
||||
@@ -19,7 +19,7 @@ from PySide6.QtGui import (
|
||||
QTextCursor, QCloseEvent, QFont, QIcon, QDesktopServices
|
||||
)
|
||||
|
||||
import utils.ConfigManager as ConfigManager
|
||||
import managers.config.ConfigManager as ConfigManager
|
||||
|
||||
from base.MsgBase import MsgBase
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ from PySide6.QtGui import (
|
||||
QCloseEvent
|
||||
)
|
||||
|
||||
import utils.ConfigManager as ConfigManager
|
||||
import managers.config.ConfigManager as ConfigManager
|
||||
import utils.TimerUtils as TimerUtils
|
||||
|
||||
from gui.resources.ui.Ui_ALTimerTaskManageWidget import Ui_ALTimerTaskManageWidget
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
"""
|
||||
GUI module for the AutoLibrary project.
|
||||
|
||||
Here are the classes and modules in this package:
|
||||
- ALMainWindow: Main window class.
|
||||
- ALAboutDialog: About dialog class.
|
||||
- ALConfigWidget: Configuration widget class.
|
||||
- ALSeatFrame: Seat frame class.
|
||||
- ALSeatMapView: Seat map view class.
|
||||
- ALSeatMapTable: Seat map table class.
|
||||
- ALSeatMapSelectDialog: Seat map select dialog class.
|
||||
- ALTimerTaskAddDialog: Timer task add dialog class.
|
||||
- ALTimerTaskHistoryDialog: Timer task history dialog class.
|
||||
- ALTimerTaskManageWidget: Timer task manage widget class.
|
||||
- ALUserTreeWidget: User tree widget class.
|
||||
- ALMainWorkers: Main workers class.
|
||||
- ALVersionInfo: Version info class.
|
||||
"""
|
||||
@@ -0,0 +1,3 @@
|
||||
"""
|
||||
GUI resources module for the AutoLibrary project.
|
||||
"""
|
||||
@@ -0,0 +1,8 @@
|
||||
"""
|
||||
Managers module for the AutoLibrary project.
|
||||
|
||||
Here are the classes and modules in this package:
|
||||
- ConfigManager: Config manager for managing configuration files.
|
||||
- LogManager: Log manager for logging.
|
||||
- WebDriverManager: Web driver manager for managing web drivers.
|
||||
"""
|
||||
@@ -234,11 +234,12 @@ def instance(
|
||||
global _config_manager_instance
|
||||
with _instance_lock:
|
||||
if _config_manager_instance is None:
|
||||
if not config_dir:
|
||||
raise ValueError("ConfigManager 需要配置目录参数")
|
||||
_config_manager_instance = ConfigManager(config_dir)
|
||||
else:
|
||||
if config_dir == "":
|
||||
return _config_manager_instance
|
||||
if getBaseConfigDir() != config_dir:
|
||||
raise ValueError(
|
||||
"ConfigManager 的实例已初始化,不能使用不同的配置目录。")
|
||||
raise ValueError("ConfigManager 的实例已初始化,不能使用不同的配置目录。")
|
||||
return _config_manager_instance
|
||||
@@ -0,0 +1,6 @@
|
||||
"""
|
||||
Config managers module for the AutoLibrary project.
|
||||
|
||||
Here are the classes and modules in this package:
|
||||
- ConfigManager: Config manager for managing configuration files.
|
||||
"""
|
||||
@@ -0,0 +1,8 @@
|
||||
"""
|
||||
Driver managers module for the AutoLibrary project.
|
||||
|
||||
Here are the classes and modules in this package:
|
||||
- WebBrowserDetector: Web browser detector class.
|
||||
- WebDriverDownloader: Web driver downloader class.
|
||||
- WebDriverManager: Web driver manager class.
|
||||
"""
|
||||
@@ -174,11 +174,11 @@ def instance(
|
||||
with _instance_lock:
|
||||
if _log_manager_instance is None:
|
||||
if not log_dir:
|
||||
raise ValueError("LogManager initialization requires log_dir parameter")
|
||||
raise ValueError("LogManager 需要日志目录参数")
|
||||
_log_manager_instance = LogManager(log_dir)
|
||||
else:
|
||||
if log_dir and _log_manager_instance.logDir() != os.path.abspath(log_dir):
|
||||
raise ValueError("LogManager instance already initialized with a different log directory")
|
||||
raise ValueError("LogManager 的实例已初始化,不能使用不同的日志目录")
|
||||
return _log_manager_instance
|
||||
|
||||
|
||||
@@ -187,5 +187,5 @@ def getLogger(
|
||||
) -> logging.Logger:
|
||||
|
||||
if _log_manager_instance is None:
|
||||
raise RuntimeError("LogManager not initialized, please call LogManager.instance(log_dir) first")
|
||||
raise RuntimeError("LogManager 未初始化,请先调用 LogManager.instance(log_dir) 初始化")
|
||||
return _log_manager_instance.getLogger(name)
|
||||
@@ -0,0 +1,6 @@
|
||||
"""
|
||||
Log managers module for the AutoLibrary project.
|
||||
|
||||
Here are the classes and modules in this package:
|
||||
- LogManager: Log manager for logging.
|
||||
"""
|
||||
@@ -2,7 +2,7 @@
|
||||
Utils module for the AutoLibrary project.
|
||||
|
||||
Here are the classes and modules in this package:
|
||||
- ConfigManager: Configuration manager class for the AutoLibrary project.
|
||||
- TimerUtils: Timer utils class for the AutoLibrary project.
|
||||
- JSONReader: JSON reader class for the AutoLibrary project.
|
||||
- JSONWriter: JSON writer class for the AutoLibrary project.
|
||||
"""
|
||||
Reference in New Issue
Block a user