Anton Shestakov <av6@dwimlabs.net>, Mon, 13 Jun 2016 21:51:21 +0800
viewer: add basic index page
viewer.py
Permissions: -rwxr-xr-x
from tornado.ioloop import IOLoop from tornado.options import define, options from tornado.web import Application, RequestHandler, URLSpec from candolint.models import database, Project, Change, Check 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): super(BaseHandler, self).prepare() if not database.is_closed(): class IndexHandler(BaseHandler): .select(Check, Project, Change) .group_by(Check.project)) self.render('index.html', checks=checks) class CandolintViewer(Application): URLSpec(r'/', IndexHandler), static_path=rel('static'), template_path=rel('templates'), super(CandolintViewer, self).__init__(handlers, **settings) 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) options.parse_command_line() application = CandolintViewer() application.listen(options.port, address=options.listen, xheaders=options.xheaders) IOLoop.instance().start() if __name__ == '__main__':