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

查看:75
本文介绍了如何远程更新 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.

推荐答案

如果您还没有使用 InnoSetup,我强烈建议您切换到它,因为它具有使此类事情更容易的功能.您可以在 InnoSetup 脚本中指定任何特殊情况,例如如果文件已经存在则不应更新(即如果您有任何内部配置文件或类似的东西).

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.

接下来,为了让客户端机器了解您的应用程序的新版本,请在您的公共网络服务器上保留一个非常小的文件,其中包含当前版本的版本号和最新版本安装程序 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 从您的网络服务器检索当前版本文件,并将那里的版本号与应用程序自己的 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 作为命令行参数传入并让更新脚本 每秒向该进程发送一个查询信号 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天全站免登陆