2016-06-15 23:01:55 +02:00
|
|
|
#!/usr/bin/env python
|
2016-02-25 22:41:50 +01:00
|
|
|
|
|
|
|
import optparse
|
|
|
|
from jinja2 import Environment, FileSystemLoader
|
|
|
|
|
|
|
|
from ansible.playbook import Play
|
|
|
|
from ansible.playbook.block import Block
|
|
|
|
from ansible.playbook.role import Role
|
|
|
|
from ansible.playbook.task import Task
|
|
|
|
|
|
|
|
template_file = 'playbooks_directives.rst.j2'
|
|
|
|
oblist = {}
|
2016-02-26 22:18:55 +01:00
|
|
|
clist = []
|
|
|
|
class_list = [ Play, Role, Block, Task ]
|
2016-02-25 22:41:50 +01:00
|
|
|
|
|
|
|
p = optparse.OptionParser(
|
|
|
|
version='%prog 1.0',
|
|
|
|
usage='usage: %prog [options]',
|
|
|
|
description='Generate module documentation from metadata',
|
|
|
|
)
|
|
|
|
p.add_option("-T", "--template-dir", action="store", dest="template_dir", default="hacking/templates", help="directory containing Jinja2 templates")
|
|
|
|
p.add_option("-o", "--output-dir", action="store", dest="output_dir", default='/tmp/', help="Output directory for rst files")
|
|
|
|
|
|
|
|
(options, args) = p.parse_args()
|
|
|
|
|
2016-02-26 22:27:10 +01:00
|
|
|
for aclass in class_list:
|
2016-02-26 22:18:55 +01:00
|
|
|
aobj = aclass()
|
|
|
|
name = type(aobj).__name__
|
|
|
|
|
|
|
|
# build ordered list to loop over and dict with attributes
|
|
|
|
clist.append(name)
|
2016-03-10 07:00:33 +01:00
|
|
|
oblist[name] = {x: aobj.__dict__['_attributes'][x] for x in aobj.__dict__['_attributes'] if 'private' not in x or not x.private}
|
2016-02-26 22:18:55 +01:00
|
|
|
|
|
|
|
# loop is really with_ for users
|
2016-03-10 07:00:33 +01:00
|
|
|
if name == 'Task':
|
2016-02-26 22:18:55 +01:00
|
|
|
oblist[name]['with_<lookup_plugin>'] = True
|
|
|
|
|
|
|
|
# local_action is implicit with action
|
|
|
|
if 'action' in oblist[name]:
|
|
|
|
oblist[name]['local_action'] = True
|
|
|
|
|
2016-02-25 22:41:50 +01:00
|
|
|
env = Environment(loader=FileSystemLoader(options.template_dir), trim_blocks=True,)
|
|
|
|
template = env.get_template(template_file)
|
|
|
|
outputname = options.output_dir + template_file.replace('.j2','')
|
2016-02-26 22:18:55 +01:00
|
|
|
tempvars = { 'oblist': oblist, 'clist': clist }
|
2016-02-25 22:41:50 +01:00
|
|
|
|
|
|
|
with open( outputname, 'w') as f:
|
|
|
|
f.write(template.render(tempvars))
|