diff --git a/src/install/Common.py b/src/install/Common.py index 4b3b048..7984150 100644 --- a/src/install/Common.py +++ b/src/install/Common.py @@ -7,9 +7,9 @@ from loguru import logger mariadb_port = 3417 mariadb_passowrd = '1qaz@WSX' -mariadb_user='root' +mariadb_user = 'root' mariadb_init_schema = 'em_data_prod' -comac_db_port=12396 +comac_db_port = 12396 class MyCustomError(Exception): @@ -19,6 +19,7 @@ class MyCustomError(Exception): # 调用基类的构造函数 super().__init__(message) + def ensure_dir(directory): if not os.path.exists(directory): os.makedirs(directory) @@ -87,8 +88,8 @@ def start_service_if_not_running(service_name): logger.info(f"启动服务 {service_name} 失败: {start_result.stderr}") raise MyCustomError(rf"服务 {service_name} 启动失败") -def delete_old_files(directory, days=2): +def delete_old_files(directory, days=2): if not os.path.exists(directory): return @@ -117,4 +118,4 @@ def delete_old_files(directory, days=2): logger.info(f"\n操作完成!共删除 {deleted_count} 个日志文件。") except Exception as e: - logger.info(f"遍历目录时出错: {str(e)}", file=sys.stderr) \ No newline at end of file + logger.info(f"遍历目录时出错: {str(e)}", file=sys.stderr) diff --git a/src/install/InstallMariaDB.py b/src/install/InstallMariaDB.py index 5fe4fd9..0112514 100644 --- a/src/install/InstallMariaDB.py +++ b/src/install/InstallMariaDB.py @@ -59,7 +59,8 @@ class InstallMariaDb: if __name__ == '__main__': - current_dir = os.path.dirname(sys.executable) if getattr(sys, 'frozen', False) else os.path.dirname(os.path.abspath(__file__)) + current_dir = os.path.dirname(sys.executable) if getattr(sys, 'frozen', False) else os.path.dirname( + os.path.abspath(__file__)) log_dir = os.path.join(current_dir, "logs") ensure_dir(log_dir) logger.add( diff --git a/src/install/InstallOrUpgradeComacDB.py b/src/install/InstallOrUpgradeComacDB.py index d6456f7..b982760 100644 --- a/src/install/InstallOrUpgradeComacDB.py +++ b/src/install/InstallOrUpgradeComacDB.py @@ -1,4 +1,5 @@ import shutil + from Common import * current_dir = os.path.dirname(sys.executable) if getattr(sys, 'frozen', False) else os.path.dirname( @@ -8,6 +9,7 @@ app_log_dir = os.path.join(current_dir, "logs") sql_path = get_resource_path(os.path.join("datas", "init.sql")) jar_path = get_resource_path(os.path.join("datas", "electromagnetic.jar")) + def set_sql(): with open(sql_path, 'r', encoding='utf-8') as file: lines = file.readlines() @@ -33,12 +35,14 @@ def set_sql(): logger.info("sql设置成功") pass + def set_jar(): dest_jar_path = os.path.join(current_dir, "electromagnetic.jar") shutil.copy(jar_path, dest_jar_path) logger.info("jar设置成功") pass + def update_service(cmd): command = [manage_service_exe, cmd] result = subprocess.run(command, capture_output=True, text=True) @@ -69,4 +73,4 @@ if __name__ == '__main__': update_service("install") update_service("start") - pass \ No newline at end of file + pass diff --git a/src/install/ManagerService.py b/src/install/ManagerService.py index c4507ef..57cd258 100644 --- a/src/install/ManagerService.py +++ b/src/install/ManagerService.py @@ -4,6 +4,7 @@ import servicemanager import win32event import win32service import win32serviceutil + from Common import * current_dir = os.path.dirname(sys.executable) if getattr(sys, 'frozen', False) else os.path.dirname( @@ -14,6 +15,7 @@ java_exe = os.path.join(current_dir, "jdk", "bin", "java.exe") jar_path = os.path.join(current_dir, "electromagnetic.jar") app_log_dir = os.path.join(current_dir, "logs") + class ComacDBService(win32serviceutil.ServiceFramework): _svc_name_ = service_name # 服务名称 _svc_display_name_ = service_name # 显示名称 @@ -150,6 +152,7 @@ class ComacDBService(win32serviceutil.ServiceFramework): # 报告服务已停止 self.ReportServiceStatus(win32service.SERVICE_STOPPED) logger.info("Service stopped successfully") + pass @@ -176,4 +179,4 @@ if __name__ == '__main__': pythonClassString=win32serviceutil.GetServiceClassString(ComacDBService), serviceName=service_name, startType=win32service.SERVICE_AUTO_START, - ) \ No newline at end of file + ) diff --git a/src/install/SetFile.py b/src/install/SetFile.py index 61a44db..d014f86 100644 --- a/src/install/SetFile.py +++ b/src/install/SetFile.py @@ -4,11 +4,11 @@ import time import pyzipper from loguru import logger - prjRootPath = os.getcwd() + fr"/szsd/data/ele/prj/" srcDataPath = os.getcwd() + rf"/dev.zip" passwd = "Comac" + def unzip_file(): with pyzipper.AESZipFile(srcDataPath) as zip_file: try: @@ -18,6 +18,7 @@ def unzip_file(): return False pass + if __name__ == '__main__': if not os.path.exists(prjRootPath): os.makedirs(prjRootPath) @@ -27,4 +28,4 @@ if __name__ == '__main__': else: logger.info("文件设置成功,3秒钟后自动退出") time.sleep(3) - pass \ No newline at end of file + pass diff --git a/src/install/SetReplaceSqlFile.py b/src/install/SetReplaceSqlFile.py index 27e4f3e..be4749e 100644 --- a/src/install/SetReplaceSqlFile.py +++ b/src/install/SetReplaceSqlFile.py @@ -1,5 +1,6 @@ sql_path = rf"E:\workspace\szsd\database-win-pkg\src\datas\init.sql" + def set_replace(): with open(sql_path, 'r', encoding='utf-8') as file: lines = file.readlines() @@ -18,5 +19,6 @@ def set_replace(): with open(sql_path, 'w', encoding='utf-8') as file: file.writelines(new_lines) + if __name__ == '__main__': - set_replace() \ No newline at end of file + set_replace() diff --git a/src/install/Uninstall.py b/src/install/Uninstall.py index d35d96b..414dea1 100644 --- a/src/install/Uninstall.py +++ b/src/install/Uninstall.py @@ -1,9 +1,11 @@ -import subprocess -import time import os -from loguru import logger import shutil +import subprocess import sys +import time + +from loguru import logger + def delete_service(service_name): stop_command = ["sc", "stop", service_name]