forked from jboss-openshift/cct_module
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_docs.py
executable file
·51 lines (41 loc) · 1.58 KB
/
generate_docs.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
#!/usr/bin/env python
import os
import yaml
import sys
from jinja2 import Environment, Template
autogen_warning="""////
AUTOGENERATED FILE - this file was generated via ./gen_template_docs.py.
Changes to .adoc or HTML files may be overwritten! Please change the
generator or the input template (./*.jinja)
////
"""
template = Template(open('./template.adoc.jinja').read())
module_dirs = ['./jboss']
def generate_doc_for_module(module_file):
with open(module_file) as open_file:
data = yaml.load(open_file)
output_file = os.path.join(os.path.dirname(module_file), 'README.adoc')
print ("Generating %s..." % os.path.join(os.path.relpath(output_file, os.getcwd())), os.path.basename(output_file))
with open(output_file, "w") as text_file:
text_file.write(autogen_warning)
text_file.write(template.render(data))
def scan_for_modules(curdir=os.getcwd()):
if not os.path.isdir(curdir):
return
for file in sorted(os.listdir(curdir)):
full_file = os.path.join(curdir, file)
if os.path.isdir(full_file):
scan_for_modules(full_file)
elif os.path.basename(full_file) == 'module.yaml':
generate_doc_for_module(full_file)
# expects to be run from the root of the repository
if __name__ == "__main__":
# the user may specify a particular template to parse,
if 1 < len(sys.argv):
sys.argv.pop(0)
for t in sys.argv:
generate_doc_for_module(t)
# otherwise we'll look for them all (and do an index)
else:
for dir in module_dirs:
scan_for_modules(dir)