Python 实现PyQt自动更新功能的正确方法
我几乎完成了一个用于Windows的PyQt应用程序,我希望它能够从远程服务器上托管的ZIP存档自动更新 我已经完成了大部分更新脚本,它正确地下载了新的源代码并将其解压缩。我的最后一步是停止软件,替换旧的源代码并重新启动应用程序 我的问题是以下哪项更合适:Python 实现PyQt自动更新功能的正确方法,python,pyqt,updates,zipfile,Python,Pyqt,Updates,Zipfile,我几乎完成了一个用于Windows的PyQt应用程序,我希望它能够从远程服务器上托管的ZIP存档自动更新 我已经完成了大部分更新脚本,它正确地下载了新的源代码并将其解压缩。我的最后一步是停止软件,替换旧的源代码并重新启动应用程序 我的问题是以下哪项更合适: 通过对python的系统调用运行更新程序脚本,并使用python终止软件 使用对批处理文件的系统调用运行更新程序脚本,该批处理文件在覆盖主软件的源代码之前终止主软件 将更新程序作为模块导入,并在与主软件相同的过程中执行其所有操作 如果需要,我
@staticmethod
def install(folder):
# stop Pierre, unpack newest version, then restart Pierre.
try:
with open('pierre.pid', mode='r') as pid:
os.kill(int(pid.read()), signal.SIGINT)
with zipfile.ZipFile(file=folder) as zipped:
zipped.extractall(path='src')
try:
pierre = os.path.join(os.path.abspath(os.getcwd()), 'src/pierre.py')
exec(pierre)
except OSError as exc:
logging.error("Restarting Pierre failed. " + str(exc))
try:
os.remove('src.zip')
except OSError as exc:
logging.error("Deletion of zip failed. " + str(exc))
except zipfile.BadZipFile:
logging.error("Pierre update file is corrupt.")
except Exception as exc:
logging.error("Pierre update install failed. " + str(exc))
什么不起作用:
@staticmethod
def update_process():
# Begin the update process by spawning the updater script.
script = 'python ' + os.getcwd() + '\\updater.py'
subprocess.Popen([script])
尽管在命令提示符下手动运行时路径有效,但子进程正在生成一个
FileNotFoundError
。(第二种方法是启动脚本的方法,导致第一种方法。)我已经知道了。下面是流程产卵器现在的样子:
@staticmethod
def update_process():
# Begin the update process by spawning the updater script.
script = os.path.join(os.getcwd() + '/updater.py')
script = script.replace('\\', '/')
subprocess.Popen([sys.executable, script], shell=True)
这将启动单独的更新程序脚本 您尝试过其中任何一种方法吗?@eyllanesc我一直在研究第三种方法,但我在一种方法上遇到了问题,无法在不结束更新程序脚本的情况下终止主进程。@smallpants:向我们展示了您到目前为止得到的结果(代码)@Skandix更新了操作。