Member Avatar for leegeorg07

Hi again, I'm now working on a twitter client and I'm wondering how people update their programs when it needs it, for example when I commit a change. Any help on the subject would be most appreciated thanks

Recommended Answers

All 12 Replies

One thing you could try doing is to give the user two different programs. Prog1 is the auto updater and Prog2 is the twitter client. The user will always run prog1. Prog1 will check for a version string in prog2 and check if an updated version of prog2 is available. If so, then it will replace prog2 with the updated version. If there isn't an updated version available, then it will just run prog2.

There might be a better way, but that is what I was able to think of.

Member Avatar for leegeorg07

I was thinking like that, but how could I get prog1 to see any differences? Is there any free services to do this?

Why dont you just have it that it reads the first line of project1 and that can have a simple string telling you what version it is. Then if there is a newer one replace

Have this as the first line:

"12"

f = open('proj1.py')
lineOne = int(f.readlines()[0].strip('"'))
newVersion = 13
if newVersion > lineOne:
    #update

Hope that helps

Exactly. You could use the urllib2 library to connect to a website and pull down a file with the latest version number of your software. Then compare that to the version number that you have as the first line of your program. If different, then use urllib2 to pull down the latest version of your software replacing the old version.

Member Avatar for leegeorg07

oh right okay, i get you now, I will set that up now so i can start sending out previews

Here are my 2cents:
1.Have two textfiles (or whatever) in your server as well as on app
2. app.txt stores current version, last updated, update interval
3. serv.txt stores latest version and status (alpha, beta etc) and type (next version or just bugfix)

At startup, have program compare last updated, add to interval and then compare to current date to see if it should look for update or not.
Then if it is to check for upd, it should invoke update.exe (or whatever you call) which will update necessary components (files et al)

You will be just changing server version and put something higher. Anyway you could use database with full details of what to be updated and the link to the updated file on server. This is better but you can implement whatever you see fullfilling your needs

I'm in hurry, so forgive me for any typo or broken english ;)

Member Avatar for leegeorg07

thanks, I have it finished anyway, if anyone would like the code it's:

import urllib2

update=str(urllib2.urlopen('http://leegeorg07.co.cc/pwitty/update.html'))
current=open('main.py')
def extract(text, sub1, sub2):
    """
    extract a substring from text between first
    occurances of substrings sub1 and sub2
    """
    return text.split(sub1, 1)[-1].split(sub2, 1)[0]
lineOne = float(current.readlines()[0].strip('"'))
for line in update.split('><'):
  if 'a href="' in line:
      print line
      value=extract(line, 'a href="', '.html"')
      print float(value)
      if lineOne < value:
        print 'Pwitty is out of date, I will update now!'
        newVersion=urllib2.urlopen(extract(line, value, '/a'))
        current=newVersion


import main

is this right? It seems to be for me, but I'm just about to compile it for previews.

As I see it, it is a bit complex for the task
you could put a text with three lines
let say this is a server text (serv.txt)

version = 0.1
state = stable
files_to_update =

Then use urllib2 to retrieve that data and update your program. You could use dictionary of filename:file url instead of the above list

Just my 2cents

Member Avatar for leegeorg07

oh ok, so i would just update a single file? that does sound easier.

so would I do something like:

import urllib2

update=str(urllib2.urlopen('http://leegeorg07.co.cc/pwitty/update.txt'))
lineOne = float(current.readlines()[0].strip('"'))
for line in update:
  if 'version = ' in line:
    if line[9:] > lineOne:
      ntu=True #need to update
  if ntu:
    for file in files_to_update:
      tmp=open(file 'w')
      tmp.write(urllib2.urlopen(file))
      tmp.close()

import main

I see,
but I suggest you download it somewhere, check integrity of file and if all is well replacing files with updated. I guess your files will get corrupted if urllib2 fails while updating

Member Avatar for leegeorg07

yeah I probably will, thanks for the help though!

yeah I probably will, thanks for the help though!

glad to help :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.