2:213d23f13f6f
Anton Shestakov <av6@dwimlabs.net>, Mon, 13 Jun 2016 09:54:55 +0800
candolint: revision number is not unique for a project (after editing history)

next change 3:73d07ba32f93
previous change 1:4c512d0ecec5

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
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()