clean code
This commit is contained in:
parent
0f2077670d
commit
bfb95cc372
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
@ -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]
|
||||
|
|
|
|||
Loading…
Reference in New Issue