5

I have developed my own program, but I would like to be able to dynamically tell the user that there is an update available for the program. This program is designed to be cross-platform, and is written in python. There will be two types of updates:

1) data updates (an xml file that includes the information required to run the program was updates) - This type of update will occur much more often

2) System updates (the actual executable [a python program compiled] is updated - This type of update will not occur as often

I need to be able to connect to an online database and compare the version posted there to the current program version to see if there is any update. If there is an update from the server, the program needs to be able to download and install that update with minimal user input. My question is how would I tell my program to systematically check for the update and then download and install it without crashing the program or asking the user to manually download and install it?

Ben Schwabe
  • 1,283
  • 1
  • 21
  • 36

2 Answers2

6

A simple workaround is to put some sort of file on you server (let's say program.txt) and put some basic information about the most updated versions in it. Then you have a similar txt file that downloads with the program (let's say version.txt) and put a function in the code to compare the version.txt with the program.txt. If they are the same, then your program is up to date. if not, net you need to go online and download the newest version.

Python function:

import Tkinter
import urllib

def updateCheck(self):
    update = False

    updateWindow = Tkinter.Toplevel()
    updateWindow.title(string="Update Checker")
    updateWindow.resizable(False, False)

    #Gets downloaded version
    versionSource = open('version.txt', 'r')
    versionContents = versionSource.read()

    #gets newest version
    updateSource = urllib.urlopen("http://www.suturesoft.com/Updates/craftbook.txt")
    updateContents = updateSource.read()

    #checks for updates
    for i in range(0,20):
        if updateContents[i] != versionContents[i]:
            dataLabel = Tkinter.Label(updateWindow,text="\n\nThere are data updates availible.\n\n")
            dataLabel.pack()
            update = True
            break
    for i in range(22,42):
        if updateContents[i] != versionContents[i]:
            versionLabel = Tkinter.Label(updateWindow,text="\n\nThere are version updates availible.\n\n")
            versionLabel.pack()
            update = True
            break
    if update == False:
        versionLabel = Tkinter.Label(updateWindow,text="\n\nYou are already running the most up to date version.\n\n")
        versionLabel.pack()

proram.txt and version.txt:

data_version:10.11.12
exec_version:10.11.12

in this case the program would tell you that the program is up to date.

Ben Schwabe
  • 1,283
  • 1
  • 21
  • 36
  • This answer is very useful. Just a small thing, if someone is using python3x, use `import urllib.request` and `urllib.request.urlopen(........)` – Aaditya Joshi Apr 06 '21 at 16:36
5

Set up a simple web service that returns the current version number of the xml file and the executable. Have your program dial home to this web service on startup, and if the web service returns a newer version number then what the program has in its local copy then display a message to the user saying they could update (or start an automated update process).

Joe Day
  • 6,965
  • 4
  • 25
  • 26
  • That's basically what I want to do. The issue is that I have no idea how to program this. Also, I do not have admin privileges to the server, so it would be easier to have python just check a file on the server that we update manually every time we update the program. So I guess the real question is this: is there a way for python to read the contents of an html file? – Ben Schwabe Oct 11 '12 at 15:24
  • 1
    you could just put a static text file on the server at a known url and update that static text file when you publish an update. Have your program download that static text file on startup, and parse it for the version numbers. Possibly using json like this: http://daycodes.com/version.json – Joe Day Oct 11 '12 at 15:31
  • Yep, that's what I want to do. Thanks! – Ben Schwabe Oct 11 '12 at 18:03
  • Did you need a code example for downloading and parsing said json? – Joe Day Oct 11 '12 at 20:09
  • I actually just used basic txt. It works fine. I'll post the code once I can Answer my own question. – Ben Schwabe Oct 11 '12 at 21:15
  • 2
    Umm, I may not have given you something you could cut and paste, but how did I not answer your question? – Joe Day Oct 11 '12 at 21:55