-
Notifications
You must be signed in to change notification settings - Fork 11
/
gen-all-repos.py
executable file
·120 lines (95 loc) · 3.27 KB
/
gen-all-repos.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/usr/bin/python3
# pylint: disable=invalid-name
"""
Generate all repo snapshot configuration files based on the definitions list
"""
import argparse
import json
import logging
import subprocess
import sys
import yaml
logger = logging.getLogger(__name__)
def get_parser():
"""
Create argument parser
"""
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument(
'--definitions',
default='repo-definitions.yaml',
help='Path to the definitions list (JSON or YAML)'
)
parser.add_argument(
'--output-dir',
default='./repo',
help='Path to the output directory'
)
parser.add_argument(
'-d', '--debug',
action='store_true',
default=False,
help='Enable debug logging'
)
return parser
# pylint: disable=too-many-locals,too-many-branches
def main():
"""
Main function
"""
parser = get_parser()
args = parser.parse_args()
logging.basicConfig(level=logging.INFO, format='%(message)s')
if args.debug:
logger.setLevel(logging.DEBUG)
logger.info('Reading definitions from %s', args.definitions)
with open(args.definitions, encoding='utf-8') as file:
if args.definitions.endswith('.json'):
definitions = json.load(file)
if args.definitions.endswith('.yaml'):
definitions = yaml.safe_load(file)
else:
raise ValueError('Unknown file type: %s' % args.definitions)
for distro, repos in definitions.items():
for repo in repos:
cmd = [sys.executable, 'gen-repos.py', '--target-dir', args.output_dir]
# COMMON OPTIONS
arch = repo.get('arch', [])
for a in arch:
cmd.extend(['--arch', a])
repo_name = repo.get('repo_name', [])
for n in repo_name:
cmd.extend(['--repo-name', n])
base_url = repo.get('base_url')
if base_url:
cmd.extend(['--base-url', base_url])
base_url_template = repo.get('base_url_template')
if base_url_template:
cmd.extend(['--base-url-template', base_url_template])
snapshot_id_suffix = repo.get('snapshot_id_suffix')
if snapshot_id_suffix:
cmd.extend(['--snapshot-id-suffix', snapshot_id_suffix])
storage = repo.get('storage')
if storage:
cmd.extend(['--storage', storage])
singleton = repo.get('singleton')
if singleton:
cmd.extend(['--singleton', singleton])
# END OF COMMON OPTIONS
cmd.append(distro)
# DISTRO SPECIFIC OPTIONS
if distro != 'eln':
release = repo['release']
cmd.extend(['--release', release])
if distro == 'rhel':
released = repo.get('released', False)
if released:
cmd.append('--released')
elif distro == 'fedora':
stream = repo.get('stream')
if stream:
cmd.extend(['--stream', stream])
logger.debug('Running %s', ' '.join(cmd))
subprocess.check_call(cmd, stdout=sys.stdout)
if __name__ == '__main__':
main()