annotate wsgintegrate/factory.py @ 29:d742aff49859

-> python3
author Jeff Hammel <k0scist@gmail.com>
date Sun, 10 May 2020 18:46:40 -0700
parents caf763fc1c7d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
70fa0bda7726 stub factory class built on pyloader class
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
1 """
70fa0bda7726 stub factory class built on pyloader class
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
2 WSGI integration factory
70fa0bda7726 stub factory class built on pyloader class
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
3 """
70fa0bda7726 stub factory class built on pyloader class
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
4
10
67cc627cbea7 stub reloading; does not yet work
Jeff Hammel <jhammel@mozilla.com>
parents: 3
diff changeset
5 import os
67cc627cbea7 stub reloading; does not yet work
Jeff Hammel <jhammel@mozilla.com>
parents: 3
diff changeset
6 import sys
2
70fa0bda7726 stub factory class built on pyloader class
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
7 from pyloader.factory import IniFactory
70fa0bda7726 stub factory class built on pyloader class
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
8
70fa0bda7726 stub factory class built on pyloader class
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
9 class WSGIfactory(IniFactory):
10
67cc627cbea7 stub reloading; does not yet work
Jeff Hammel <jhammel@mozilla.com>
parents: 3
diff changeset
10 def __init__(self, inifile, main=''):
67cc627cbea7 stub reloading; does not yet work
Jeff Hammel <jhammel@mozilla.com>
parents: 3
diff changeset
11 IniFactory.__init__(self, inifile, main)
67cc627cbea7 stub reloading; does not yet work
Jeff Hammel <jhammel@mozilla.com>
parents: 3
diff changeset
12 self.mtime = os.path.getmtime(self.inifile)
67cc627cbea7 stub reloading; does not yet work
Jeff Hammel <jhammel@mozilla.com>
parents: 3
diff changeset
13
2
70fa0bda7726 stub factory class built on pyloader class
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
14 def __call__(self, environ, start_response):
10
67cc627cbea7 stub reloading; does not yet work
Jeff Hammel <jhammel@mozilla.com>
parents: 3
diff changeset
15 """WSGI application"""
67cc627cbea7 stub reloading; does not yet work
Jeff Hammel <jhammel@mozilla.com>
parents: 3
diff changeset
16
67cc627cbea7 stub reloading; does not yet work
Jeff Hammel <jhammel@mozilla.com>
parents: 3
diff changeset
17 # if the configuration has changed,
67cc627cbea7 stub reloading; does not yet work
Jeff Hammel <jhammel@mozilla.com>
parents: 3
diff changeset
18 # reload the .ini file
67cc627cbea7 stub reloading; does not yet work
Jeff Hammel <jhammel@mozilla.com>
parents: 3
diff changeset
19 mtime = os.path.getmtime(self.inifile)
67cc627cbea7 stub reloading; does not yet work
Jeff Hammel <jhammel@mozilla.com>
parents: 3
diff changeset
20 if mtime > self.mtime:
29
d742aff49859 -> python3
Jeff Hammel <k0scist@gmail.com>
parents: 20
diff changeset
21 print("Reloading '%s': %s > %s" % (self.inifile, mtime, self.mtime))
10
67cc627cbea7 stub reloading; does not yet work
Jeff Hammel <jhammel@mozilla.com>
parents: 3
diff changeset
22 try:
67cc627cbea7 stub reloading; does not yet work
Jeff Hammel <jhammel@mozilla.com>
parents: 3
diff changeset
23 config = self.read(self.inifile)
67cc627cbea7 stub reloading; does not yet work
Jeff Hammel <jhammel@mozilla.com>
parents: 3
diff changeset
24 self.configure(config)
29
d742aff49859 -> python3
Jeff Hammel <k0scist@gmail.com>
parents: 20
diff changeset
25 except Exception as e:
d742aff49859 -> python3
Jeff Hammel <k0scist@gmail.com>
parents: 20
diff changeset
26 sys.stderr.write("Error reading '%s': %s\n" % (self.inifile, e))
10
67cc627cbea7 stub reloading; does not yet work
Jeff Hammel <jhammel@mozilla.com>
parents: 3
diff changeset
27 self.mtime = mtime
20
caf763fc1c7d front end more servers
Jeff Hammel <k0scist@gmail.com>
parents: 10
diff changeset
28
3
05683af3240c fix up main.py
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
29 app = self.load(self.main)
05683af3240c fix up main.py
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
30 return app(environ, start_response)