暂时测试通了。
This commit is contained in:
parent
dfde3d3387
commit
4b002a69e1
|
|
@ -1,5 +1,5 @@
|
||||||
cd src
|
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 --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\Uninstall.py
|
||||||
pyinstaller --onefile .\install\SetFile.py
|
pyinstaller --onefile .\install\SetFile.py
|
||||||
Binary file not shown.
|
|
@ -1,6 +1,3 @@
|
||||||
import shutil
|
|
||||||
import time
|
|
||||||
|
|
||||||
from Common import *
|
from Common import *
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -14,7 +11,6 @@ class InstallMariaDb:
|
||||||
self.passowrd = mariadb_passowrd
|
self.passowrd = mariadb_passowrd
|
||||||
self.init_schema = mariadb_init_schema
|
self.init_schema = mariadb_init_schema
|
||||||
self.init_sql = os.path.join(install_path, 'mariadb', 'data', 'init.sql')
|
self.init_sql = os.path.join(install_path, 'mariadb', 'data', 'init.sql')
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def start_install_mariadb(self):
|
def start_install_mariadb(self):
|
||||||
|
|
@ -26,19 +22,17 @@ class InstallMariaDb:
|
||||||
self.__register_service()
|
self.__register_service()
|
||||||
logger.info("启动数据库")
|
logger.info("启动数据库")
|
||||||
self.__start_mariadb()
|
self.__start_mariadb()
|
||||||
logger.info("数据库用户初始化")
|
|
||||||
self.__init_db_user()
|
|
||||||
logger.info("数据库初始化")
|
logger.info("数据库初始化")
|
||||||
self.__init_db()
|
self.__init_db_user()
|
||||||
logger.info("安装完成,10秒自动退出")
|
logger.info("安装完成,10秒自动退出")
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def __start_mariadb(self):
|
def __start_mariadb(self):
|
||||||
command = 'net start ' + self.service_name
|
args1 = 'net'
|
||||||
with os.popen(command) as stream:
|
args2 = 'start'
|
||||||
res = stream.read()
|
res = subprocess.run([args1, args2, self.service_name], text=True, capture_output=True)
|
||||||
logger.info(res)
|
logger.info(res.stdout)
|
||||||
|
|
||||||
def __register_service(self):
|
def __register_service(self):
|
||||||
args1 = self.root_path + '/mariadb/bin/mysql_install_db.exe'
|
args1 = self.root_path + '/mariadb/bin/mysql_install_db.exe'
|
||||||
|
|
@ -51,23 +45,30 @@ class InstallMariaDb:
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def __init_db_user(self):
|
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:
|
with os.popen(command1) as stream:
|
||||||
res = stream.read()
|
res = stream.read()
|
||||||
logger.info(res)
|
logger.info(res)
|
||||||
|
|
||||||
def __init_db(self):
|
schema_dir = fr'{self.root_path}\mariadb\data\{self.init_schema}'
|
||||||
new_path = get_resource_path(os.path.join('datas', 'init.sql'))
|
if not os.path.exists(schema_dir):
|
||||||
shutil.copy(str(new_path), self.mariadb_data_path)
|
logger.error("数据库初始化失败")
|
||||||
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}'
|
raise MyCustomError("数据库安装失败")
|
||||||
with os.popen(command2) as stream:
|
|
||||||
res2 = stream.read()
|
|
||||||
logger.info(res2)
|
|
||||||
os.remove(self.init_sql)
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
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()
|
InstallMariaDb(current_dir).start_install_mariadb()
|
||||||
pass
|
pass
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
import time
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from Common import *
|
from Common import *
|
||||||
|
|
@ -22,7 +21,6 @@ class InstallOrUpgradeComacDb:
|
||||||
# Java和JAR文件路径
|
# Java和JAR文件路径
|
||||||
self.java_path = os.path.join(current_dir, "jdk", "bin", "java.exe")
|
self.java_path = os.path.join(current_dir, "jdk", "bin", "java.exe")
|
||||||
self.sql_path = get_resource_path(os.path.join("datas", "init.sql"))
|
self.sql_path = get_resource_path(os.path.join("datas", "init.sql"))
|
||||||
ensure_dir(self.app_log_dir)
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def start_comac_db(self):
|
def start_comac_db(self):
|
||||||
|
|
@ -121,6 +119,17 @@ class InstallOrUpgradeComacDb:
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
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()
|
InstallOrUpgradeComacDb(current_dir).start_comac_db()
|
||||||
pass
|
pass
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
import subprocess
|
import subprocess
|
||||||
import time
|
import time
|
||||||
import tkinter as tk
|
import os
|
||||||
from tkinter import messagebox
|
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
import shutil
|
||||||
|
import sys
|
||||||
|
|
||||||
def delete_service(service_name):
|
def delete_service(service_name):
|
||||||
stop_command = ["sc", "stop", service_name]
|
stop_command = ["sc", "stop", service_name]
|
||||||
|
|
@ -21,18 +21,17 @@ def start_uninstall():
|
||||||
service_names = {'ComacDatabase', 'ComacMariaDB'}
|
service_names = {'ComacDatabase', 'ComacMariaDB'}
|
||||||
for service in service_names:
|
for service in service_names:
|
||||||
delete_service(service)
|
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秒钟后自动退出")
|
logger.info("服务清理完成,请手动删除当前文件夹下的数据,5秒钟后自动退出")
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# 创建主窗口(但不显示)
|
|
||||||
root = tk.Tk()
|
|
||||||
root.withdraw() # 隐藏主窗口
|
|
||||||
# 弹出确认对话框
|
|
||||||
response = messagebox.askyesno("确认卸载", "确定卸载?")
|
|
||||||
if response:
|
|
||||||
start_uninstall()
|
start_uninstall()
|
||||||
else:
|
|
||||||
logger.info("卸载取消")
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue