Self-updating python Scripts

前端 未结 1 1690
南笙
南笙 2021-01-22 01:22

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 selfu

相关标签:
1条回答
  • 2021-01-22 02:08

    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.

    0 讨论(0)
提交回复
热议问题