The Artima Developer Community
Sponsored Link

Python Buzz Forum
Autoupdate application modules

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Martin Skou

Posts: 20
Nickname: martinskou
Registered: Jul, 2007

Martin Skou is a developer in Infoserv
Autoupdate application modules Posted: Jul 12, 2007 2:30 PM
Reply to this message Reply

This post originated from an RSS feed registered with Python Buzz by Martin Skou.
Original Post: Autoupdate application modules
Feed Title: Python Fanatic
Feed URL: http://blog.1x.dk/feeds/posts/default
Feed Description: On Python web development.
Latest Python Buzz Posts
Latest Python Buzz Posts by Martin Skou
Latest Posts From Python Fanatic

Advertisement
It's pretty easy to reload modules in Python. Using this feature you can update you whole application to a new version, without leaving or restarting your application.

The code below updates all loaded modules with newer version from any given path. To be included in the update, the module must contain the attribute autoupdate and a version attribute.

import sys
import os

def check(path):
""" Update all modules containing a autoupdate attribute
"""
for name,mod in sys.modules.items():
if hasattr(mod,'autoupdate'):
last_version=getattr(mod,'version')
print "Testing update of : %s v. %d" % (name,last_version)
org_file=os.path.split(mod.__file__)[1].replace('.pyc','.py')
new_module_file="%s\\%s.%d" % (path,org_file,last_version+1)
if os.path.exists(new_module_file):
print "Update found: %s" % new_module_file
update=file(new_module_file,'rb').read()
destination="%s\\%s" % (os.getcwd(), org_file)
print "Will replace: %s" % destination
#os.remove(destination)
#file(destination,'wb').write(update)
reload(mod)


This only works for modules that can work after a reload. Fx. SQLObject has a problem with that...

It would be an easy task to extend this to autoupdate from a FTP- or website.

Read: Autoupdate application modules

Topic: Pownce API - it exists, it's just not yet 'open' Previous Topic   Next Topic Topic: U.S. Fed leaves key interest rate unchanged at 5.25 percent

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use