-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathprocess
More file actions
executable file
·116 lines (89 loc) · 3.32 KB
/
process
File metadata and controls
executable file
·116 lines (89 loc) · 3.32 KB
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
#!/usr/bin/env python3
import argparse
import json
from dataclasses import asdict
from fpo import load_config, Entry
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 issues_link(issues_url):
if 'github.com' in issues_url:
issues_label = 'GitHub'
elif 'projects.theforeman.org' in issues_url:
issues_label = 'Redmine'
else:
issues_label = 'Issues'
return markdown_link(issues_label, issues_url)
def print_markdown_table(entries, i18n=True):
headers = ['Name', 'Team', 'Installer', 'RPM', 'deb', 'Tests', 'Issues']
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),
issues_link(entry.issues_url),
]
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('# Libraries')
print_markdown_table(data['libraries'], i18n=False)
print('# Client')
print_markdown_table(data['client'], i18n=False)
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()