Download:
child 201:3e522a31ae89
parent 199:3d3300a1af40
200:51b38a0bdcea
Anton Shestakov <av6@dwimlabs.net>, Fri, 05 Aug 2016 15:39:05 +0800
checker: use candolint.yml if it's found in project's root directory

2 файлов изменено, 51 вставок(+), 17 удалений(-) [+]
checker.py file | annotate | diff | comparison | revisions
worker-queue.py file | annotate | diff | comparison | revisions
--- a/checker.py Fri Aug 05 12:46:39 2016 +0800
+++ b/checker.py Fri Aug 05 15:39:05 2016 +0800
@@ -74,6 +74,20 @@
return None
+def read_intree_config():
+ try:
+ fd = open('candolint.yml')
+ except Exception as e:
+ print("# C&O couldn't load in-tree config: {}".format(e))
+ return None
+ with fd:
+ try:
+ return yaml.safe_load(fd)
+ except Exception as e:
+ print("# C&O couldn't parse in-tree config: {}".format(e))
+ return None
+
+
def prevalidate(config):
ok = True
@@ -227,6 +241,17 @@
return False
print('# C&O task: setup')
+ if args.data is not None:
+ intree = read_intree_config()
+ if intree is not None:
+ config.update(intree)
+ print('# C&O using in-tree config')
+ else:
+ print('# C&O in-tree config is required while bootstrapping')
+ return False
+ else:
+ print('# C&O not using in-tree config')
+
linters = []
distinct = []
for linter in config.get('linters', []):
@@ -329,12 +354,19 @@
def main():
parser = ArgumentParser()
- parser.add_argument(
- 'config', type=FileType('r'),
+ group = parser.add_mutually_exclusive_group(required=True)
+ group.add_argument(
+ '--config', metavar='FILE', type=FileType('r'),
help='project configuration file (YAML)')
- parser.add_argument('commit', nargs='?', help='commit to update to')
+ group.add_argument(
+ '--data', metavar='YAML',
+ help='bootstrapping data as a YAML string')
+ parser.add_argument('--commit', help='a commit to update to')
args = parser.parse_args()
- config = yaml.safe_load(args.config)
+ if args.data is not None:
+ config = yaml.safe_load(args.data)
+ else:
+ config = yaml.safe_load(args.config)
try:
wrapper(config, args)
except:
--- a/worker-queue.py Fri Aug 05 12:46:39 2016 +0800
+++ b/worker-queue.py Fri Aug 05 15:39:05 2016 +0800
@@ -3,7 +3,7 @@
import logging
import sys
from argparse import ArgumentParser, FileType, SUPPRESS
-from os.path import exists
+from os.path import exists, isfile
from subprocess import check_output, STDOUT
from time import sleep
@@ -17,22 +17,24 @@
def handle(isolation, rconn, change):
payload = json.loads(change)
- config = 'projects/{source}/{repo}.yml'.format(**payload)
+ flags = ['--commit', payload['change']]
- if not exists(config):
- logging.warn("Skipping %s (file doesn't exist: %r)", payload['repo'], config)
- return
+ path = 'projects/{source}/{repo}.yml'.format(**payload)
+ if exists(path) and isfile(path):
+ logging.debug("Using config: %r", path)
+ flags += ['--config', path]
+ else:
+ logging.debug("File %r doesn't exist, trying to bootstrap", path)
+ flags += ['--data', json.dumps(payload)]
- logging.info('Checking %s (payload: %r)', config, payload)
+ logging.info('Checking %s (payload: %r)', payload['repo'], payload)
if isolation == 'none':
- output = check_output([
- sys.executable, '-u', rel('checker.py'), config, payload['change']
- ], stderr=STDOUT)
+ cmd = [sys.executable, '-u', rel('checker.py')]
+ output = check_output(cmd + flags, stderr=STDOUT)
elif isolation == 'docker':
- output = check_output([
- rel('check-in-docker.sh'), config, payload['change']
- ])
- logging.info('Checked %s', config)
+ cmd = [rel('check-in-docker.sh')]
+ output = check_output(cmd + flags)
+ logging.info('Done checking %s', payload['repo'])
payload.update({
'output': output,