mirror of https://github.com/ansible/ansible.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
2.3 KiB
Python
70 lines
2.3 KiB
Python
9 years ago
|
#!/usr/bin/env python
|
||
9 years ago
|
|
||
|
import optparse
|
||
8 years ago
|
import yaml
|
||
|
|
||
9 years ago
|
from jinja2 import Environment, FileSystemLoader
|
||
|
|
||
8 years ago
|
from ansible.playbook import Play
|
||
|
from ansible.playbook.block import Block
|
||
|
from ansible.playbook.role import Role
|
||
|
from ansible.playbook.task import Task
|
||
9 years ago
|
|
||
8 years ago
|
template_file = 'playbooks_keywords.rst.j2'
|
||
9 years ago
|
oblist = {}
|
||
9 years ago
|
clist = []
|
||
|
class_list = [ Play, Role, Block, Task ]
|
||
9 years ago
|
|
||
|
p = optparse.OptionParser(
|
||
|
version='%prog 1.0',
|
||
|
usage='usage: %prog [options]',
|
||
|
description='Generate module documentation from metadata',
|
||
|
)
|
||
8 years ago
|
p.add_option("-T", "--template-dir", action="store", dest="template_dir", default="../templates", help="directory containing Jinja2 templates")
|
||
9 years ago
|
p.add_option("-o", "--output-dir", action="store", dest="output_dir", default='/tmp/', help="Output directory for rst files")
|
||
8 years ago
|
p.add_option("-d", "--docs-source", action="store", dest="docs", default=None, help="Source for attribute docs")
|
||
9 years ago
|
|
||
|
(options, args) = p.parse_args()
|
||
|
|
||
9 years ago
|
for aclass in class_list:
|
||
9 years ago
|
aobj = aclass()
|
||
|
name = type(aobj).__name__
|
||
|
|
||
8 years ago
|
if options.docs:
|
||
|
with open(options.docs) as f:
|
||
|
docs = yaml.safe_load(f)
|
||
|
else:
|
||
|
docs = {}
|
||
|
|
||
9 years ago
|
# build ordered list to loop over and dict with attributes
|
||
|
clist.append(name)
|
||
8 years ago
|
oblist[name] = dict((x, aobj.__dict__['_attributes'][x]) for x in aobj.__dict__['_attributes'] if 'private' not in x or not x.private)
|
||
9 years ago
|
|
||
8 years ago
|
# pick up docs if they exist
|
||
|
for a in oblist[name]:
|
||
|
if a in docs:
|
||
|
oblist[name][a] = docs[a]
|
||
|
else:
|
||
|
oblist[name][a] = ' UNDOCUMENTED!! '
|
||
|
|
||
9 years ago
|
# loop is really with_ for users
|
||
9 years ago
|
if name == 'Task':
|
||
8 years ago
|
oblist[name]['with_<lookup_plugin>'] = 'with_ is how loops are defined, it can use any available lookup plugin to generate the item list'
|
||
9 years ago
|
|
||
|
# local_action is implicit with action
|
||
|
if 'action' in oblist[name]:
|
||
8 years ago
|
oblist[name]['local_action'] = 'Same as action but also implies ``delegate_to: localhost``'
|
||
|
|
||
|
# remove unusable (used to be private?)
|
||
|
for nouse in ('loop', 'loop_args'):
|
||
|
if nouse in oblist[name]:
|
||
|
del oblist[name][nouse]
|
||
9 years ago
|
|
||
9 years ago
|
env = Environment(loader=FileSystemLoader(options.template_dir), trim_blocks=True,)
|
||
|
template = env.get_template(template_file)
|
||
|
outputname = options.output_dir + template_file.replace('.j2','')
|
||
9 years ago
|
tempvars = { 'oblist': oblist, 'clist': clist }
|
||
9 years ago
|
|
||
|
with open( outputname, 'w') as f:
|
||
|
f.write(template.render(tempvars))
|