-
Notifications
You must be signed in to change notification settings - Fork 22
/
main.py
executable file
·82 lines (65 loc) · 2.46 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
75
76
77
78
79
80
81
82
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os.path
import sys
import asyncio
import tornado.web
import tornado.options
from tornado.options import 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
import logging
logger = logging.getLogger('mltshp')
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 = settings.get("db") or 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)
async def main():
mltshpoptions.parse_dictionary(settings)
tornado.options.parse_command_line()
app_settings = MltshpApplication.app_settings()
if options.dump_settings:
from pprint import pprint
pprint({'options': dict((k, opt.value())
for k, opt in options.items()),
'app_settings': app_settings})
sys.exit(0)
application = MltshpApplication(routes, autoescape=None, **app_settings)
if options.debug:
logger.setLevel(logging.DEBUG)
logger.info("starting on port %s" % (options.on_port))
application.listen(int(options.on_port))
await asyncio.Event().wait()
if __name__ == "__main__":
asyncio.run(main())