Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 77 lines (64 sloc) 2.758 kB
2050401 @peterbe right hashbang
authored
1 #!/usr/bin/env python
6441c6d @peterbe initial commit
authored
2 import os
9617d79 @peterbe improved lookups display
authored
3 import re
1edb934 @peterbe reshuffling import of vendor directory
authored
4 import here
6441c6d @peterbe initial commit
authored
5 import tornado.httpserver
6 import tornado.ioloop
7 import tornado.options
8 import tornado.web
9 import redis.client
10 from tornado.options import define, options
d855cc0 @peterbe adding a basic test framework
authored
11 from tornado_utils.routes import route
5132691 @peterbe doing some pep8 cleanup
authored
12 import handlers
1edb934 @peterbe reshuffling import of vendor directory
authored
13 import settings
6441c6d @peterbe initial commit
authored
14
15
16 define("debug", default=False, help="run in debug mode", type=bool)
17 define("database_name", default=settings.DATABASE_NAME, help="db name")
18 define("port", default=8000, help="run on the given port", type=int)
19
20
21 class Application(tornado.web.Application):
22 def __init__(self, database_name=None):
9617d79 @peterbe improved lookups display
authored
23 _ui_modules = __import__('ui_modules', globals(), locals(), ['ui_modules'], -1)
24 ui_modules_map = {}
25 for name in [x for x in dir(_ui_modules) if re.findall('[A-Z]\w+', x)]:
26 thing = getattr(_ui_modules, name)
27 try:
28 if issubclass(thing, tornado.web.UIModule):
29 ui_modules_map[name] = thing
876d6a6 @peterbe adding so it randomly picks a funny background image
authored
30 except TypeError: # pragma: no cover
9617d79 @peterbe improved lookups display
authored
31 # most likely a builtin class or something
32 pass
33
5132691 @peterbe doing some pep8 cleanup
authored
34 routed_handlers = route.get_routes()
6441c6d @peterbe initial commit
authored
35 app_settings = dict(
36 title=settings.PROJECT_TITLE,
37 template_path=os.path.join(os.path.dirname(__file__), "templates"),
38 static_path=os.path.join(os.path.dirname(__file__), "static"),
39 cookie_secret=settings.COOKIE_SECRET,
40 debug=options.debug,
8834f88 @peterbe much better error handling
authored
41 email_backend=options.debug and \
42 'tornado_utils.send_mail.backends.console.EmailBackend' \
43 or 'tornado_utils.send_mail.backends.pickle.EmailBackend',
44 admin_emails=settings.ADMIN_EMAILS,
9617d79 @peterbe improved lookups display
authored
45 ui_modules=ui_modules_map,
6441c6d @peterbe initial commit
authored
46 twitter_consumer_key=settings.TWITTER_CONSUMER_KEY,
47 twitter_consumer_secret=settings.TWITTER_CONSUMER_SECRET,
48 )
a39bc5b @peterbe much improved 404 handling
authored
49 if 1 or not options.debug:
50 routed_handlers.append(
51 tornado.web.url('/.*?', handlers.PageNotFoundHandler,
52 name='page_not_found')
53 )
5132691 @peterbe doing some pep8 cleanup
authored
54 super(Application, self).__init__(routed_handlers, **app_settings)
6441c6d @peterbe initial commit
authored
55
56 self.redis = redis.client.Redis(settings.REDIS_HOST,
57 settings.REDIS_PORT)
58
8775fee @peterbe using mongodb now
authored
59 from models import connection
876d6a6 @peterbe adding so it randomly picks a funny background image
authored
60 self.db = connection[database_name or settings.DATABASE_NAME]
8775fee @peterbe using mongodb now
authored
61
62
6441c6d @peterbe initial commit
authored
63
64 def main(): # pragma: no cover
65 tornado.options.parse_command_line()
66 http_server = tornado.httpserver.HTTPServer(Application())
67 print "Starting tornado on port", options.port
68 http_server.listen(options.port)
69 try:
70 tornado.ioloop.IOLoop.instance().start()
71 except KeyboardInterrupt:
72 pass
73
74
876d6a6 @peterbe adding so it randomly picks a funny background image
authored
75 if __name__ == "__main__": # pragma: no cover
6441c6d @peterbe initial commit
authored
76 main()
Something went wrong with that request. Please try again.