-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.py
52 lines (38 loc) · 1.18 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import sys
import os
abspath = os.path.dirname(__file__)
print abspath
if len(abspath) > 0:
sys.path.append(abspath)
os.chdir(abspath)
# common imports
from modules.common import *
import modules.glob as glob
from web import form
import signal
from os import _exit
import time
from urlparse import urlparse
from modules.PageServer import *
class QuickVoteApp(web.application):
def run(self, *middleware):
func = self.wsgifunc(*middleware)
return web.httpserver.runsimple(func, ('0.0.0.0', config.listen_port))
if __name__ == '__main__':
app = QuickVoteApp((), globals())
else:
app = web.application(glob.urls, globals(), autoreload=False)
path_prefix = urlparse(config.base_url).path
print "path_prefix = " + path_prefix
for v in glob.urls.values():
app.add_mapping(v['pattern'], v['class'])
v['url_pattern'] = path_prefix + v['pattern'][1:].replace('(.+)', '%s')
print '(%s, %s, %s)' % (v['pattern'], v['class'], v['url_pattern'])
def signal_handler(signum, frame):
print "stopped."
_exit(signal.SIGTERM)
if __name__ == '__main__':
signal.signal(signal.SIGINT, signal_handler)
app.run()
else:
application = app.wsgifunc()