Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 76 lines (64 sloc) 2.758 kb
20504013 »
2011-08-26 right hashbang
1 #!/usr/bin/env python
6441c6d0 »
2011-08-22 initial commit
2 import os
9617d795 »
2011-10-20 improved lookups display
3 import re
1edb9344 »
2011-10-06 reshuffling import of vendor directory
4 import here
6441c6d0 »
2011-08-22 initial commit
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
d855cc05 »
2011-09-02 adding a basic test framework
11 from tornado_utils.routes import route
51326910 »
2011-09-02 doing some pep8 cleanup
12 import handlers
1edb9344 »
2011-10-06 reshuffling import of vendor directory
13 import settings
6441c6d0 »
2011-08-22 initial commit
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):
9617d795 »
2011-10-20 improved lookups display
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
876d6a6d »
2011-10-21 adding so it randomly picks a funny background image
30 except TypeError: # pragma: no cover
9617d795 »
2011-10-20 improved lookups display
31 # most likely a builtin class or something
32 pass
33
51326910 »
2011-09-02 doing some pep8 cleanup
34 routed_handlers = route.get_routes()
6441c6d0 »
2011-08-22 initial commit
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,
8834f886 »
2011-11-01 much better error handling
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,
9617d795 »
2011-10-20 improved lookups display
45 ui_modules=ui_modules_map,
6441c6d0 »
2011-08-22 initial commit
46 twitter_consumer_key=settings.TWITTER_CONSUMER_KEY,
47 twitter_consumer_secret=settings.TWITTER_CONSUMER_SECRET,
48 )
a39bc5b4 »
2011-11-07 much improved 404 handling
49 if 1 or not options.debug:
50 routed_handlers.append(
51 tornado.web.url('/.*?', handlers.PageNotFoundHandler,
52 name='page_not_found')
53 )
51326910 »
2011-09-02 doing some pep8 cleanup
54 super(Application, self).__init__(routed_handlers, **app_settings)
6441c6d0 »
2011-08-22 initial commit
55
56 self.redis = redis.client.Redis(settings.REDIS_HOST,
57 settings.REDIS_PORT)
58
8775feef »
2011-09-25 using mongodb now
59 from models import connection
876d6a6d »
2011-10-21 adding so it randomly picks a funny background image
60 self.db = connection[database_name or settings.DATABASE_NAME]
8775feef »
2011-09-25 using mongodb now
61
62
6441c6d0 »
2011-08-22 initial commit
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
876d6a6d »
2011-10-21 adding so it randomly picks a funny background image
75 if __name__ == "__main__": # pragma: no cover
6441c6d0 »
2011-08-22 initial commit
76 main()
Something went wrong with that request. Please try again.