如何远程更新Python应用程序 [英] How to remotely update Python applications

查看:632
本文介绍了如何远程更新Python应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将更改推送到用Python编写的程序的最佳方法是什么?我有一个用Python编写的软件,该软件会定期更新.最好的方法是什么?所有机器都将安装Windows 7.

What is the best method to push changes to a program written in Python? I have a piece of software that is written in Python that will regularly be updated. What would be the best way to do this? All the machines will have Windows 7.

此外,请原谅我的问题含糊不清.这是我第一次必须执行更新程序.随意提及您希望我添加的细节.

Also, excuse the ambiguity of my question. This will be my first time having to implement an updating procedure. Feel free to mention specifics you would like me ot add.

推荐答案

如果尚未使用

If you're not already packaging your program with InnoSetup, I strongly recommend you switch to it, because it has facilities to make this sort of thing easier. You can specify any special situations, such as files that should not be updated if they already exist (i.e. if you have any internal configuration files or things like that), in the InnoSetup script.

接下来,要允许客户端计算机查找应用程序的新版本,请在公共Web服务器上保留一个非常小的文件,该文件应具有当前发行版的版本号以及最新版本的安装程序exe的URL.为了使此文件有用,每当您发布程序的较新版本时,都必须更新此文件,InnoSetup脚本中的版本号以及程序中的某种APP_VERSION常量.

Next, to allow the client machine to find out about new versions of your app, keep a very small file on your public web server that has the version number of the current release and the URL to the latest version's installer exe. For this file to be useful, whenever you release a newer version of your program you must update this file, as well as the version number in the InnoSetup script, and also some kind of APP_VERSION constant in your program.

然后,您需要自己处理更新程序的这些部分:

Then, you'll need to handle these parts of the updater yourself:

  1. 通过HTTP检索Web服务器中的当前版本文件,然后将其中的版本号与应用程序自己的APP_VERSION进行比较,从而确定何时有更新版本可用.确保以这样的方式进行此查询:如果客户端计算机无法访问Internet,并且不会在执行请求时阻止GUI(如果存在网络问题而导致查询不得不等待),则该查询会以正常方式失败很长一段时间超时).
  2. 如果有较新的版本,请询问用户是否要更新,如果回答是",则将更新的安装程序下载到TEMP目录.根据所使用的GUI工具箱,有多种机制可用于在下载过程中显示进度对话框.这是个好主意,因为安装程序可能至少为MB.
  3. 关闭您的应用,在后台运行特殊的更新脚本<​​a href="https://stackoverflow.com/questions/1196074/starting-a-background-process-in-python"> ,然后再次启动该应用.
  1. Detecting when a newer version is available by retrieving the current-version file from your web server over HTTP, and comparing the version number there to the app's own APP_VERSION. Make sure to do this query in a way that fails gracefully if the client machine doesn't have Internet access, and that doesn't block the GUI while it is doing the request (in case there's a network issue that forces the query to wait a long while for a timeout).
  2. If a newer version is available, asking the user if they want to update, and if they say yes downloading an updated installer to the TEMP directory. Depending on what GUI toolkit you are using, there are various mechanisms for displaying a progress dialog during the download; this is a good idea since the installer is likely to be at least an MB.
  3. Closing your app, running a special update script in the background, then starting up the app again.

更新脚本将等待原始进程完全终止(最简单的方法是将原始进程的PID作为命令行参数传入,并使用更新脚本<​​a href ="https://stackoverflow. com/questions/568271/check-if-pid-is-not-in-in-in-in-in-in-in-in-in-in-in-in-in-in-in-in-in-in-in-in-in-in-in-in-in-in-in-in-in-in-in-in-in-in-in-in-in-in-in-in-in-in-in-in-in --------------------/-/-///-/-中,每秒使用查询信号0 ,直到其消失. )然后可以在后台静默运行安装程序,也许同时向用户显示请稍候..."对话框.安装程序完成并在返回代码中报告成功后,更新程序可以重新启动您的程序.

The update script will wait for the original process to die completely (easiest way to do this is to pass in the original process's PID as a command line argument and have the update script send a query signal 0 to that process every second or so until it goes away.) It can then run the installer silently in the background, perhaps while displaying a "Please Wait..." dialog to the user. Once the installer is done and reports success in its return code, the updater can restart your program.

取决于您的应用程序的大小,这比使用git或其他SCM的方法更浪费带宽.使用此方法进行的每次更新都涉及为该应用程序的最新版本下载整个安装程序,而SCM仅下载已更改的文件.但是,它的优点是,除了常规的Web服务器外,它不需要特殊的服务器功能,并且不需要在用户计算机上特殊安装SCM客户端.

Depending on how big your app is, this is more wasteful of bandwidth than the method using git or another SCM. Every update with this approach would involve downloading the entire installer for the latest version of the app, whereas an SCM would only download the files that have changed. However, it has the advantage that it requires no special server facilities except a regular web server, and no special installation of the SCM client on the user's computer.

另外,InnoSetup通常很酷. :-)

Plus, InnoSetup is just generally cool. :-)

这篇关于如何远程更新Python应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆