blob: 33d45ca21d51e6b585d711e432d0e18b35929734 [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
17import yaml
18
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. Blairdc4721b2017-03-03 10:01:18 -080042 config = yaml.safe_load(open(config_path))
James E. Blair8a3729d2017-01-26 09:55:33 -080043 for block in config:
44 if 'job' not in block:
45 continue
46 job = block['job']['name']
47 playbook = os.path.join(path, 'playbooks', job + '.yaml')
48 if not os.path.exists(playbook):
49 print(' Creating: %s' % job)
50 make_playbook(playbook)
51
52
53def main():
54 repo_dirs = []
55
56 for root, dirs, files in os.walk(CONFIG_DIR):
57 if 'zuul.yaml' in files or '.zuul.yaml' in files:
58 repo_dirs.append(root)
59
60 for path in repo_dirs:
61 handle_repo(path)
62
63
64if __name__ == '__main__':
65 main()