forked from rh-openjdk/redhat-openjdk-containers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gendocs.py
executable file
·57 lines (48 loc) · 1.58 KB
/
gendocs.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
#!/usr/bin/env python3
# read in all the module YAML files specified for an image, in order, to
# produce a comprehensive list of configuration environment variables,
# then write them out to something useful
#
# Usage:
# ./gendocs.py name-of-image > output-asciidoc-file
#
# This script reads target/image.yaml, which is produced by a cekit
# build (including --dry-run)
import yaml
import sys
def getvars():
y = yaml.safe_load(open("target/image.yaml","r"))
es = {}
for mobj in y['modules']['install']:
mname = mobj['name']
mf = open("target/image/modules/{}/module.yaml".format(mname))
my = yaml.safe_load(mf)
for h in my['envs']:
es[h['name']] = h
es2 = list(es.values())
es2.sort(key=(lambda h: h['name']))
return es2
def adocpreamble(title):
print("= {}".format(title))
print("Jonathan Dowland <[email protected]>")
print(":toc:")
print()
def adoctable(es,ty,test, field):
print("== {} variables".format(ty))
print(".Table {} variables".format(ty))
print("|===")
print("|Name |{}{} |Description".format(field[0].upper(),field[1:]))
for h in es:
if test(h):
print("|{}".format(h['name']))
print("|`{}`".format(h.get(field,'-')))
print("|{}".format(h.get('description','-')))
print("|===")
print()
def main(title):
es = getvars()
adocpreamble(title)
adoctable(es,"Informational",lambda h: 'value' in h, 'value')
adoctable(es,"Configuration",lambda h: 'value' not in h, 'example')
if __name__ == "__main__":
main(sys.argv[1])