-
Notifications
You must be signed in to change notification settings - Fork 6
/
launch.py
executable file
·56 lines (41 loc) · 1.46 KB
/
launch.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
53
54
55
#!/usr/bin/env python
import tornado.httpserver
import tornado.ioloop
import tornado.web
import sys
import app # our application
from settings import app_settings
from optparse import OptionParser
from app.views.viewlib import route
def start_instance(settings):
http_server = tornado.httpserver.HTTPServer(
app.setup_app(settings)
)
http_server.listen(settings['port'])
try: tornado.ioloop.IOLoop.instance().start()
except KeyboardInterrupt: pass
def list_routes(routes):
for r in routes:
print '{:20s} => {}'.format(r.regex.pattern, r.name)
if __name__ == "__main__":
parser = OptionParser()
parser.add_option("-r", "--routes", action="store_true",
help="print list of routes and exit" )
parser.add_option("-p", "--port", help="specify httpd port")
parser.add_option("-d", "--debug", action="store_true",
help="start with debugging enabled" )
(options, args) = parser.parse_args()
if options.routes:
list_routes(route.get_routes())
raise SystemExit
if options.port:
try: app_settings['port'] = int(options.port)
except: pass
elif args:
try: app_settings['port'] = int(args[0])
except: pass
if options.debug:
app_settings['debug'] = True
print "starting Tornado{} on port {}".format(
'(dbg)' if app_settings.get('debug') else '', app_settings['port'] )
start_instance(app_settings)