Checking for new version of a program

Andrei Kulakov sill at optonline.net
Tue Aug 21 01:36:49 EDT 2001


Hello,

I made a little function that checks for a new version of a program and if
there is a new version, asks the user if he wants it downloaded. Are there
any gotchas here? I don't know much about proxies, could there be any
problem with them caching the document with version info? It works here
but I'm afraid this looks too easy to be flawless.

Here's how I'm doing it:

    def live_update(self):
        if check_for_updates:
            try:
                global __version__
                vers = urllib.urlopen(vers_url).read()[:-1]
                if vers != __version__:
                    self.new_version = 1
                    __version__ = vers
            except: pass

    def get_update(self):
        self.stop()
        self.clear_line()
        print """
    New Cymbaline version is available: %s.

    If you don't want to check for new versions, set
    check_for_updates to 0 at the top of cymbaline.py

    Hit Enter... """ % __version__,
        raw_input(" ")
        changes = urllib.urlopen(changes_url).read()
        print
        print changes
        print "Hit Enter..",
        raw_input("")
        print "\rDo you wish to download the latest version? [Y/n] ",
        sys.stdout.flush()
        self.set_normal_term()
        ans = raw_input(" ")
        self.set_curses_term()
        if not ans or ans in "Yy":
            cy_fname = "cymbaline-%s.tar.gz" % __version__
            cy_url = base_url + cy_fname
            cy = urllib.urlopen(cy_url).read()
            fname = os.path.expanduser("~/" + cy_fname)
            f = open(fname, 'w')
            f.write(cy)
            f.close()
            os.system("tar zxvf %s " % fname)
            os.remove(fname)
            print """
    If all went right, Cymbaline should now be untarred to your home
    directory. If not, you can always get it at http://cy.silmarill.org
    To use new Cymbaline, copy cymbaline.py to some location in your path.
    """
        self.new_version = 0

thread.start_new_thread(self.live_update, ())


Comments appreciated,

 - Andrei

-- 
Cymbaline: intelligent learning mp3 player - python, linux, console.
get it at: cy.silmarill.org



More information about the Python-list mailing list