comparison wsgintegrate/factory.py @ 10:67cc627cbea7

stub reloading; does not yet work
author Jeff Hammel <jhammel@mozilla.com>
date Sat, 25 Jun 2011 11:06:29 -0700
parents 05683af3240c
children caf763fc1c7d
comparison
equal deleted inserted replaced
9:25424199f1af 10:67cc627cbea7
1
2 """ 1 """
3 WSGI integration factory 2 WSGI integration factory
4 """ 3 """
5 4
5 import os
6 import sys
6 from pyloader.factory import IniFactory 7 from pyloader.factory import IniFactory
7 8
8 class WSGIfactory(IniFactory): 9 class WSGIfactory(IniFactory):
10 def __init__(self, inifile, main=''):
11 IniFactory.__init__(self, inifile, main)
12 self.mtime = os.path.getmtime(self.inifile)
13
9 def __call__(self, environ, start_response): 14 def __call__(self, environ, start_response):
10 """WSGI""" 15 """WSGI application"""
16
17 # if the configuration has changed,
18 # reload the .ini file
19 mtime = os.path.getmtime(self.inifile)
20 if mtime > self.mtime:
21 print "Reloading '%s': %s > %s" % (self.inifile, mtime, self.mtime)
22 try:
23 config = self.read(self.inifile)
24 self.configure(config)
25 except Exception, e:
26 print >> sys.stderr, "Error reading '%s': %s" % (self.inifile, e)
27 self.mtime = mtime
28
11 app = self.load(self.main) 29 app = self.load(self.main)
12 return app(environ, start_response) 30 return app(environ, start_response)
13 31