Member Avatar for Member #361407

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

Dani AI

Generated

Good foundation here — ’s two-program pattern and the simple version-file ideas from and are exactly the right way to start for a small Python tool like a Twitter client. The code snippets in the thread are fine for prototypes; the gaps to close before shipping are robustness and security. The rest of this note explains practical, low-risk practices to make an updater safe and reliable.

Always treat the updater as an untrusted network client: serve metadata over HTTPS, and never replace live files until you have validated the download. Use a small manifest (version, channel, file list, file hashes and a signature) rather than parsing HTML. Download updated files to a temporary location, verify a strong checksum (SHA256) and a cryptographic signature if possible, then perform an atomic replace (move/rename) and keep a last-known-good backup so you can roll back on failure. Run the actual replace from a helper/updater process so the running program isn’t overwriting itself.

Decide update policy up front: semantic versioning, optional vs forced updates, and release channels (stable/beta). Avoid checking every startup — use a sensible interval, exponential backoff on failures, and let users opt out or defer. Log every update attempt and show clear release notes so users know what changed. For Python-distributed software consider publishing proper packages (pip/PyPI) or using platform-native installers instead of ad-hoc script-replacement when wider distribution is intended.

Common pitfalls to watch for: partial downloads, insufficient disk space, file locks/permissions (especially on Windows), race conditions if multiple instances check at once, and executing downloaded code before verification. For quick testing your approach is fine, but before distributing beyond friends add transport encryption, integrity checks, atomic replacement, and a rollback path.

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 Member #361407

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 Member #361407

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 Member #361407

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 Member #361407

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(''))
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 Member #361407

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.