on adding an update checker to my Python programs [Sat, 06 Nov 2010 01:59:27 +0000]
As I've been writing a few Python applications to share [http://blog.humaneguitarist.org/projects/], I've been wondering the last day or so about how to have the application check, upon startup, for updates. This is a pretty common feature in a lot of programs, so I've been wondering how to do it.
Here's what I came up for now. It should work.
Say I have an application called FooPython and its project folder is http://blog.humaneguitarist.org/uploads/FooPython/.
I can just maintain a small XML file in that directory called update.xml that would look like this:
<message>Version 0.9.1 is now available!</message><br/>
Now all I'd have to do is add code similar to that below in my application to alert the user of an update:
from lxml import etree #see: http://codespeak.net/lxml/
url = "http://blog.humaneguitarist.org/uploads/FooPython/update.xml" #not a real URL
update = urllib.urlopen(url).read()
root = etree.XML(update)
currentVersion = root.find(".//currentVersion")
currentVersionValue = currentVersion.text
message = root.find(".//message")
messageValue = message.text
if currentVersionValue != "0.9.0": #assuming this code is for version 0.9.0
All this does is go to the update.xml file and read the element values. If the doesn't match the version specified within the source code itself then it will print the value of the element.