6:3262fb214544
Anton Shestakov <av6@dwimlabs.net>, Mon, 13 Jun 2016 11:22:32 +0800
candolint: revision + node hash is still unique per project Even though SQLite doesn't enforce uniqueness if rev is NULL, the index is still useful in BaseModel.create_or_get().

next change 9:ac48bb613c6f
previous change 4:69b4a7343f90

checker.py

Permissions: -rwxr-xr-x

Other formats: Feeds:
#!/usr/bin/env python -u
from __future__ import print_function
import os
from argparse import ArgumentParser, FileType
from datetime import datetime
from shutil import rmtree
from subprocess import check_call, CalledProcessError
from tempfile import mkdtemp
import yaml
rel = lambda *x: os.path.abspath(os.path.join(os.path.dirname(__file__), *x))
def print_and_run(args):
print('$ ' + ' '.join(args))
check_call(args)
def run_ignore_1(fn, args):
try:
fn(args)
except CalledProcessError as e:
if e.returncode == 1:
pass
def run(args, silent=False, ignore_1=False):
if silent:
fn = check_call
else:
fn = print_and_run
try:
if ignore_1:
run_ignore_1(fn, args)
else:
fn(args)
return True
except Exception as e:
print('# C&O error: {}'.format(e))
print('# C&O job failed')
return False
def now():
return datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%S+00:00')
def execute(config):
ok = True
print('# C&O job started: {}'.format(now()))
tmp = mkdtemp(prefix='candolint.', dir=rel('workdir'))
os.chdir(tmp)
print('# C&O task: clone')
print('# C&O project URL: {}'.format(config['url']))
source = './source'
if ok and not run(['hg', 'clone', config['url'], source]):
ok = False
if ok:
print('$ cd {}'.format(source))
os.chdir(source)
if ok and not run(['hg', 'sum']):
ok = False
if ok:
template = (r'# C&O commit: {rev}:{node} {branch}\n'
r'# C&O commit date: {date|isodatesec}\n'
r'# C&O commit author: {author|person}\n'
r'# C&O commit message: {desc|firstline}\n')
if not run(['hg', 'log', '-r', '.', '-T', template], silent=True):
ok = False
if ok:
print('# C&O task: setup')
venv = '../venv'
print_and_run(['virtualenv', venv])
pip = os.path.join(venv, 'bin', 'pip')
for linter in config['linters']:
if 'pip' in linter:
if not run([pip, 'install'] + linter['pip']):
ok = False
break
print('# C&O task: cleanup')
rmtree(tmp)
print('# C&O job finished: {}'.format(now()))
def main():
parser = ArgumentParser()
parser.add_argument('config', help='configuration file (YAML)', type=FileType('r'))
args = parser.parse_args()
config = yaml.safe_load(args.config)
execute(config)
if __name__ == '__main__':
main()