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