Download:
child 2:213d23f13f6f
parent 0:4dcbaa8e310c
1:4c512d0ecec5
Anton Shestakov <av6@dwimlabs.net>, Mon, 13 Jun 2016 09:47:55 +0800
incoming: a script to run checks At the moment, it just clones source and then cleans up.

2 файлов изменено, 81 вставок(+), 0 удалений(-) [+]
checker.py file | annotate | diff | comparison | revisions
requirements.txt file | annotate | diff | comparison | revisions
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/checker.py Mon Jun 13 09:47:55 2016 +0800
@@ -0,0 +1,80 @@
+#!/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()
--- a/requirements.txt Sun Jun 12 22:28:31 2016 +0800
+++ b/requirements.txt Mon Jun 13 09:47:55 2016 +0800
@@ -1,1 +1,2 @@
peewee==2.8.1
+PyYAML==3.11