解决更新时需要关闭所有python应用的问题

This commit is contained in:
Bail 2023-01-01 12:16:31 +08:00
parent 596eaf689f
commit d37c400c08
13 changed files with 59 additions and 14 deletions

View File

@ -30,7 +30,8 @@ build:
cp -rv builer.svg new-deb-build/opt/apps/com.gitee.uengine.runner.spark/files/ cp -rv builer.svg new-deb-build/opt/apps/com.gitee.uengine.runner.spark/files/
cp -rv api new-deb-build/opt/apps/com.gitee.uengine.runner.spark/files/ cp -rv api new-deb-build/opt/apps/com.gitee.uengine.runner.spark/files/
cp -rv Help new-deb-build/opt/apps/com.gitee.uengine.runner.spark/files/ cp -rv Help new-deb-build/opt/apps/com.gitee.uengine.runner.spark/files/
cp -rv Download.py new-deb-build/opt/apps/com.gitee.uengine.runner.spark/files/ cp -rv Download.py new-deb-build/opt/apps/com.gitee.uengine.runner.spark/files/
cp -rv updatekiller.py new-deb-build/opt/apps/com.gitee.uengine.runner.spark/files/
cp -rv pkexec/* new-deb-build/usr/share/polkit-1/actions cp -rv pkexec/* new-deb-build/usr/share/polkit-1/actions
python3 RemovePycacheFile.py python3 RemovePycacheFile.py
cp -rv new-deb-build /tmp/uengine-runner-builder cp -rv new-deb-build /tmp/uengine-runner-builder

View File

@ -26,6 +26,7 @@ import traceback
import threading import threading
import webbrowser import webbrowser
import subprocess import subprocess
import updatekiller
map = True map = True
import matplotlib import matplotlib
import matplotlib.figure import matplotlib.figure
@ -1099,7 +1100,7 @@ class UpdateWindow():
updateWidgetLayout = QtWidgets.QGridLayout() updateWidgetLayout = QtWidgets.QGridLayout()
versionLabel = QtWidgets.QLabel(f"当前版本:{version}\n最新版本:未知\n更新内容:") versionLabel = QtWidgets.QLabel(f"当前版本:{version}\n最新版本:未知\n更新内容:")
updateText = QtWidgets.QTextBrowser() updateText = QtWidgets.QTextBrowser()
ok = QtWidgets.QPushButton("更新(更新过程中会关闭所有Python应用包括这个应用)") ok = QtWidgets.QPushButton("更新(更新过程中会关闭这个应用的所有进程")
ok.clicked.connect(UpdateWindow.Update) ok.clicked.connect(UpdateWindow.Update)
cancel = QtWidgets.QPushButton("取消") cancel = QtWidgets.QPushButton("取消")
cancel.clicked.connect(UpdateWindow.update.close) cancel.clicked.connect(UpdateWindow.update.close)
@ -1134,8 +1135,8 @@ class UpdateWindow():
write_txt("/tmp/uengine-runner/update.sh", f"""#!/bin/bash write_txt("/tmp/uengine-runner/update.sh", f"""#!/bin/bash
echo 删除多余的安装包 echo 删除多余的安装包
rm -rfv /tmp/uengine-runner/update/* rm -rfv /tmp/uengine-runner/update/*
echo 关闭UEngine 运行器以及其它Python 应用 echo 关闭UEngine 运行器
killall python3 python3 /opt/apps/com.gitee.uengine.runner.spark/files/updatekiller.py
echo 下载安装包 echo 下载安装包
wget -P /tmp/uengine-runner/update {UpdateWindow.data["Url"][0]} wget -P /tmp/uengine-runner/update {UpdateWindow.data["Url"][0]}
echo 安装安装包 echo 安装安装包

View File

@ -18,6 +18,7 @@ import random
import zipfile import zipfile
import traceback import traceback
import subprocess import subprocess
import updatekiller
import PyQt5.QtGui as QtGui import PyQt5.QtGui as QtGui
import PyQt5.QtCore as QtCore import PyQt5.QtCore as QtCore
import PyQt5.QtWidgets as QtWidgets import PyQt5.QtWidgets as QtWidgets

View File

@ -1,6 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import os import os
import sys import sys
import updatekiller
if len(sys.argv) > 1: if len(sys.argv) > 1:
if sys.argv[1] == "--help": if sys.argv[1] == "--help":
print("帮助:") print("帮助:")

View File

@ -2,6 +2,7 @@
from modulefinder import packagePathMap from modulefinder import packagePathMap
import sys import sys
import ttkthemes import ttkthemes
import updatekiller
import tkinter as tk import tkinter as tk
import tkinter.ttk as ttk import tkinter.ttk as ttk

View File

@ -1,6 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import os import os
import sys import sys
import updatekiller
if len(sys.argv) > 1: if len(sys.argv) > 1:
if sys.argv[1] == "--help": if sys.argv[1] == "--help":
print("帮助:") print("帮助:")

View File

@ -1,6 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import os import os
import sys import sys
import updatekiller
if len(sys.argv) > 1: if len(sys.argv) > 1:
if sys.argv[1] == "--help": if sys.argv[1] == "--help":
print("帮助:") print("帮助:")

View File

@ -14,6 +14,7 @@ import traceback
import ttkthemes import ttkthemes
import pyautogui import pyautogui
import threading import threading
import updatekiller
import tkinter as tk import tkinter as tk
import tkinter.ttk as ttk import tkinter.ttk as ttk
import tkinter.messagebox as messagebox import tkinter.messagebox as messagebox

View File

@ -16,6 +16,7 @@ import time
import json import json
import ttkthemes import ttkthemes
import subprocess import subprocess
import updatekiller
import tkinter as tk import tkinter as tk
import tkinter.ttk as ttk import tkinter.ttk as ttk

View File

@ -6,6 +6,7 @@ import base64
import requests import requests
import traceback import traceback
import webbrowser import webbrowser
import updatekiller
import urllib.parse as parse import urllib.parse as parse
import PyQt5.QtGui as QtGui import PyQt5.QtGui as QtGui
import PyQt5.QtWidgets as QtWidgets import PyQt5.QtWidgets as QtWidgets

View File

@ -6,6 +6,7 @@
import os import os
import sys import sys
import traceback import traceback
import updatekiller
import PyQt5.QtWidgets as QtWidgets import PyQt5.QtWidgets as QtWidgets
######################## ########################
# #

View File

@ -3,6 +3,7 @@ import os
import sys import sys
import shutil import shutil
import traceback import traceback
import updatekiller
def Add(): def Add():
try: try:

33
updatekiller.py Executable file
View File

@ -0,0 +1,33 @@
#!/usr/bin/env python3
import sys
import os
import atexit
PIDFILE = '/tmp/uengine-runner.pid'
#程序结束时清理pid
@atexit.register
def remove_pid():
with open(PIDFILE) as pidfile:
pidlst = pidfile.readlines()
pidlst.remove(str(PID)+'\n')
with open(PIDFILE,'w') as pidfile:
pidfile.writelines(pidlst)
#更新时结束进程
def main():
for i in open(PIDFILE):
try:
os.kill(int(i),15)
except ProcessLookupError:
pass
os.remove(PIDFILE)
#当该程序被直接执行时执行结束进程操作。如果是导入的形式则只是记录pid
if __name__ == '__main__':
sys.exit(main())
else:
#获取进程pid用于更新时结束进程
PID = os.getpid()
with open(PIDFILE,'a') as pidfile:
print(PID,file=pidfile) #使用print可以在行末输出换行符而且可以省去类型转换