暂时测试通了。
This commit is contained in:
parent
dfde3d3387
commit
4b002a69e1
|
|
@ -1,5 +1,5 @@
|
|||
cd src
|
||||
pyinstaller --onefile --add-data "install/Common.py:install" --add-data "datas/init.sql:datas" .\install\InstallMariaDB.py
|
||||
pyinstaller --onefile --add-data "install/Common.py:install" .\install\InstallMariaDB.py
|
||||
pyinstaller --onefile --add-data "install/Common.py:install" --add-data "datas/nssm.exe:datas" --add-data "datas/electromagnetic.jar:datas" --add-data "datas/init.sql:datas" .\install\InstallOrUpgradeComacDB.py
|
||||
pyinstaller --onefile .\install\Uninstall.py
|
||||
pyinstaller --onefile .\install\SetFile.py
|
||||
Binary file not shown.
|
|
@ -1,6 +1,3 @@
|
|||
import shutil
|
||||
import time
|
||||
|
||||
from Common import *
|
||||
|
||||
|
||||
|
|
@ -14,7 +11,6 @@ class InstallMariaDb:
|
|||
self.passowrd = mariadb_passowrd
|
||||
self.init_schema = mariadb_init_schema
|
||||
self.init_sql = os.path.join(install_path, 'mariadb', 'data', 'init.sql')
|
||||
|
||||
pass
|
||||
|
||||
def start_install_mariadb(self):
|
||||
|
|
@ -26,19 +22,17 @@ class InstallMariaDb:
|
|||
self.__register_service()
|
||||
logger.info("启动数据库")
|
||||
self.__start_mariadb()
|
||||
logger.info("数据库用户初始化")
|
||||
self.__init_db_user()
|
||||
logger.info("数据库初始化")
|
||||
self.__init_db()
|
||||
self.__init_db_user()
|
||||
logger.info("安装完成,10秒自动退出")
|
||||
time.sleep(10)
|
||||
pass
|
||||
|
||||
def __start_mariadb(self):
|
||||
command = 'net start ' + self.service_name
|
||||
with os.popen(command) as stream:
|
||||
res = stream.read()
|
||||
logger.info(res)
|
||||
args1 = 'net'
|
||||
args2 = 'start'
|
||||
res = subprocess.run([args1, args2, self.service_name], text=True, capture_output=True)
|
||||
logger.info(res.stdout)
|
||||
|
||||
def __register_service(self):
|
||||
args1 = self.root_path + '/mariadb/bin/mysql_install_db.exe'
|
||||
|
|
@ -51,23 +45,30 @@ class InstallMariaDb:
|
|||
return res
|
||||
|
||||
def __init_db_user(self):
|
||||
command1 = fr'{self.root_path}\mariadb\bin\mysql -u root -p{self.passowrd} -P {self.mariadb_port} -e "create database if not exists {self.init_schema}; use {self.init_schema};"'
|
||||
command1 = fr'{self.root_path}\mariadb\bin\mysql.exe -u root -p{self.passowrd} -P {self.mariadb_port} -e "create database if not exists {self.init_schema}; use {self.init_schema};"'
|
||||
command2 = fr'{self.root_path}\mariadb\bin\mysql.exe -u root -p****** -P {self.mariadb_port} -e "create database if not exists {self.init_schema}; use {self.init_schema};"'
|
||||
logger.info(command2)
|
||||
with os.popen(command1) as stream:
|
||||
res = stream.read()
|
||||
logger.info(res)
|
||||
|
||||
def __init_db(self):
|
||||
new_path = get_resource_path(os.path.join('datas', 'init.sql'))
|
||||
shutil.copy(str(new_path), self.mariadb_data_path)
|
||||
command2 = fr'{self.root_path}\mariadb\bin\mysql --no-defaults -u root -p{self.passowrd} -P {self.mariadb_port} {self.init_schema} < {self.init_sql}'
|
||||
with os.popen(command2) as stream:
|
||||
res2 = stream.read()
|
||||
logger.info(res2)
|
||||
os.remove(self.init_sql)
|
||||
pass
|
||||
schema_dir = fr'{self.root_path}\mariadb\data\{self.init_schema}'
|
||||
if not os.path.exists(schema_dir):
|
||||
logger.error("数据库初始化失败")
|
||||
raise MyCustomError("数据库安装失败")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
current_dir = os.getcwd()
|
||||
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(
|
||||
sink=os.path.join(log_dir, "InstallMariaDB_{time}.log"), # 文件路径模板
|
||||
rotation="10 MB", # 文件大小达到10MB时轮转
|
||||
retention="1 days", # 保留最近30天的日志
|
||||
compression="zip", # 压缩旧日志节省空间
|
||||
enqueue=True, # 线程安全写入
|
||||
format="{time:YYYY-MM-DD HH:mm:ss} | {level} | {message}" # 自定义格式
|
||||
)
|
||||
InstallMariaDb(current_dir).start_install_mariadb()
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
import time
|
||||
from datetime import datetime
|
||||
|
||||
from Common import *
|
||||
|
|
@ -22,7 +21,6 @@ class InstallOrUpgradeComacDb:
|
|||
# Java和JAR文件路径
|
||||
self.java_path = os.path.join(current_dir, "jdk", "bin", "java.exe")
|
||||
self.sql_path = get_resource_path(os.path.join("datas", "init.sql"))
|
||||
ensure_dir(self.app_log_dir)
|
||||
pass
|
||||
|
||||
def start_comac_db(self):
|
||||
|
|
@ -121,6 +119,17 @@ class InstallOrUpgradeComacDb:
|
|||
|
||||
|
||||
if __name__ == '__main__':
|
||||
current_dir = os.getcwd()
|
||||
|
||||
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(
|
||||
sink=os.path.join(log_dir, "InstallComacDB_{time}.log"), # 文件路径模板
|
||||
rotation="10 MB", # 文件大小达到10MB时轮转
|
||||
retention="1 days", # 保留最近30天的日志
|
||||
compression="zip", # 压缩旧日志节省空间
|
||||
enqueue=True, # 线程安全写入
|
||||
format="{time:YYYY-MM-DD HH:mm:ss} | {level} | {message}" # 自定义格式
|
||||
)
|
||||
InstallOrUpgradeComacDb(current_dir).start_comac_db()
|
||||
pass
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
import subprocess
|
||||
import time
|
||||
import tkinter as tk
|
||||
from tkinter import messagebox
|
||||
import os
|
||||
from loguru import logger
|
||||
|
||||
import shutil
|
||||
import sys
|
||||
|
||||
def delete_service(service_name):
|
||||
stop_command = ["sc", "stop", service_name]
|
||||
|
|
@ -21,18 +21,17 @@ def start_uninstall():
|
|||
service_names = {'ComacDatabase', 'ComacMariaDB'}
|
||||
for service in service_names:
|
||||
delete_service(service)
|
||||
|
||||
if getattr(sys, 'frozen', False): # 检查是否为打包环境
|
||||
prj_dir = os.path.dirname(sys.executable) # exe 所在目录
|
||||
else:
|
||||
prj_dir = os.path.dirname(os.path.abspath(__file__)) # 正常脚本路径
|
||||
logger.info("删除文件路径--->" + prj_dir)
|
||||
shutil.rmtree(prj_dir)
|
||||
logger.info("服务清理完成,请手动删除当前文件夹下的数据,5秒钟后自动退出")
|
||||
time.sleep(5)
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# 创建主窗口(但不显示)
|
||||
root = tk.Tk()
|
||||
root.withdraw() # 隐藏主窗口
|
||||
# 弹出确认对话框
|
||||
response = messagebox.askyesno("确认卸载", "确定卸载?")
|
||||
if response:
|
||||
start_uninstall()
|
||||
else:
|
||||
logger.info("卸载取消")
|
||||
|
|
|
|||
Loading…
Reference in New Issue