This repository has been archived by the owner on May 14, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathapp.py
59 lines (47 loc) · 1.44 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
53
54
55
56
57
58
59
#!/usr/bin/env python
# coding=utf-8
import sys
default_encoding = 'utf-8'
if sys.getdefaultencoding() != default_encoding:
reload(sys)
sys.setdefaultencoding(default_encoding)
import logging
import config
from tornado import web
from tornado.ioloop import IOLoop
from tornado.httpserver import HTTPServer
from tornado.options import options, define
from tornado.options import parse_command_line
from tornado.options import parse_config_file
config.init()
class Application(web.Application):
def __init__(self):
from handlers import handlers
settings = dict(
debug=options.debug,
autoescape=None
)
super(Application, self).__init__(handlers, **settings)
def main():
if options.debug:
define('settings', '%s/wechat.conf' % config.PROJDIR)
else:
define('settings', '')
parse_command_line()
debug = options.debug
if options.settings:
parse_config_file(options.settings)
if not debug:
options.debug = False
if options.debug:
logging.info('Starting server at port %s in debug mode' % options.port)
else:
logging.info('Starting server at port %s' % options.port)
server = HTTPServer(Application(), xheaders=True)
server.listen(int(options.port))
IOLoop.instance().start()
if __name__ == '__main__':
try:
main()
except (EOFError, KeyboardInterrupt):
print("\nExiting application")