优化代码。
This commit is contained in:
parent
b4246948c0
commit
a2aba153c0
|
|
@ -24,7 +24,7 @@ def ensure_dir(directory):
|
|||
|
||||
def unzip_file():
|
||||
new_path = get_resource_path(os.path.join('datas', 'mariadb.zip'))
|
||||
with zipfile.ZipFile(new_path, 'r') as zip_ref:
|
||||
with zipfile.ZipFile(str(new_path), 'r') as zip_ref:
|
||||
zip_ref.extractall(path) # 将文件解压到指定路径
|
||||
|
||||
def register_service():
|
||||
|
|
@ -59,7 +59,7 @@ def init_db_user():
|
|||
res = stream.read()
|
||||
loguru.logger.info(res)
|
||||
|
||||
def check_service(service_name):
|
||||
def check_service():
|
||||
"""检查服务是否存在及运行状态"""
|
||||
try:
|
||||
service = psutil.win_service_get(service_name)
|
||||
|
|
@ -95,7 +95,7 @@ def set_java_env():
|
|||
pass
|
||||
|
||||
def start_install():
|
||||
status = check_service(service_name)
|
||||
status = check_service()
|
||||
if status:
|
||||
return
|
||||
loguru.logger.info("开始安装MariaDB")
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@ import webview
|
|||
new_java_path = 'D:/database/jdk/bin/java.exe'
|
||||
app_log_dir = 'D:/database/logs'
|
||||
port = 12396
|
||||
# 构建JDK和JAR的路径
|
||||
jar_path = os.path.join("datas", "electromagnetic.jar")
|
||||
|
||||
def ensure_dir(directory):
|
||||
if not os.path.exists(directory):
|
||||
|
|
@ -31,9 +33,6 @@ def get_resource_path(relative_path):
|
|||
base_path = os.path.dirname(os.path.abspath("."))
|
||||
return os.path.join(base_path, relative_path)
|
||||
|
||||
# 构建JDK和JAR的路径
|
||||
jar_path = os.path.join("datas", "electromagnetic.jar")
|
||||
|
||||
def delete_old_files(directory, days=2):
|
||||
# 计算时间阈值(当前时间 - days天)
|
||||
threshold_time = time.time() - days * 24 * 60 * 60
|
||||
|
|
@ -63,10 +62,9 @@ def delete_old_files(directory, days=2):
|
|||
except Exception as e:
|
||||
logger.info(f"遍历目录时出错: {str(e)}", file=sys.stderr)
|
||||
|
||||
|
||||
def format_time(timestamp):
|
||||
"""将时间戳格式化为可读字符串"""
|
||||
return datetime.datetime.fromtimestamp(timestamp).strftime('%Y-%m-%d %H:%M:%S')
|
||||
return datetime.fromtimestamp(timestamp).strftime('%Y-%m-%d %H:%M:%S')
|
||||
|
||||
def start():
|
||||
try:
|
||||
|
|
@ -93,7 +91,6 @@ def start():
|
|||
logger.info(f"启动失败: {str(e)}")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def kill_process_by_port(run_port):
|
||||
# 执行netstat命令获取端口占用信息
|
||||
cmd_netstat = ['netstat', '-ano', '-p', 'tcp']
|
||||
|
|
|
|||
Loading…
Reference in New Issue