114:7314f0b864b8
Anton Shestakov <av6@dwimlabs.net>, Wed, 06 Jul 2016 16:43:51 +0800
viewer: join change table in check handler for performance reasons

next change 144:e9e0737e1b6e
previous change 100:403f302df870

viewer.py

Permissions: -rwxr-xr-x

Other formats: Feeds:
#!/usr/bin/env python
from __future__ import absolute_import
import logging
import os
from tornado.ioloop import IOLoop
from tornado.options import define, options
from tornado.web import Application, URLSpec
from candolint import uimodules
from candolint.handlers import IndexHandler, ProjectHandler, CheckHandler, StatusHandler, ErrorHandler
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 CandolintViewer(Application):
def __init__(self):
handlers = [
URLSpec(r'/', IndexHandler),
URLSpec(r'/([.a-z0-9_-]+)/([^/]+)/([^/]+)', ProjectHandler),
URLSpec(r'/([.a-z0-9_-]+)/([^/]+)/([^/]+)/([\d]+|latest)(?:/(raw))?', CheckHandler),
URLSpec(r'/([.a-z0-9_-]+)/([^/]+)/([^/]+)/status\.svg', StatusHandler),
URLSpec(r'.*', ErrorHandler, {'status_code': 404})
]
settings = dict(
static_path=rel('static'),
template_path=rel('templates'),
ui_modules=uimodules,
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):
name = self.__class__.__name__
logging.info('%s is serving on %s:%d', 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()