/
main.py
56 lines (44 loc) · 1.72 KB
/
main.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
#!/usr/bin/env python
#coding=utf-8
import os
import tornado.httpserver
import tornado.ioloop
import tornado.locale
import tornado.options
import tornado.web
from tornado.options import define, options
from init_db import db
import urls
ROOT = os.path.abspath(os.path.dirname(__file__))
define('port', default=8888, help='run on the given port', type=int)
define('settings', default=os.path.join(ROOT, 'settings.py'),
help='path to the settings file.', type=str)
class Application(tornado.web.Application):
def __init__(self):
settings = {'template_path': os.path.join(ROOT, "templates"),
'role': {1: 'Member',
2: 'Admin',
3: 'SuperAdmin'}}
execfile(options.settings, {}, settings)
if 'static_path' not in settings:
settings['static_path'] = os.path.join(ROOT, "static")
super(Application, self).__init__(urls.handlers,
ui_modules=urls.ui_modules, login_url='/account/signin',
**settings)
self.db = db
tornado.locale.load_translations(os.path.join(ROOT, "locale"))
tornado.locale.set_default_locale(settings['default_locale'])
supported_locales = tornado.locale.get_supported_locales()
supported_locales.sort()
locales = []
for locale in supported_locales:
locale = (locale, tornado.locale.LOCALE_NAMES[locale]['name'])
locales.append(locale)
self.locales = tuple(locales)
def main():
tornado.options.parse_command_line()
http_server = tornado.httpserver.HTTPServer(Application())
http_server.listen(options.port)
tornado.ioloop.IOLoop.instance().start()
if __name__ == '__main__':
main()