You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
2.3 KiB
63 lines
2.3 KiB
import tkinter as tk
|
|
from tkinter import filedialog
|
|
import platform
|
|
import zipfile
|
|
import subprocess
|
|
import os
|
|
import datetime
|
|
|
|
def select_and_copy_file():
|
|
file_path = filedialog.askopenfilename()
|
|
if file_path:
|
|
update(file_path)
|
|
return
|
|
# update(file_path)
|
|
|
|
#system_name = platform.system()
|
|
|
|
def update(file_path: str):
|
|
usb_mount_path = file_path
|
|
file_name = os.path.basename(file_path)
|
|
if not os.path.exists("/home/mzh/rms_bak"):
|
|
os.makedirs("/home/mzh/rms_bak") # 如果路径不存在,则创建路径
|
|
if not os.path.exists("/home/mzh/rms"):
|
|
os.makedirs("/home/mzh/rms") # 如果路径不存在,则创建路径
|
|
# # 备份文件夹
|
|
backup_folder(f"/home/mzh/{file_name}", "/home/mzh/rms_bak")
|
|
# 复制解压命令
|
|
command = f" " \
|
|
f" sudo cp {usb_mount_path} /home/mzh " \
|
|
f"&& sudo chmod 777 /home/mzh/{file_name}/**" \
|
|
f"&& sudo unzip -o /home/mzh/{file_name} -d /home/mzh " \
|
|
f"&& sudo rm /home/mzh/{file_name} " \
|
|
f"&& cd /home/mzh/rms " \
|
|
f"&& /home/mzh/miniconda3/envs/rms/bin/pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/ " \
|
|
f"&& /home/mzh/miniconda3/envs/rms/bin/pip install -r requirement.txt " \
|
|
f"&& /home/mzh/miniconda3/envs/rms/bin/python main.py"
|
|
try:
|
|
subprocess.run(command, shell=True, check=True)
|
|
return f"Service updated successfully with {file_name}"
|
|
except subprocess.CalledProcessError as e:
|
|
raise
|
|
|
|
def backup_folder(folder_path, backup_path):
|
|
current_time = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
|
|
backup_file_name = f"rms{current_time}.zip"
|
|
with zipfile.ZipFile(os.path.join(backup_path, backup_file_name), 'w', zipfile.ZIP_DEFLATED) as backup_zip:
|
|
for root, _, files in os.walk(folder_path):
|
|
for file in files:
|
|
file_path = os.path.join(root, file)
|
|
archive_path = file_path[len(folder_path) + 1:]
|
|
backup_zip.write(file_path, archive_path)
|
|
#
|
|
# 创建 Tkinter 应用程序窗口
|
|
root = tk.Tk()
|
|
root.title("选择并复制文件到当前目录")
|
|
|
|
# 创建按钮
|
|
select_button = tk.Button(root, text="选择文件并复制", command=select_and_copy_file)
|
|
select_button.pack(padx=20, pady=10)
|
|
|
|
# 启动主循环
|
|
root.mainloop()
|