blob: 93c37bc815faaadd8afcd6b233f4cbaa4834fca6 [file] [log] [blame]
James E. Blair8a3729d2017-01-26 09:55:33 -08001#!/usr/bin/env python
2
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14
15import os
16
Clint Byrum88fdfde2017-03-28 16:22:42 -070017from zuul.lib import yamlutil as yaml
James E. Blair8a3729d2017-01-26 09:55:33 -080018
19FIXTURE_DIR = os.path.join(os.path.dirname(__file__),
20 'fixtures')
21CONFIG_DIR = os.path.join(FIXTURE_DIR, 'config')
22
23
24def make_playbook(path):
25 d = os.path.dirname(path)
26 try:
27 os.makedirs(d)
28 except OSError:
29 pass
30 with open(path, 'w') as f:
31 f.write('- hosts: all\n')
32 f.write(' tasks: []\n')
33
34
35def handle_repo(path):
36 print('Repo: %s' % path)
37 config_path = None
38 for fn in ['zuul.yaml', '.zuul.yaml']:
39 if os.path.exists(os.path.join(path, fn)):
40 config_path = os.path.join(path, fn)
41 break
James E. Blairb9c0d772017-03-03 14:34:49 -080042 try:
43 config = yaml.safe_load(open(config_path))
44 except Exception:
45 print(" Has yaml errors")
46 return
James E. Blair8a3729d2017-01-26 09:55:33 -080047 for block in config:
48 if 'job' not in block:
49 continue
50 job = block['job']['name']
51 playbook = os.path.join(path, 'playbooks', job + '.yaml')
52 if not os.path.exists(playbook):
53 print(' Creating: %s' % job)
54 make_playbook(playbook)
55
56
57def main():
58 repo_dirs = []
59
60 for root, dirs, files in os.walk(CONFIG_DIR):
61 if 'zuul.yaml' in files or '.zuul.yaml' in files:
62 repo_dirs.append(root)
63
64 for path in repo_dirs:
65 handle_repo(path)
66
67
68if __name__ == '__main__':
69 main()