自我更新的python脚本 [英] Self-updating python Scripts

查看:115
本文介绍了自我更新的python脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为pyload编写了2-3个插件.有时他们会更改,我会在论坛上让用户知道有新版本.

I wrote 2-3 Plugins for pyload. Sometimes they change and i let users know over forum that theres a new version.

为避免这种情况,我想为脚本提供自动的自我更新功能. https://github.com/Gutz-Pilz/pyLoad-stuff/blob/master/FileBot.py

To avoid that i'd like to give my scripts an auto selfupdate function. https://github.com/Gutz-Pilz/pyLoad-stuff/blob/master/FileBot.py

像这样容易设置的东西吗?

Something like that easy to setup ?

或者有人可以指出我的方向?

Or someone can point me in a direction ?

提前谢谢!

推荐答案

可能有一些警告.但是,它很容易变得非常复杂.在您不知不觉中,您的自动更新功能"将比原始代码还要大!

It is possible, with some caveats. But it can easily become very complicated. Before you know it, your auto-update "feature" will be bigger than the original code!

首先,您需要拥有一个始终包含最新版本的URL.由于您使用的是github,因此使用 raw.githubusercontent 可能会很好.

First you need to have an URL that always contains the latest version. Since you are using github, using raw.githubusercontent might do very well.

让您的代码从该URL下载最新版本(例如,使用 requests ),然后将该版本与当前代码中的版本进行比较.为此,我建议使用一个简单的整数版本号,因此您不需要任何复杂的解析逻辑.

Have your code download the latest version from that URL (e.g. using requests), and compare the version with that in the current code. For this purpose I would recommend a simple integer version number, so you don't need any complicated parsing logic.

但是,您可能希望考虑每天或每周只运行一次该检查.如果每次运行文件时都这样做,则服务器可能会受到重击!因此,现在您必须保存带有最后一次检查日期的文件,然后阅读该文件以查看是否该再次执行检查.该文件将需要保存在您可以在其上运行代码的每个平台上访问的位置.这本身就是一个挑战.

However, you might want to consider only running that check once per day, or once per week. If you do it every time your file is run, the server might get hammered! So now you have to save a file with the date when the check was last done, and read that to see if it is time to run the check again. This file will need to be saved in a location that you can access on every platform your code is liable to run on. That in itself can be a challenge.

如果它只是一个python文件,并以运行它的用户身份安装,则更新相对容易.但是,如果原始文件作为root用户安装在全局Python目录中,并且您的脚本以非特权用户身份运行,则将很困难.尤其是当它作为插件运行并且无法要求用户提供(临时)根凭据来安装文件时.

If it is just a single python file, which is installed as the user that is running it, updating is relatively easy. But if the original was installed as root in the global Python directory and your script is running as a nonprivileged user it will be difficult. Especially if it is running as a plugin and cannot ask the user for (temporary) root credentials to install the file.

如果新版本在标准库之外有更多依赖项,您将怎么办?

And what are you going to do if a newer version has more dependencies outside the standard library?

最后但并非最不重要,作为系统管理员,我真的不喜欢自动更新软件.特别是对于关键的系统基础结构,我希望能够在更新之前 估计后果.

Last but not least, as a sysadmin I don't really like auto-updating software. Especially for critical system infrstructure I like to be able to estimate the consequences before an update.

这篇关于自我更新的python脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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