forked from MLTSHP/mltshp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·74 lines (61 loc) · 2.49 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os.path
import sys
import tornado.httpserver
import tornado.ioloop
import tornado.web
import tornado.options
import torndb
from tornado.options import define, options
from tornado.httpclient import AsyncHTTPClient
from lib.flyingcow import register_connection
import lib.flyingcow.cache
from routes import routes
import lib.uimodules
import mltshpoptions
from settings import settings
import stripe
AsyncHTTPClient.configure("tornado.curl_httpclient.CurlAsyncHTTPClient")
class MltshpApplication(tornado.web.Application):
@classmethod
def app_settings(cls):
dirname = os.path.dirname(os.path.abspath(__file__))
return {
"debug": options.debug,
"cookie_secret": options.cookie_secret,
"xsrf_cookies": options.xsrf_cookies,
"twitter_consumer_key": options.twitter_consumer_key,
"twitter_consumer_secret": options.twitter_consumer_secret,
# invariant settings
"login_url": "/sign-in",
"static_path": os.path.join(dirname, "static"),
"template_path": os.path.join(dirname, "templates"),
"ui_modules": lib.uimodules,
}
def __init__(self, *args, **settings):
self.db = register_connection(host=options.database_host,
name=options.database_name,
user=options.database_user,
password=options.database_password,
charset="utf8mb4")
if options.use_query_cache:
lib.flyingcow.cache.use_query_cache = True
if options.stripe_secret_key:
stripe.api_key = options.stripe_secret_key
super(MltshpApplication, self).__init__(*args, **settings)
if __name__ == "__main__":
mltshpoptions.parse_dictionary(settings)
tornado.options.parse_command_line()
if options.dump_settings:
from pprint import pprint
pprint({'options': dict((k, opt.value())
for k, opt in options.iteritems()),
'app_settings': app_settings})
sys.exit(0)
app_settings = MltshpApplication.app_settings()
application = MltshpApplication(routes, autoescape=None, **app_settings)
http_server = tornado.httpserver.HTTPServer(application)
print "starting on port %s" % (options.on_port)
http_server.listen(int(options.on_port))
tornado.ioloop.IOLoop.instance().start()