Anton Shestakov <av6@dwimlabs.net>, Sun, 19 Jun 2016 14:07:11 +0800
incoming: skip checking the whole line when it's linter output
When a line starts with a certain pattern, it's recognized as linter output,
but determining if it's an error or a warning was done looking at the whole
string again multiple times. Let's save on regexes and look only on the
important part.
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') state = 'not even started' m = re.match(r'^(.+):(\d+):\d+: ', line) # https://pep8.readthedocs.io/en/latest/intro.html#error-codes if re.match(r'^E9\d{2}', rest) is not None: elif re.match(r'^[EWFCN]\d{3}', rest) is not None: elif re.match(r'^\[error\]', rest) is not None: elif re.match(r'^\[warning\]', rest) is not None: elif re.match(r'^\(E\d{3}\)', rest) is not None: elif re.match(r'^\(W\d{3}\)', rest) is not None: 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) result.append((cls, line)) parts = [part for part in parsed.path.split('/') if part] with database.transaction(): project, created = Project.create_or_get( change, created = Change.create_or_get( ordinal=Check.select().where(Check.project == project).count() + 1, 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__':