Anton Shestakov <engored@ya.ru>, Sat, 02 May 2015 02:56:30 +0800
bench: default revsets should be an iterable
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 settings import DBPATH, HG, TEMPLATES, TESTHGREPO define('listen', metavar='IP', default='127.0.0.1') define('port', metavar='PORT', default=8065, type=int) define('xheaders', metavar='True|False', default=False, type=bool) define('debug', metavar='True|False', default=False, type=bool) output = subprocess.check_output([HG, 'log', '-R', TESTHGREPO, '-T', 'json', '-r', revset]) return json.loads(output) class BaseHandler(RequestHandler): self.conn = sqlite3.connect(DBPATH) super(BaseHandler, self).prepare() class IndexHandler(BaseHandler): self.redirect('results.html') class ResultsHandler(BaseHandler): rev = self.get_argument('rev', 'tip') 'SELECT MIN(time), MAX(time) FROM results WHERE mark = ? AND cache = ?', (mark, False)).fetchone() changesets = getinfo('first(%s:0, %d)' % (rev, revcount)) resultsq = self.conn.execute( 'SELECT mark, time FROM results WHERE node = ? AND cache = ?', for mark, time in resultsq: color = green_to_red(limits[mark], time) if time is not None else None results.setdefault(node, {})[mark] = (time, color) return changesets, results self.set_header('Content-Type', 'text/plain; charset=UTF-8') changesets, results = self.getdata() self.write('%(rev)s\t%(node)s\t' % cset) str(results.get(cset['node'], {}).get(mark, ('',))[0]) self.set_header('Content-Type', 'text/plain; charset=UTF-8') rev = self.get_argument('rev', 'tip') regex = re.compile(r'^[-\\|/+ ]+([0-9a-f]{40})$') template = '{rev}:{node|short} {tags} {date|isodate} {author|user} {desc|firstline|strip}\n {node}\n\n' revset = 'first(%s:0, %d)' % (rev, revcount) cmd = [HG, 'log', '-R', TESTHGREPO, '-G', '-T', template, '-r', revset] graph = subprocess.Popen(cmd, stdout=subprocess.PIPE) while graph.poll() is None: line = graph.stdout.readline() matches = regex.findall(line) rows = self.conn.execute('SELECT mark, time FROM results WHERE node = ?', (match,)) msg.append('{}: {:.2g}s'.format(*row)) line = line.replace(match, ' '.join(msg)) changesets, results = self.getdata() self.render('results.html', changesets=changesets, marks=MARKS, results=results) def green_to_red((low, high), value): hue = (value - low) / (high - low) if high != low else 0.5 r, g, b = colorsys.hsv_to_rgb((1 - hue) * 0.3, 1, 1) return (int(r * 255), int(g * 255), int(b * 255)) class Viewer(Application): URLSpec(r'/', IndexHandler), URLSpec(r'/results\.(html|tsv|asc)', ResultsHandler), super(Viewer, self).__init__(handlers, **settings) def listen(self, port, address='', **kwargs): logging.info('{} is serving on {}:{}'.format(self.__class__.__name__, address, port)) super(Viewer, self).listen(port, address, **kwargs) options.parse_command_line() application.listen(options.port, address=options.listen, xheaders=options.xheaders) IOLoop.instance().start() if __name__ == '__main__':