优化安装程序
This commit is contained in:
parent
dc0234af14
commit
9b0d21f4ea
|
|
@ -1,2 +1,2 @@
|
||||||
pyinstaller --onefile --add-data "datas/mariadb.zip:datas" --add-data "datas/init.sql:datas" --add-data "datas/jdk.zip:datas" src/install.py
|
pyinstaller --onefile --add-data "datas/mariadb.zip:datas" --add-data "datas/init.sql:datas" --add-data "datas/jdk.zip:datas" --add-data "datas/start.bat:datas" src/install.py
|
||||||
pyinstaller --onefile --add-data "datas/electromagnetic.jar:datas" src/start.py
|
pyinstaller --onefile --add-data "datas/electromagnetic.jar:datas" src/start.py
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
D:/database/start.exe --startWindow
|
||||||
Binary file not shown.
Binary file not shown.
|
|
@ -1,5 +1,6 @@
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import time
|
||||||
import zipfile
|
import zipfile
|
||||||
import subprocess
|
import subprocess
|
||||||
import loguru
|
import loguru
|
||||||
|
|
@ -7,7 +8,7 @@ import elevate
|
||||||
import shutil
|
import shutil
|
||||||
import psutil
|
import psutil
|
||||||
|
|
||||||
path = r'D:\database'
|
root_path = r'D:\database'
|
||||||
service_name = 'ComacMariaDB'
|
service_name = 'ComacMariaDB'
|
||||||
passowrd = '1qaz@WSX'
|
passowrd = '1qaz@WSX'
|
||||||
mariadb_data_path = r'D:\database\mariadb\data'
|
mariadb_data_path = r'D:\database\mariadb\data'
|
||||||
|
|
@ -25,10 +26,10 @@ 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(str(new_path), 'r') as zip_ref:
|
with zipfile.ZipFile(str(new_path), 'r') as zip_ref:
|
||||||
zip_ref.extractall(path) # 将文件解压到指定路径
|
zip_ref.extractall(root_path) # 将文件解压到指定路径
|
||||||
|
|
||||||
def register_service():
|
def register_service():
|
||||||
args1 = path + '/mariadb/bin/mysql_install_db.exe'
|
args1 = root_path + '/mariadb/bin/mysql_install_db.exe'
|
||||||
args2 = '--datadir=' + mariadb_data_path
|
args2 = '--datadir=' + mariadb_data_path
|
||||||
args3 = '--service=' + service_name
|
args3 = '--service=' + service_name
|
||||||
args4 = '--password=' + passowrd
|
args4 = '--password=' + passowrd
|
||||||
|
|
@ -44,7 +45,7 @@ def start_mariadb():
|
||||||
loguru.logger.info(res)
|
loguru.logger.info(res)
|
||||||
|
|
||||||
def init_db():
|
def init_db():
|
||||||
command2 = fr'{path}\mariadb\bin\mysql --no-defaults -u root -p{passowrd} -P {mariadb_port} {init_schema} < {init_sql}'
|
command2 = fr'{root_path}\mariadb\bin\mysql --no-defaults -u root -p{passowrd} -P {mariadb_port} {init_schema} < {init_sql}'
|
||||||
with os.popen(command2) as stream:
|
with os.popen(command2) as stream:
|
||||||
res2 = stream.read()
|
res2 = stream.read()
|
||||||
loguru.logger.info(res2)
|
loguru.logger.info(res2)
|
||||||
|
|
@ -54,7 +55,7 @@ def init_db():
|
||||||
def init_db_user():
|
def init_db_user():
|
||||||
new_path = get_resource_path(os.path.join('datas', 'init.sql'))
|
new_path = get_resource_path(os.path.join('datas', 'init.sql'))
|
||||||
shutil.copy(str(new_path), mariadb_data_path)
|
shutil.copy(str(new_path), mariadb_data_path)
|
||||||
command1 = fr'{path}\mariadb\bin\mysql -u root -p{passowrd} -P {mariadb_port} -e "create database if not exists {init_schema}; use {init_schema};"'
|
command1 = fr'{root_path}\mariadb\bin\mysql -u root -p{passowrd} -P {mariadb_port} -e "create database if not exists {init_schema}; use {init_schema};"'
|
||||||
with os.popen(command1) as stream:
|
with os.popen(command1) as stream:
|
||||||
res = stream.read()
|
res = stream.read()
|
||||||
loguru.logger.info(res)
|
loguru.logger.info(res)
|
||||||
|
|
@ -91,15 +92,19 @@ def get_resource_path(relative_path):
|
||||||
def set_java_env():
|
def set_java_env():
|
||||||
new_path = get_resource_path(os.path.join('datas', 'jdk.zip'))
|
new_path = get_resource_path(os.path.join('datas', 'jdk.zip'))
|
||||||
with zipfile.ZipFile(str(new_path), 'r') as zip_ref:
|
with zipfile.ZipFile(str(new_path), 'r') as zip_ref:
|
||||||
zip_ref.extractall(path) # 将文件解压到指定路径
|
zip_ref.extractall(root_path) # 将文件解压到指定路径
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def set_bat():
|
||||||
|
new_path = get_resource_path(os.path.join('datas', 'start.bat'))
|
||||||
|
shutil.copy(str(new_path), root_path)
|
||||||
|
|
||||||
def start_install():
|
def start_install():
|
||||||
status = check_service()
|
status = check_service()
|
||||||
if status:
|
if status:
|
||||||
return
|
return
|
||||||
loguru.logger.info("开始安装MariaDB")
|
loguru.logger.info("开始安装MariaDB")
|
||||||
ensure_dir(path)
|
ensure_dir(root_path)
|
||||||
loguru.logger.info("开始解压文件")
|
loguru.logger.info("开始解压文件")
|
||||||
unzip_file()
|
unzip_file()
|
||||||
loguru.logger.info("开始注册服务")
|
loguru.logger.info("开始注册服务")
|
||||||
|
|
@ -112,6 +117,10 @@ def start_install():
|
||||||
init_db()
|
init_db()
|
||||||
loguru.logger.info("设置Java运行环境")
|
loguru.logger.info("设置Java运行环境")
|
||||||
set_java_env()
|
set_java_env()
|
||||||
|
loguru.logger.info("生成脚本文件")
|
||||||
|
set_bat()
|
||||||
|
loguru.logger.info("安装完成,10秒后自动退出")
|
||||||
|
time.sleep(10)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
elevate.elevate()
|
elevate.elevate()
|
||||||
|
|
|
||||||
17
src/start.py
17
src/start.py
|
|
@ -8,12 +8,15 @@ from datetime import datetime
|
||||||
import re
|
import re
|
||||||
import webview
|
import webview
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
|
||||||
# 获取当前脚本所在的目录
|
# 获取当前脚本所在的目录
|
||||||
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的路径
|
# 构建JDK和JAR的路径
|
||||||
jar_path = os.path.join("datas", "electromagnetic.jar")
|
jar_path = os.path.join("datas", "electromagnetic.jar")
|
||||||
|
url = f'http://127.0.0.1:{port}/index'
|
||||||
|
|
||||||
def ensure_dir(directory):
|
def ensure_dir(directory):
|
||||||
if not os.path.exists(directory):
|
if not os.path.exists(directory):
|
||||||
|
|
@ -111,12 +114,24 @@ def kill_process_by_port(run_port):
|
||||||
def open_web():
|
def open_web():
|
||||||
webview.settings['ALLOW_DOWNLOADS'] = True
|
webview.settings['ALLOW_DOWNLOADS'] = True
|
||||||
webview.settings['OPEN_DEVTOOLS_IN_DEBUG'] = False
|
webview.settings['OPEN_DEVTOOLS_IN_DEBUG'] = False
|
||||||
webview.create_window('数据库管理系统', f'http://127.0.0.1:{port}/index')
|
webview.create_window('数据库管理系统', url=url)
|
||||||
webview.start(debug=True)
|
webview.start(debug=True)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
kill_process_by_port(port)
|
kill_process_by_port(port)
|
||||||
delete_old_files(app_log_dir, days=2)
|
delete_old_files(app_log_dir, days=2)
|
||||||
start()
|
start()
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument('--startWindow',
|
||||||
|
type=lambda x: x.lower() == 'true',
|
||||||
|
default=None,
|
||||||
|
help='设置为true则执行open_window(),false或未设置则不执行')
|
||||||
|
args = parser.parse_args()
|
||||||
|
if args.startWindow:
|
||||||
open_web()
|
open_web()
|
||||||
|
else:
|
||||||
|
logger.info(f"请打开浏览器,输入 {url} 访问使用")
|
||||||
|
while True:
|
||||||
|
pass
|
||||||
Loading…
Reference in New Issue