Debian Codegraph @

ansible_collections/community/okd/ci/downstream_fragments.py

raw
1 #!/usr/bin/env python
2
3 from __future__ import (absolute_import, division, print_function)
4 __metaclass__ = type
5
6 import json
7 import sys
8 import yaml
9
10 with open("./rendereddocfragments.txt", 'w') as df_fd:
11 with open(sys.argv[2], 'r') as fd:
12 json_docs = json.load(fd)
13
14 # ansible-doc has introduced a 'doc.plugin_name' on branch 'stable-2.17'
15 # This change generated the following sanity tests error.
16 # invalid-documentation: DOCUMENTATION.plugin_name: extra keys not allowed @ data['plugin_name'].
17 # This will be removed from the module documentation
18
19 json_docs[sys.argv[1]]['doc'].pop('plugin_name', '')
20 json_docs[sys.argv[1]]['doc'].pop('collection', '')
21 json_docs[sys.argv[1]]['doc'].pop('filename', '')
22 json_docs[sys.argv[1]]['doc'].pop('has_action', '')
23
24 df_fd.write('DOCUMENTATION = """\n')
25 df_fd.write(yaml.dump(json_docs[sys.argv[1]]['doc'], default_flow_style=False))
26 df_fd.write('"""\n\n')
27
28 df_fd.write('EXAMPLES = """')
29 df_fd.write(json_docs[sys.argv[1]]['examples'])
30 df_fd.write('"""\n\n')
31
32 df_fd.write('RETURN = r"""')
33 data = json_docs[sys.argv[1]]['return']
34 if isinstance(data, dict):
35 df_fd.write(yaml.dump(data, default_flow_style=False))
36 else:
37 df_fd.write(data)
38 df_fd.write('"""\n\n')