--- a/checker.py Fri Aug 05 12:46:39 2016 +0800
+++ b/checker.py Fri Aug 05 15:39:05 2016 +0800
+def read_intree_config():
+ fd = open('candolint.yml')
+ print("# C&O couldn't load in-tree config: {}".format(e))
+ return yaml.safe_load(fd)
+ print("# C&O couldn't parse in-tree config: {}".format(e))
print('# C&O task: setup')
+ if args.data is not None:
+ intree = read_intree_config()
+ print('# C&O using in-tree config')
+ print('# C&O in-tree config is required while bootstrapping')
+ print('# C&O not using in-tree config')
for linter in config.get('linters', []):
parser = ArgumentParser()
- 'config', type=FileType('r'),
+ group = parser.add_mutually_exclusive_group(required=True)
+ '--config', metavar='FILE', type=FileType('r'),
help='project configuration file (YAML)')
- parser.add_argument('commit', nargs='?', help='commit to update to')
+ '--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)
+ config = yaml.safe_load(args.config)
--- a/worker-queue.py Fri Aug 05 12:46:39 2016 +0800
+++ b/worker-queue.py Fri Aug 05 15:39:05 2016 +0800
from argparse import ArgumentParser, FileType, SUPPRESS
-from os.path import exists
+from os.path import exists, isfile
from subprocess import check_output, STDOUT
def handle(isolation, rconn, change):
payload = json.loads(change)
- config = 'projects/{source}/{repo}.yml'.format(**payload)
+ flags = ['--commit', payload['change']]
- logging.warn("Skipping %s (file doesn't exist: %r)", payload['repo'], config)
+ path = 'projects/{source}/{repo}.yml'.format(**payload)
+ if exists(path) and isfile(path):
+ logging.debug("Using config: %r", path)
+ flags += ['--config', path]
+ 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)
- output = check_output([
- sys.executable, '-u', rel('checker.py'), config, payload['change']
+ 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'])