Self-updating python Scripts

ⅰ亾dé卋堺 提交于 2020-11-29 09:59:27

问题


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

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 ?

Thanks in advance!


回答1:


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!

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.

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.

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.



来源:https://stackoverflow.com/questions/31918875/self-updating-python-scripts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!