view wsgintegrate/factory.py @ 20:caf763fc1c7d

front end more servers
author Jeff Hammel <k0scist@gmail.com>
date Thu, 06 Mar 2014 22:52:25 -0800
parents 67cc627cbea7
children d742aff49859
line wrap: on
line source

"""
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 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)