-
Notifications
You must be signed in to change notification settings - Fork 2
/
process
executable file
·289 lines (222 loc) · 8.93 KB
/
process
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
#!/usr/bin/env python3
import argparse
import json
from dataclasses import asdict, dataclass, field
import yaml
# OS-specific packages use this path
DEBIAN_RELEASE = 'bullseye'
PACKAGING_URL = 'https://github.com/theforeman/foreman-packaging'
@dataclass
class Entry:
short_name: str
name: str | None = None
url: str | None = None
github_org: str = 'theforeman'
installer: bool = True
description: str | None = None
@property
def ci_badges(self):
return []
def __post_init__(self):
if not self.name:
self.name = self.short_name
if not self.url:
self.url = f'https://github.com/{self.github_org}/{self.name}'
class PuppetModule(Entry): # pylint: disable=too-few-public-methods
@property
def ci_badges(self):
url = f'{self.url}/actions/workflows/ci.yml'
return [f"[![CI]({url}/badge.svg)]({url})"]
def __post_init__(self):
if not self.name:
self.name = f'puppet-{self.short_name}'
super().__post_init__()
@dataclass
class PackagedEntry(Entry):
rpm: str | None = None
rpm_directory: str = 'plugins'
deb: str | None = None
puppet_acceptance_tests: str | None = None
translations: str | None | bool = None
github_team: str | None = None
satellite: bool | None = False
tests: dict = field(default_factory=dict)
def __post_init__(self):
super().__post_init__()
if self.rpm is True:
self.rpm = f'rubygem-{self.name}'
if self.deb is True:
self.deb = f'ruby-{self.name.replace("_", "-")}'
if self.translations is True:
self.translations = f'https://app.transifex.com/foreman/foreman/{self.name}/'
elif self.translations:
self.translations = f'https://app.transifex.com/foreman/foreman/{self.translations}/'
@property
def github_team_url(self):
if not self.github_team:
return None
org, name = self.github_team.split('/')
return f'https://github.com/orgs/{org}/teams/{name}'
@property
def rpm_url(self):
if not self.rpm:
return None
return f'{PACKAGING_URL}/tree/rpm/develop/packages/{self.rpm_directory}/{self.rpm}'
@property
def deb_url(self):
if not self.deb:
return None
return f'{PACKAGING_URL}/tree/deb/develop/plugins/{self.deb}'
@property
def puppet_module(self):
return None # implemented by a subclass
@property
def puppet_acceptance_tests_url(self):
if not self.puppet_acceptance_tests:
return None
return f'https://github.com/theforeman/{self.puppet_module}/tree/master/spec/acceptance/{self.puppet_acceptance_tests}_spec.rb' # pylint: disable=line-too-long
@property
def github_test_urls(self):
return [(f'GitHub {label}', f'{self.url}/actions/workflows/{test}') for (label, test) in self.tests.get('github', {}).items()]
@property
def jenkins_test_urls(self):
if not self.tests.get('jenkins'):
return []
return [('Jenkins', f'https://ci.theforeman.org/job/{self.tests["jenkins"]}')]
@property
def puppet_test_urls(self):
return [('Puppet', self.puppet_acceptance_tests_url)]
@property
def test_urls(self):
return [(label, url) for (label, url) in (self.puppet_test_urls + self.github_test_urls + self.jenkins_test_urls) if url]
class ForemanPlugin(PackagedEntry):
def __post_init__(self):
if not self.name:
self.name = f'foreman_{self.short_name}'
super().__post_init__()
@property
def puppet_module(self):
return 'puppet-foreman'
class SmartProxyPlugin(PackagedEntry): # pylint: disable=too-few-public-methods
def __post_init__(self):
if not self.name:
self.name = f'smart_proxy_{self.short_name}'
if self.deb is True:
self.deb = self.name.replace("-", "_")
if self.puppet_acceptance_tests is True:
self.puppet_acceptance_tests = self.short_name
super().__post_init__()
@property
def puppet_module(self):
return 'puppet-foreman_proxy'
class HammerPlugin(PackagedEntry):
def __post_init__(self):
if not self.name:
self.name = f'hammer_cli_{self.short_name}'
if not self.url:
# A lot of repos use dashes, unlike the gem name
self.url = f'https://github.com/{self.github_org}/hammer-cli-{self.short_name.replace("_", "-")}'
if self.deb is True:
self.deb = self.name.replace("-", "_")
if self.puppet_acceptance_tests is None:
self.puppet_acceptance_tests = True
super().__post_init__()
@property
def deb_url(self):
if not self.deb:
return None
return f'{PACKAGING_URL}/tree/deb/develop/dependencies/{DEBIAN_RELEASE}/{self.deb}'
@property
def puppet_module(self):
return 'puppet-foreman'
@property
def puppet_acceptance_tests_url(self):
if not self.puppet_acceptance_tests:
return None
return f'https://github.com/theforeman/{self.puppet_module}/tree/master/spec/acceptance/foreman_cli_plugins_spec.rb' # pylint: disable=line-too-long
def load_config(config):
data = yaml.safe_load(config)
data['cli']['plugins'] = [HammerPlugin(short_name=plugin_id, **(plugin or {}))
for plugin_id, plugin in data['cli']['plugins'].items()]
data['foreman']['plugins'] = [ForemanPlugin(short_name=plugin_id, **(plugin or {}))
for plugin_id, plugin in data['foreman']['plugins'].items()]
data['smart_proxy']['modules'] = [SmartProxyPlugin(short_name=module_id, **(module or {}))
for module_id, module in data['smart_proxy']['modules'].items()]
data['smart_proxy']['providers'] = [SmartProxyPlugin(short_name=provider_id, **(provider or {}))
for provider_id, provider in data['smart_proxy']['providers'].items()]
data['installer']['modules'] = [PuppetModule(short_name=module_id, **(module or {}))
for module_id, module in data['installer']['modules'].items()]
data['auxiliary'] = [Entry(short_name=repository_id, **(repository or {}))
for repository_id, repository in data['auxiliary'].items()]
return data
def markdown_link(label, url):
return f'[{label}]({url})' if url else '—'
def markdown_links(urls):
if urls:
return ', '.join([markdown_link(label, url) for (label, url) in urls])
else:
return '—'
def print_markdown_table(entries, i18n=True):
headers = ['Name', 'Team', 'Installer', 'RPM', 'deb', 'Tests']
if i18n:
headers.append('I18n')
rows = []
for entry in entries:
row = [
markdown_link(entry.short_name, entry.url),
markdown_link('team', entry.github_team_url),
"✅" if entry.installer else "❌",
markdown_link('RPM', entry.rpm_url),
markdown_link('deb', entry.deb_url),
markdown_links(entry.test_urls),
]
if i18n:
row.append(markdown_link('i18n', entry.translations))
rows.append(row)
print(f'| {" | ".join(headers)} |')
print(f'|{"|".join("-" * len(headers))}|')
for columns in rows:
print(f'| {" | ".join(columns)} |')
print()
def render_markdown(data):
print('# [CLI](https://github.com/theforeman/hammer-cli)')
print('## Plugins')
print_markdown_table(data['cli']['plugins'])
print('# [Foreman](https://github.com/theforeman/foreman)')
print('## Plugins')
print_markdown_table(data['foreman']['plugins'])
print('# [Foreman Proxy](https://github.com/theforeman/smart-proxy)')
print('## Modules')
print_markdown_table(data['smart_proxy']['modules'], i18n=False)
print('## Providers')
print_markdown_table(data['smart_proxy']['providers'], i18n=False)
print('# [Foreman Installer](https://github.com/theforeman/foreman-installer)')
print('## Modules')
for puppet_module in data['installer']['modules']:
line = ''
for badge in puppet_module.ci_badges:
line += f'{badge} '
line += f'{markdown_link(puppet_module.short_name, puppet_module.url)}'
print(f'* {line}')
print()
print('# Auxiliary repositories')
for repository in data['auxiliary']:
print(f'* [{repository.short_name}]({repository.url}) {repository.description}')
def render_json(data):
def default_func(value):
if isinstance(value, Entry):
return asdict(value)
return None
print(json.dumps(data, default=default_func))
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--filename', '-f', default='config.yaml', type=argparse.FileType())
parser.add_argument('mode', choices=('json', 'markdown'))
args = parser.parse_args()
data = load_config(args.filename)
if args.mode == 'json':
render_json(data)
elif args.mode == 'markdown':
render_markdown(data)
if __name__ == '__main__':
main()