Download:
child 8:12e714447f64
parent 6:3262fb214544
7:43cbf5d4ef13
Anton Shestakov <av6@dwimlabs.net>, Mon, 13 Jun 2016 11:26:22 +0800
viewer: the frontend

1 файлов изменено, 60 вставок(+), 0 удалений(-) [+]
viewer.py file | annotate | diff | comparison | revisions
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/viewer.py Mon Jun 13 11:26:22 2016 +0800
@@ -0,0 +1,60 @@
+#!/usr/bin/env python
+import logging
+import os
+
+from tornado.ioloop import IOLoop
+from tornado.options import define, options
+from tornado.web import Application, RequestHandler
+
+from candolint.models import database
+
+
+rel = lambda *x: os.path.abspath(os.path.join(os.path.dirname(__file__), *x))
+
+
+define('listen', metavar='IP', default='127.0.0.1')
+define('port', metavar='PORT', default=8033, type=int)
+define('xheaders', metavar='True|False', default=False, type=bool)
+define('debug', metavar='True|False', default=False, type=bool)
+
+
+class BaseHandler(RequestHandler):
+ def prepare(self):
+ database.connect()
+ super(BaseHandler, self).prepare()
+
+ def on_finish(self):
+ if not database.is_closed():
+ database.close()
+
+
+class CandolintViewer(Application):
+ def __init__(self):
+ handlers = [
+ ]
+ settings = dict(
+ static_path=rel('static'),
+ template_path=rel('templates'),
+ debug=options.debug
+ )
+ super(CandolintViewer, self).__init__(handlers, **settings)
+ if options.debug:
+ logging.getLogger('peewee').setLevel(logging.DEBUG)
+ database.init(rel('database.sqlite'))
+
+ def listen(self, port, address='', **kwargs):
+ logging.info('{} is serving on {}:{}'.format(self.__class__.__name__, address, port))
+ super(CandolintViewer, self).listen(port, address, **kwargs)
+
+
+def main():
+ options.parse_command_line()
+
+ application = CandolintViewer()
+ application.listen(options.port, address=options.listen, xheaders=options.xheaders)
+
+ IOLoop.instance().start()
+
+
+if __name__ == '__main__':
+ main()