# HG changeset patch # User Jeff Hammel # Date 1309025189 25200 # Node ID 67cc627cbea7f1953f1a30c391436f18888591ae # Parent 25424199f1afb806882cf326f8012fe19cd131b9 stub reloading; does not yet work diff -r 25424199f1af -r 67cc627cbea7 wsgintegrate/factory.py --- a/wsgintegrate/factory.py Tue Jun 21 07:08:24 2011 -0700 +++ b/wsgintegrate/factory.py Sat Jun 25 11:06:29 2011 -0700 @@ -1,13 +1,31 @@ - """ WSGI integration factory """ +import os +import sys from pyloader.factory import IniFactory class WSGIfactory(IniFactory): + def __init__(self, inifile, main=''): + IniFactory.__init__(self, inifile, main) + self.mtime = os.path.getmtime(self.inifile) + def __call__(self, environ, start_response): - """WSGI""" + """WSGI application""" + + # if the configuration has changed, + # reload the .ini file + mtime = os.path.getmtime(self.inifile) + if mtime > self.mtime: + print "Reloading '%s': %s > %s" % (self.inifile, mtime, self.mtime) + try: + config = self.read(self.inifile) + self.configure(config) + except Exception, e: + print >> sys.stderr, "Error reading '%s': %s" % (self.inifile, e) + self.mtime = mtime + app = self.load(self.main) return app(environ, start_response)