-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.py
More file actions
91 lines (72 loc) · 3.4 KB
/
app.py
File metadata and controls
91 lines (72 loc) · 3.4 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
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
83
84
85
86
87
88
89
90
91
####################################
# Tornado App Launcher. #
# Author: Giorgos Eracleous #
# Acknowledgement: Alexis Michael #
####################################
import ConfigParser #@UnresolvedImport
import environment #@UnusedImport
import tornado.web, os, pymongo
import app.deps
from urls import url_patterns
from dependencies import css_deps, js_deps
from mongoengine import connect #@UnresolvedImport
from optparse import OptionParser #@UnresolvedImport
class Fasham(tornado.web.Application):
def __init__(self, env, port, config_file):
self.APP_NAME = "fasham-" + str(port)
settings = {
'static_path' : "static",
'template_path' : "templates",
'cookie_secret' : "aKlRsPkySWyOqByxAQfLsKMbEAKj3ErRtg1RgkBUQ6E=noteslib",
'login_url' : "/login", #landing page if user is not authenticated
'xsrf_cookies' : True,
'autoescape' : "xhtml_escape",
'facebook_api_key': "431893480184932",
'facebook_secret': "810bec79e4614b5d3cf338f37dc41b70"
}
config = ConfigParser.RawConfigParser()
config.read(config_file)
############################
# Databse configuration #
############################
db_host = config.get(env, "db_host") or "localhost"
db_name = "fasham_db"
db_user = config.get(env, "db_user")
db_pass = config.get(env, "db_pass")
if env == "prod" and db_user and db_pass:
connect(db_name, host=db_host, username=db_user, password=db_pass)
else:
connect(db_name, host=db_host)
conn = pymongo.Connection(host=db_host)
if hasattr(conn, db_name):
db = getattr(conn, db_name)
if env == "prod" and db_user and db_pass:
db.authenticate(db_user, db_pass)
# Create some capped collections..
if "system.profile" not in db.collection_names():
db.create_collection("system.profile", capped=True, size=50000000, max=300000)
db.set_profiling_level(pymongo.ALL)
############################################
## Configure CSS and JS dependency loader ##
############################################
deps = app.deps.ScriptDeps().registerDep(css_deps).registerDep(js_deps)
########################################################
## Initialize references to application-wide modules. ##
########################################################
self.db = db
self.deps = deps
self.env = env
tornado.web.Application.__init__(self, url_patterns, **settings)
if __name__ == "__main__":
parser = OptionParser()
parser.add_option("-p", type="int", dest="port", help="Server port.")
parser.add_option("-c", type="string", dest="config", help="Config file location.")
options, args = parser.parse_args()
env = "NLENV" in os.environ and os.environ["NLENV"] or "dev"
config_file = options.config or os.path.join("config", "config.default")
config = ConfigParser.RawConfigParser()
config.read(config_file)
port = int(options.port or config.get(env, "port") or 8888)
Fasham(env, port, config_file).listen(port)
# tornado.ioloop.DEFAULT_TIMEOUT = 50000
tornado.ioloop.IOLoop.instance().start()