Anton Shestakov <av6@dwimlabs.net>, Wed, 29 Jun 2016 09:00:24 +0800
viewer: add proper markup to changeset date so it's picked up by moment.js
incoming.py
Permissions: -rwxr-xr-x
from __future__ import absolute_import from datetime import datetime from urlparse import urlparse from tornado.escape import json_encode from candolint.models import database, Project, Change, Check rel = lambda *x: os.path.abspath(os.path.join(os.path.dirname(__file__), *x)) def parse_timestamp(value): return datetime.strptime(value, '%Y-%m-%dT%H:%M:%S+00:00') def parse_project_url(url): parts = [part for part in parsed.path.split('/') if part] name = '/'.join(parts[1:]) return domain, user, name def match_linter_output(line): m = re.match(r'^(?P<filename>.+):(?P<fileline>\d+):\d+: ', line) item['filename'] = m.group('filename') item['fileline'] = int(m.group('fileline')) # https://pep8.readthedocs.io/en/latest/intro.html#error-codes (r'^[EWFCN]\d{3}', 'warning'), (r'^\[error\]', 'error'), (r'^\[warning\]', 'warning'), (r'^\(E\d{3}\)', 'error'), (r'^\(W\d{3}\)', 'warning'), for regex, cls in patterns: m = re.match(regex, rest) return errors, warnings, item line = line.rstrip('\r\n') if line.startswith(meta_prefix): rest = line[len(meta_prefix):] m = re.match('^task: (\w+)$', rest) m = re.match('^job failed$', rest) m = re.match('^job (started|finished): ([\dT:+-]+)$', rest) if m.group(1) == 'started': started = parse_timestamp(m.group(2)) elif m.group(1) == 'finished': finished = parse_timestamp(m.group(2)) m = re.match('^project URL: (\S+)$', rest) m = re.match('^commit: (\d+):(\w+) (\w+)$', rest) m = re.match('^commit date: (.+)$', rest) m = re.match('^commit author: (.+)$', rest) m = re.match('^commit message: (.+)$', rest) de, dw, extra = match_linter_output(line) domain, user, name = parse_project_url(url) with database.transaction(): project, created = Project.create_or_get( change, created = Change.create_or_get( ordinal=Check.get_next_ordinal(project), lines=json_encode(result), database.init(rel('database.sqlite')) database.create_tables([Project, Change, Check], safe=True) logger = logging.getLogger('peewee') logger.setLevel(logging.DEBUG) logger.addHandler(logging.StreamHandler()) insert_check(list(fileinput.input())) if __name__ == '__main__':