-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
55 lines (40 loc) · 1.3 KB
/
Copy pathmain.py
File metadata and controls
55 lines (40 loc) · 1.3 KB
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
# -*- coding: utf-8 -*-
import logging
import tornado.ioloop
import tornado.web
import tornado.autoreload
from tornado.options import define, options
from skeleton.routes import routes
from utils.config import ConfigManager
define(
'env', default='local',
help='Target environment e.g. mthomas, stg, prod', type=str)
config = None
def get_config(args):
global config
if config is None:
# Get config from conf manager based on provided env
env = options.env
logging.info('Loading new etcd config for env: %s', env)
config = ConfigManager.load(env, 'skeleton')
return config
class Application(tornado.web.Application):
def __init__(self):
handlers = routes()
tornado.web.Application.__init__(self, handlers, **config)
def main():
fmt = '%(asctime)s %(levelname)-8.8s %(message)s'
logging.basicConfig(format=fmt)
logging.root.setLevel('INFO')
tornado.options.parse_command_line()
global config
config = get_config(options)
app = Application()
app.listen(int(config['port']))
logging.info('Starting skeleton app on port %d', int(config['port']))
if config['debug']:
tornado.autoreload.start()
tornado.ioloop.IOLoop.instance().start()
if __name__ == '__main__':
main()