-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathmain.py
More file actions
55 lines (38 loc) · 1.44 KB
/
Copy pathmain.py
File metadata and controls
55 lines (38 loc) · 1.44 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
#coding:utf-8
import os
import sys
from redis import Redis
from tomako import MakoTemplateLoader
from tornado import web
from tornado.ioloop import IOLoop
from tornado.httpserver import HTTPServer
from tornado.options import define, options
from util.session import SessionManager
from url import handlers,sub_handlers
from config import conf
reload(sys)
sys.setdefaultencoding("utf-8")
define('port', default=8081, type=int)
define('dev', default="true")
options.parse_command_line()
class Main(web.Application):
def __init__(self):
settings = dict(
debug = True if options.dev == "true" else False,
cookie_secret = "",
xsrf_cookies = False,
login_url = "/auth/login",
static_path = os.path.join(os.path.dirname(__file__), "static"),
template_loader = MakoTemplateLoader(os.path.join(os.path.dirname(__file__),'templates')),
)
super(Main, self).__init__(handlers, **settings)
self.redis = Redis(host=conf.get("redis", "host"), port=conf.get("redis", "port"), db =2)
self.session_manager = SessionManager(self.redis)
for sub_handler in sub_handlers:
self.add_handlers(sub_handler[0], sub_handler[1])
if __name__ == "__main__":
http_server = HTTPServer(Main(), xheaders=True)
http_server.bind(options.port)
http_server.start(1)
print "start on port %s..." % options.port
IOLoop.instance().start()