From d37c400c08184c04dce61876fd4836992049249a Mon Sep 17 00:00:00 2001 From: Bail <2915289604@qq.com> Date: Sun, 1 Jan 2023 12:16:31 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E6=97=B6=E9=9C=80=E8=A6=81=E5=85=B3=E9=97=AD=E6=89=80=E6=9C=89?= =?UTF-8?q?python=E5=BA=94=E7=94=A8=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 3 ++- mainwindow.py | 7 ++++--- uengine-apk-builder | 3 ++- uengine-app-install | 3 ++- uengine-app-setting.py | 3 ++- uengine-app-uninstall | 3 ++- uengine-clean | 3 ++- uengine-keyboard | 3 ++- uengine-runner-about | 3 ++- uengine-runner-update-bug | 3 ++- uengine-useadb | 3 ++- uengine-window-size-setting.py | 3 ++- updatekiller.py | 33 +++++++++++++++++++++++++++++++++ 13 files changed, 59 insertions(+), 14 deletions(-) create mode 100755 updatekiller.py diff --git a/Makefile b/Makefile index 07d90d0..16c1596 100755 --- a/Makefile +++ b/Makefile @@ -30,7 +30,8 @@ build: 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 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 python3 RemovePycacheFile.py cp -rv new-deb-build /tmp/uengine-runner-builder diff --git a/mainwindow.py b/mainwindow.py index eb93586..a151c46 100755 --- a/mainwindow.py +++ b/mainwindow.py @@ -26,6 +26,7 @@ import traceback import threading import webbrowser import subprocess +import updatekiller map = True import matplotlib import matplotlib.figure @@ -1099,7 +1100,7 @@ class UpdateWindow(): updateWidgetLayout = QtWidgets.QGridLayout() versionLabel = QtWidgets.QLabel(f"当前版本:{version}\n最新版本:未知\n更新内容:") updateText = QtWidgets.QTextBrowser() - ok = QtWidgets.QPushButton("更新(更新过程中会关闭所有Python应用,包括这个应用)") + ok = QtWidgets.QPushButton("更新(更新过程中会关闭这个应用的所有进程)") ok.clicked.connect(UpdateWindow.Update) cancel = QtWidgets.QPushButton("取消") cancel.clicked.connect(UpdateWindow.update.close) @@ -1134,8 +1135,8 @@ class UpdateWindow(): write_txt("/tmp/uengine-runner/update.sh", f"""#!/bin/bash echo 删除多余的安装包 rm -rfv /tmp/uengine-runner/update/* -echo 关闭“UEngine 运行器”以及其它“Python 应用” -killall python3 +echo 关闭“UEngine 运行器” +python3 /opt/apps/com.gitee.uengine.runner.spark/files/updatekiller.py echo 下载安装包 wget -P /tmp/uengine-runner/update {UpdateWindow.data["Url"][0]} echo 安装安装包 diff --git a/uengine-apk-builder b/uengine-apk-builder index ee1b48e..ad6389f 100755 --- a/uengine-apk-builder +++ b/uengine-apk-builder @@ -18,6 +18,7 @@ import random import zipfile import traceback import subprocess +import updatekiller import PyQt5.QtGui as QtGui import PyQt5.QtCore as QtCore import PyQt5.QtWidgets as QtWidgets @@ -490,4 +491,4 @@ try: except: print("无参数") window.show() -sys.exit(app.exec_()) \ No newline at end of file +sys.exit(app.exec_()) diff --git a/uengine-app-install b/uengine-app-install index 120467c..5984cb2 100755 --- a/uengine-app-install +++ b/uengine-app-install @@ -1,6 +1,7 @@ #!/usr/bin/env python3 import os import sys +import updatekiller if len(sys.argv) > 1: if sys.argv[1] == "--help": print("帮助:") @@ -8,4 +9,4 @@ if len(sys.argv) > 1: sys.exit(0) sys.exit(os.system("sudo /usr/bin/uengine-session-launch-helper -- uengine install --apk='{}'".format(sys.argv[1]))) print("命令参数错误") -sys.exit(1) \ No newline at end of file +sys.exit(1) diff --git a/uengine-app-setting.py b/uengine-app-setting.py index 2fca036..0993ca1 100755 --- a/uengine-app-setting.py +++ b/uengine-app-setting.py @@ -2,6 +2,7 @@ from modulefinder import packagePathMap import sys import ttkthemes +import updatekiller import tkinter as tk import tkinter.ttk as ttk @@ -31,4 +32,4 @@ def main(): return 0 if __name__ == "__main__": - sys.exit(main()) \ No newline at end of file + sys.exit(main()) diff --git a/uengine-app-uninstall b/uengine-app-uninstall index 452bfc9..6e63022 100755 --- a/uengine-app-uninstall +++ b/uengine-app-uninstall @@ -1,6 +1,7 @@ #!/usr/bin/env python3 import os import sys +import updatekiller if len(sys.argv) > 1: if sys.argv[1] == "--help": print("帮助:") @@ -8,4 +9,4 @@ if len(sys.argv) > 1: sys.exit(0) sys.exit(os.system("sudo /usr/bin/uengine-session-launch-helper -- uengine uninstall --pkg='{}'".format(sys.argv[1]))) print("命令参数错误") -sys.exit(1) \ No newline at end of file +sys.exit(1) diff --git a/uengine-clean b/uengine-clean index 98543e0..8c3a509 100755 --- a/uengine-clean +++ b/uengine-clean @@ -1,6 +1,7 @@ #!/usr/bin/env python3 import os import sys +import updatekiller if len(sys.argv) > 1: if sys.argv[1] == "--help": print("帮助:") @@ -8,4 +9,4 @@ if len(sys.argv) > 1: sys.exit(0) print("参数错误") sys.exit(1) -sys.exit(os.system("sudo rm -rf /data/uengine")) \ No newline at end of file +sys.exit(os.system("sudo rm -rf /data/uengine")) diff --git a/uengine-keyboard b/uengine-keyboard index eaf54a7..9cb4d80 100755 --- a/uengine-keyboard +++ b/uengine-keyboard @@ -14,6 +14,7 @@ import traceback import ttkthemes import pyautogui import threading +import updatekiller import tkinter as tk import tkinter.ttk as ttk import tkinter.messagebox as messagebox @@ -238,4 +239,4 @@ keys.start() threading.Thread(target=ShowTips).start() pyautogui.FAILSAFE = False threading.Thread(target=RestartProgramTimer).start() -window.mainloop() \ No newline at end of file +window.mainloop() diff --git a/uengine-runner-about b/uengine-runner-about index ea82964..70208f7 100755 --- a/uengine-runner-about +++ b/uengine-runner-about @@ -16,6 +16,7 @@ import time import json import ttkthemes import subprocess +import updatekiller import tkinter as tk import tkinter.ttk as ttk @@ -167,4 +168,4 @@ def showhelp(): print(windowflag) helpwindow.mainloop() #helpwindow.protocol("WM_DELETE_WINDOW", on_closing) -showhelp() \ No newline at end of file +showhelp() diff --git a/uengine-runner-update-bug b/uengine-runner-update-bug index 143fa2c..544d66c 100755 --- a/uengine-runner-update-bug +++ b/uengine-runner-update-bug @@ -6,6 +6,7 @@ import base64 import requests import traceback import webbrowser +import updatekiller import urllib.parse as parse import PyQt5.QtGui as QtGui import PyQt5.QtWidgets as QtWidgets @@ -108,4 +109,4 @@ window.setCentralWidget(widget) window.setWindowTitle(f"UEngine 运行器 {version} 问题/建议反馈") window.setWindowIcon(QtGui.QIcon(iconPath)) window.show() -sys.exit(app.exec_()) \ No newline at end of file +sys.exit(app.exec_()) diff --git a/uengine-useadb b/uengine-useadb index 85fe2be..e0eaf6b 100755 --- a/uengine-useadb +++ b/uengine-useadb @@ -6,6 +6,7 @@ import os import sys import traceback +import updatekiller import PyQt5.QtWidgets as QtWidgets ######################## # @@ -69,4 +70,4 @@ try: except: traceback.print_exc() QtWidgets.QMessageBox.information(None, "错误", traceback.format_exc()) - sys.exit(2) \ No newline at end of file + sys.exit(2) diff --git a/uengine-window-size-setting.py b/uengine-window-size-setting.py index 28e8136..4178d1d 100755 --- a/uengine-window-size-setting.py +++ b/uengine-window-size-setting.py @@ -3,6 +3,7 @@ import os import sys import shutil import traceback +import updatekiller def Add(): try: @@ -41,4 +42,4 @@ if __name__ == "__main__": Del() sys.exit(0) print("参数错误!") - sys.exit(1) \ No newline at end of file + sys.exit(1) diff --git a/updatekiller.py b/updatekiller.py new file mode 100755 index 0000000..962aee4 --- /dev/null +++ b/updatekiller.py @@ -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可以在行末输出换行符,而且可以省去类型转换 From 3dfa0f37d142e4fe880e575cb0004f878a04c8f2 Mon Sep 17 00:00:00 2001 From: Bail <2915289604@qq.com> Date: Sun, 1 Jan 2023 12:44:19 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=B8=B4=E6=97=B6?= =?UTF-8?q?=E8=84=9A=E6=9C=AC=E4=BF=AE=E6=94=B9=E4=B8=BA=E5=B8=A6=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E7=9A=84=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mainwindow.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mainwindow.py b/mainwindow.py index a151c46..09dfcb7 100755 --- a/mainwindow.py +++ b/mainwindow.py @@ -1136,7 +1136,7 @@ class UpdateWindow(): echo 删除多余的安装包 rm -rfv /tmp/uengine-runner/update/* echo 关闭“UEngine 运行器” -python3 /opt/apps/com.gitee.uengine.runner.spark/files/updatekiller.py +python3 {programPath}/updatekiller.py echo 下载安装包 wget -P /tmp/uengine-runner/update {UpdateWindow.data["Url"][0]} echo 安装安装包