2012-09-26 20:41:44 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# (c) 2012, Jan-Piet Mens <jpmens () gmail.com>
|
2014-09-26 23:10:13 +02:00
|
|
|
# (c) 2012-2014, Michael DeHaan <michael@ansible.com> and others
|
2012-09-26 20:41:44 +02:00
|
|
|
#
|
|
|
|
# This file is part of Ansible
|
|
|
|
#
|
|
|
|
# Ansible is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# Ansible is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
|
|
|
|
import os
|
2013-04-28 21:03:45 +02:00
|
|
|
import glob
|
2012-09-26 20:41:44 +02:00
|
|
|
import sys
|
|
|
|
import yaml
|
|
|
|
import codecs
|
|
|
|
import json
|
|
|
|
import ast
|
|
|
|
import re
|
2012-10-11 18:11:33 +02:00
|
|
|
import optparse
|
2012-09-26 20:41:44 +02:00
|
|
|
import time
|
|
|
|
import datetime
|
|
|
|
import subprocess
|
2013-06-14 20:27:59 +02:00
|
|
|
import cgi
|
2015-07-17 16:00:02 +02:00
|
|
|
import warnings
|
2013-12-25 18:35:41 +01:00
|
|
|
from jinja2 import Environment, FileSystemLoader
|
|
|
|
|
2015-05-23 15:42:17 +02:00
|
|
|
from ansible.utils import module_docs
|
|
|
|
from ansible.utils.vars import merge_hash
|
2012-10-01 03:10:07 +02:00
|
|
|
|
2013-12-25 18:35:41 +01:00
|
|
|
#####################################################################################
|
|
|
|
# constants and paths
|
|
|
|
|
2013-11-28 03:34:00 +01:00
|
|
|
# if a module is added in a version of Ansible older than this, don't print the version added information
|
|
|
|
# in the module documentation because everyone is assumed to be running something newer than this already.
|
2015-07-17 16:00:02 +02:00
|
|
|
TO_OLD_TO_BE_NOTABLE = 1.3
|
2013-11-28 03:34:00 +01:00
|
|
|
|
2012-10-13 01:21:41 +02:00
|
|
|
# Get parent directory of the directory this script lives in
|
|
|
|
MODULEDIR=os.path.abspath(os.path.join(
|
2014-09-26 23:10:13 +02:00
|
|
|
os.path.dirname(os.path.realpath(__file__)), os.pardir, 'lib', 'ansible', 'modules'
|
2013-12-25 17:45:27 +01:00
|
|
|
))
|
|
|
|
|
|
|
|
# The name of the DOCUMENTATION template
|
2012-10-13 01:21:41 +02:00
|
|
|
EXAMPLE_YAML=os.path.abspath(os.path.join(
|
2013-12-25 17:45:27 +01:00
|
|
|
os.path.dirname(os.path.realpath(__file__)), os.pardir, 'examples', 'DOCUMENTATION.yml'
|
|
|
|
))
|
2012-09-26 20:41:44 +02:00
|
|
|
|
|
|
|
_ITALIC = re.compile(r"I\(([^)]+)\)")
|
|
|
|
_BOLD = re.compile(r"B\(([^)]+)\)")
|
|
|
|
_MODULE = re.compile(r"M\(([^)]+)\)")
|
|
|
|
_URL = re.compile(r"U\(([^)]+)\)")
|
|
|
|
_CONST = re.compile(r"C\(([^)]+)\)")
|
|
|
|
|
2014-10-31 19:20:26 +01:00
|
|
|
DEPRECATED = " (D)"
|
|
|
|
NOTCORE = " (E)"
|
2013-12-25 18:35:41 +01:00
|
|
|
#####################################################################################
|
2012-09-26 20:41:44 +02:00
|
|
|
|
|
|
|
def rst_ify(text):
|
2013-12-25 18:35:41 +01:00
|
|
|
''' convert symbols like I(this is in italics) to valid restructured text '''
|
2012-09-26 20:41:44 +02:00
|
|
|
|
|
|
|
t = _ITALIC.sub(r'*' + r"\1" + r"*", text)
|
|
|
|
t = _BOLD.sub(r'**' + r"\1" + r"**", t)
|
2015-05-05 22:48:04 +02:00
|
|
|
t = _MODULE.sub(r':ref:`' + r"\1 <\1>" + r"`", t)
|
2012-09-26 20:41:44 +02:00
|
|
|
t = _URL.sub(r"\1", t)
|
2012-11-21 18:49:30 +01:00
|
|
|
t = _CONST.sub(r'``' + r"\1" + r"``", t)
|
2012-09-26 20:41:44 +02:00
|
|
|
|
|
|
|
return t
|
|
|
|
|
2013-12-25 18:35:41 +01:00
|
|
|
#####################################################################################
|
2013-06-14 20:27:59 +02:00
|
|
|
|
2013-12-25 18:35:41 +01:00
|
|
|
def html_ify(text):
|
|
|
|
''' convert symbols like I(this is in italics) to valid HTML '''
|
2012-10-18 07:34:17 +02:00
|
|
|
|
2013-06-14 20:27:59 +02:00
|
|
|
t = cgi.escape(text)
|
2013-12-25 18:35:41 +01:00
|
|
|
t = _ITALIC.sub("<em>" + r"\1" + "</em>", t)
|
|
|
|
t = _BOLD.sub("<b>" + r"\1" + "</b>", t)
|
|
|
|
t = _MODULE.sub("<span class='module'>" + r"\1" + "</span>", t)
|
|
|
|
t = _URL.sub("<a href='" + r"\1" + "'>" + r"\1" + "</a>", t)
|
|
|
|
t = _CONST.sub("<code>" + r"\1" + "</code>", t)
|
2012-10-18 07:34:17 +02:00
|
|
|
|
|
|
|
return t
|
|
|
|
|
2013-12-25 18:35:41 +01:00
|
|
|
|
|
|
|
#####################################################################################
|
|
|
|
|
2012-09-26 20:41:44 +02:00
|
|
|
def rst_fmt(text, fmt):
|
2013-12-25 18:35:41 +01:00
|
|
|
''' helper for Jinja2 to do format strings '''
|
|
|
|
|
2012-09-26 20:41:44 +02:00
|
|
|
return fmt % (text)
|
|
|
|
|
2013-12-25 18:35:41 +01:00
|
|
|
#####################################################################################
|
|
|
|
|
2012-09-26 20:41:44 +02:00
|
|
|
def rst_xline(width, char="="):
|
2013-12-25 18:35:41 +01:00
|
|
|
''' return a restructured text line of a given length '''
|
|
|
|
|
2012-09-26 20:41:44 +02:00
|
|
|
return char * width
|
|
|
|
|
2013-12-25 18:35:41 +01:00
|
|
|
#####################################################################################
|
2012-09-26 20:41:44 +02:00
|
|
|
|
2013-12-25 19:23:58 +01:00
|
|
|
def write_data(text, options, outputname, module):
|
2013-12-25 18:35:41 +01:00
|
|
|
''' dumps module output to a file or the screen, as requested '''
|
|
|
|
|
2012-10-11 18:11:33 +02:00
|
|
|
if options.output_dir is not None:
|
2014-09-26 23:10:13 +02:00
|
|
|
fname = os.path.join(options.output_dir, outputname % module)
|
|
|
|
fname = fname.replace(".py","")
|
|
|
|
f = open(fname, 'w')
|
2013-03-17 18:33:43 +01:00
|
|
|
f.write(text.encode('utf-8'))
|
2012-10-09 22:04:55 +02:00
|
|
|
f.close()
|
|
|
|
else:
|
|
|
|
print text
|
|
|
|
|
2013-12-25 18:35:41 +01:00
|
|
|
#####################################################################################
|
|
|
|
|
2014-09-26 23:10:13 +02:00
|
|
|
|
2014-11-04 04:02:13 +01:00
|
|
|
def list_modules(module_dir, depth=0):
|
2013-12-25 18:35:41 +01:00
|
|
|
''' returns a hash of categories, each category being a hash of module names to file paths '''
|
|
|
|
|
2014-11-04 04:02:13 +01:00
|
|
|
categories = dict(all=dict(),_aliases=dict())
|
|
|
|
if depth <= 3: # limit # of subdirs
|
2014-11-03 14:15:26 +01:00
|
|
|
|
2014-11-04 04:02:13 +01:00
|
|
|
files = glob.glob("%s/*" % module_dir)
|
|
|
|
for d in files:
|
|
|
|
|
|
|
|
category = os.path.splitext(os.path.basename(d))[0]
|
|
|
|
if os.path.isdir(d):
|
|
|
|
|
|
|
|
res = list_modules(d, depth + 1)
|
|
|
|
for key in res.keys():
|
|
|
|
if key in categories:
|
2015-05-23 15:42:17 +02:00
|
|
|
categories[key] = merge_hash(categories[key], res[key])
|
2014-11-04 04:02:13 +01:00
|
|
|
res.pop(key, None)
|
2014-10-28 16:36:31 +01:00
|
|
|
|
2014-11-04 04:02:13 +01:00
|
|
|
if depth < 2:
|
|
|
|
categories.update(res)
|
|
|
|
else:
|
|
|
|
category = module_dir.split("/")[-1]
|
|
|
|
if not category in categories:
|
|
|
|
categories[category] = res
|
|
|
|
else:
|
|
|
|
categories[category].update(res)
|
|
|
|
else:
|
|
|
|
module = category
|
|
|
|
category = os.path.basename(module_dir)
|
|
|
|
if not d.endswith(".py") or d.endswith('__init__.py'):
|
2014-06-18 22:21:52 +02:00
|
|
|
# windows powershell modules have documentation stubs in python docstring
|
|
|
|
# format (they are not executed) so skip the ps1 format files
|
|
|
|
continue
|
2014-11-04 04:02:13 +01:00
|
|
|
elif module.startswith("_") and os.path.islink(d):
|
|
|
|
source = os.path.splitext(os.path.basename(os.path.realpath(d)))[0]
|
|
|
|
module = module.replace("_","",1)
|
|
|
|
if not d in categories['_aliases']:
|
|
|
|
categories['_aliases'][source] = [module]
|
|
|
|
else:
|
|
|
|
categories['_aliases'][source].update(module)
|
2014-10-30 16:26:43 +01:00
|
|
|
continue
|
2014-06-18 22:21:52 +02:00
|
|
|
|
2013-04-28 21:03:45 +02:00
|
|
|
if not category in categories:
|
|
|
|
categories[category] = {}
|
2014-11-04 04:02:13 +01:00
|
|
|
categories[category][module] = d
|
|
|
|
categories['all'][module] = d
|
2014-10-31 19:20:26 +01:00
|
|
|
|
2013-04-28 21:03:45 +02:00
|
|
|
return categories
|
2012-10-09 22:04:55 +02:00
|
|
|
|
2013-12-25 18:35:41 +01:00
|
|
|
#####################################################################################
|
|
|
|
|
|
|
|
def generate_parser():
|
|
|
|
''' generate an optparse parser '''
|
2012-09-26 20:41:44 +02:00
|
|
|
|
2012-10-11 18:11:33 +02:00
|
|
|
p = optparse.OptionParser(
|
|
|
|
version='%prog 1.0',
|
|
|
|
usage='usage: %prog [options] arg1 arg2',
|
2013-12-25 18:35:41 +01:00
|
|
|
description='Generate module documentation from metadata',
|
2012-10-11 18:11:33 +02:00
|
|
|
)
|
|
|
|
|
2013-12-25 18:35:41 +01:00
|
|
|
p.add_option("-A", "--ansible-version", action="store", dest="ansible_version", default="unknown", help="Ansible version number")
|
|
|
|
p.add_option("-M", "--module-dir", action="store", dest="module_dir", default=MODULEDIR, help="Ansible library path")
|
|
|
|
p.add_option("-T", "--template-dir", action="store", dest="template_dir", default="hacking/templates", help="directory containing Jinja2 templates")
|
2014-02-22 15:51:59 +01:00
|
|
|
p.add_option("-t", "--type", action='store', dest='type', choices=['rst'], default='rst', help="Document type")
|
2013-12-25 19:38:40 +01:00
|
|
|
p.add_option("-v", "--verbose", action='store_true', default=False, help="Verbose")
|
2013-12-25 18:35:41 +01:00
|
|
|
p.add_option("-o", "--output-dir", action="store", dest="output_dir", default=None, help="Output directory for module files")
|
|
|
|
p.add_option("-I", "--includes-file", action="store", dest="includes_file", default=None, help="Create a file containing list of processed modules")
|
2012-10-13 01:21:41 +02:00
|
|
|
p.add_option('-V', action='version', help='Show version number and exit')
|
2013-12-25 18:35:41 +01:00
|
|
|
return p
|
2012-10-11 18:11:33 +02:00
|
|
|
|
2013-12-25 18:35:41 +01:00
|
|
|
#####################################################################################
|
2012-09-26 20:41:44 +02:00
|
|
|
|
2013-12-25 18:35:41 +01:00
|
|
|
def jinja2_environment(template_dir, typ):
|
2012-10-13 01:21:41 +02:00
|
|
|
|
2013-12-25 18:35:41 +01:00
|
|
|
env = Environment(loader=FileSystemLoader(template_dir),
|
2012-09-28 09:59:43 +02:00
|
|
|
variable_start_string="@{",
|
|
|
|
variable_end_string="}@",
|
2012-09-30 15:06:18 +02:00
|
|
|
trim_blocks=True,
|
2012-11-03 23:52:59 +01:00
|
|
|
)
|
2012-09-28 09:59:43 +02:00
|
|
|
env.globals['xline'] = rst_xline
|
2012-09-28 03:06:31 +02:00
|
|
|
|
2013-12-25 18:35:41 +01:00
|
|
|
if typ == 'rst':
|
2013-12-25 17:44:01 +01:00
|
|
|
env.filters['convert_symbols_to_format'] = rst_ify
|
2012-09-28 03:06:31 +02:00
|
|
|
env.filters['html_ify'] = html_ify
|
2012-09-26 20:41:44 +02:00
|
|
|
env.filters['fmt'] = rst_fmt
|
|
|
|
env.filters['xline'] = rst_xline
|
|
|
|
template = env.get_template('rst.j2')
|
2013-12-25 19:23:58 +01:00
|
|
|
outputname = "%s_module.rst"
|
2013-12-25 18:35:41 +01:00
|
|
|
else:
|
|
|
|
raise Exception("unknown module format type: %s" % typ)
|
2012-09-30 19:07:40 +02:00
|
|
|
|
2013-12-25 18:35:41 +01:00
|
|
|
return env, template, outputname
|
2012-09-26 20:41:44 +02:00
|
|
|
|
2013-12-25 18:35:41 +01:00
|
|
|
#####################################################################################
|
2015-07-17 16:00:02 +02:00
|
|
|
def too_old(added):
|
|
|
|
if not added:
|
|
|
|
return False
|
|
|
|
try:
|
|
|
|
added_tokens = str(added).split(".")
|
|
|
|
readded = added_tokens[0] + "." + added_tokens[1]
|
|
|
|
added_float = float(readded)
|
|
|
|
except ValueError as e:
|
|
|
|
warnings.warn("Could not parse %s: %s" % (added, str(e)))
|
|
|
|
return False
|
|
|
|
return (added_float < TO_OLD_TO_BE_NOTABLE)
|
2013-04-28 21:03:45 +02:00
|
|
|
|
2014-11-04 04:02:13 +01:00
|
|
|
def process_module(module, options, env, template, outputname, module_map, aliases):
|
2013-12-25 18:35:41 +01:00
|
|
|
|
|
|
|
fname = module_map[module]
|
2014-11-04 04:02:13 +01:00
|
|
|
if isinstance(fname, dict):
|
|
|
|
return "SKIPPED"
|
|
|
|
|
2014-10-30 18:29:54 +01:00
|
|
|
basename = os.path.basename(fname)
|
|
|
|
deprecated = False
|
2013-12-25 18:35:41 +01:00
|
|
|
|
|
|
|
# ignore files with extensions
|
2014-10-30 18:29:54 +01:00
|
|
|
if not basename.endswith(".py"):
|
2013-12-25 18:35:41 +01:00
|
|
|
return
|
2014-10-31 19:20:26 +01:00
|
|
|
elif module.startswith("_"):
|
|
|
|
if os.path.islink(fname):
|
|
|
|
return # ignore, its an alias
|
2014-10-30 18:29:54 +01:00
|
|
|
deprecated = True
|
2014-10-31 19:20:26 +01:00
|
|
|
module = module.replace("_","",1)
|
|
|
|
|
|
|
|
print "rendering: %s" % module
|
2013-12-25 18:35:41 +01:00
|
|
|
|
|
|
|
# use ansible core library to parse out doc metadata YAML and plaintext examples
|
2015-05-23 15:42:17 +02:00
|
|
|
doc, examples, returndocs = module_docs.get_docstring(fname, verbose=options.verbose)
|
2013-12-25 18:35:41 +01:00
|
|
|
|
|
|
|
# crash if module is missing documentation and not explicitly hidden from docs index
|
|
|
|
if doc is None:
|
2015-05-23 15:42:17 +02:00
|
|
|
if module in module_docs.BLACKLIST_MODULES:
|
2014-10-31 19:20:26 +01:00
|
|
|
return "SKIPPED"
|
|
|
|
else:
|
|
|
|
sys.stderr.write("*** ERROR: MODULE MISSING DOCUMENTATION: %s, %s ***\n" % (fname, module))
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
if deprecated and 'deprecated' not in doc:
|
|
|
|
sys.stderr.write("*** ERROR: DEPRECATED MODULE MISSING 'deprecated' DOCUMENTATION: %s, %s ***\n" % (fname, module))
|
|
|
|
sys.exit(1)
|
2013-12-25 18:35:41 +01:00
|
|
|
|
2014-09-27 00:23:57 +02:00
|
|
|
if "/core/" in fname:
|
2014-09-26 23:52:50 +02:00
|
|
|
doc['core'] = True
|
|
|
|
else:
|
|
|
|
doc['core'] = False
|
|
|
|
|
2014-11-04 04:02:13 +01:00
|
|
|
if module in aliases:
|
|
|
|
doc['aliases'] = aliases[module]
|
2014-09-26 23:52:50 +02:00
|
|
|
|
2013-12-25 18:35:41 +01:00
|
|
|
all_keys = []
|
2013-04-28 21:03:45 +02:00
|
|
|
|
2013-12-25 18:35:41 +01:00
|
|
|
if not 'version_added' in doc:
|
|
|
|
sys.stderr.write("*** ERROR: missing version_added in: %s ***\n" % module)
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
added = 0
|
|
|
|
if doc['version_added'] == 'historical':
|
|
|
|
del doc['version_added']
|
|
|
|
else:
|
|
|
|
added = doc['version_added']
|
|
|
|
|
|
|
|
# don't show version added information if it's too old to be called out
|
2015-07-17 16:00:02 +02:00
|
|
|
if too_old(added):
|
|
|
|
del doc['version_added']
|
2013-12-25 18:35:41 +01:00
|
|
|
|
2015-05-23 15:42:17 +02:00
|
|
|
if 'options' in doc:
|
|
|
|
for (k,v) in doc['options'].iteritems():
|
2015-07-17 16:00:02 +02:00
|
|
|
# don't show version added information if it's too old to be called out
|
|
|
|
if 'version_added' in doc['options'][k] and too_old(doc['options'][k]['version_added']):
|
|
|
|
del doc['options'][k]['version_added']
|
2015-05-23 15:42:17 +02:00
|
|
|
all_keys.append(k)
|
2014-10-31 19:20:26 +01:00
|
|
|
|
2013-12-25 18:35:41 +01:00
|
|
|
all_keys = sorted(all_keys)
|
|
|
|
|
2014-10-31 19:20:26 +01:00
|
|
|
doc['option_keys'] = all_keys
|
2013-12-25 18:35:41 +01:00
|
|
|
doc['filename'] = fname
|
|
|
|
doc['docuri'] = doc['module'].replace('_', '-')
|
|
|
|
doc['now_date'] = datetime.date.today().strftime('%Y-%m-%d')
|
|
|
|
doc['ansible_version'] = options.ansible_version
|
|
|
|
doc['plainexamples'] = examples #plain text
|
2015-03-20 21:54:22 +01:00
|
|
|
if returndocs:
|
|
|
|
doc['returndocs'] = yaml.safe_load(returndocs)
|
|
|
|
else:
|
|
|
|
doc['returndocs'] = None
|
2013-12-25 18:35:41 +01:00
|
|
|
|
|
|
|
# here is where we build the table of contents...
|
|
|
|
|
|
|
|
text = template.render(doc)
|
2013-12-25 19:23:58 +01:00
|
|
|
write_data(text, options, outputname, module)
|
2014-10-31 19:20:26 +01:00
|
|
|
return doc['short_description']
|
2013-04-28 21:03:45 +02:00
|
|
|
|
2013-12-25 18:35:41 +01:00
|
|
|
#####################################################################################
|
2013-08-06 16:53:56 +02:00
|
|
|
|
2014-11-04 04:02:13 +01:00
|
|
|
def print_modules(module, category_file, deprecated, core, options, env, template, outputname, module_map, aliases):
|
|
|
|
modstring = module
|
|
|
|
modname = module
|
|
|
|
if module in deprecated:
|
|
|
|
modstring = modstring + DEPRECATED
|
|
|
|
modname = "_" + module
|
|
|
|
elif module not in core:
|
|
|
|
modstring = modstring + NOTCORE
|
|
|
|
|
|
|
|
result = process_module(modname, options, env, template, outputname, module_map, aliases)
|
|
|
|
|
|
|
|
if result != "SKIPPED":
|
|
|
|
category_file.write(" %s - %s <%s_module>\n" % (modstring, result, module))
|
|
|
|
|
2013-12-25 18:35:41 +01:00
|
|
|
def process_category(category, categories, options, env, template, outputname):
|
2013-08-06 16:53:56 +02:00
|
|
|
|
2013-12-25 18:35:41 +01:00
|
|
|
module_map = categories[category]
|
2013-04-28 21:03:45 +02:00
|
|
|
|
2014-11-04 04:02:13 +01:00
|
|
|
aliases = {}
|
|
|
|
if '_aliases' in categories:
|
|
|
|
aliases = categories['_aliases']
|
|
|
|
|
2013-12-25 19:23:58 +01:00
|
|
|
category_file_path = os.path.join(options.output_dir, "list_of_%s_modules.rst" % category)
|
|
|
|
category_file = open(category_file_path, "w")
|
2013-12-25 19:38:40 +01:00
|
|
|
print "*** recording category %s in %s ***" % (category, category_file_path)
|
2013-12-25 19:23:58 +01:00
|
|
|
|
2015-07-17 16:00:02 +02:00
|
|
|
# start a new category file
|
2013-04-28 21:03:45 +02:00
|
|
|
|
2013-12-25 18:35:41 +01:00
|
|
|
category = category.replace("_"," ")
|
|
|
|
category = category.title()
|
|
|
|
|
2014-10-31 19:20:26 +01:00
|
|
|
modules = []
|
|
|
|
deprecated = []
|
|
|
|
core = []
|
|
|
|
for module in module_map.keys():
|
|
|
|
|
2014-11-04 05:14:22 +01:00
|
|
|
if isinstance(module_map[module], dict):
|
|
|
|
for mod in module_map[module].keys():
|
|
|
|
if mod.startswith("_"):
|
|
|
|
mod = mod.replace("_","",1)
|
|
|
|
deprecated.append(mod)
|
|
|
|
elif '/core/' in module_map[module][mod]:
|
|
|
|
core.append(mod)
|
|
|
|
else:
|
|
|
|
if module.startswith("_"):
|
|
|
|
module = module.replace("_","",1)
|
|
|
|
deprecated.append(module)
|
|
|
|
elif '/core/' in module_map[module]:
|
|
|
|
core.append(module)
|
2014-10-31 19:20:26 +01:00
|
|
|
modules.append(module)
|
|
|
|
|
2013-12-25 18:35:41 +01:00
|
|
|
modules.sort()
|
|
|
|
|
2013-12-25 19:23:58 +01:00
|
|
|
category_header = "%s Modules" % (category.title())
|
|
|
|
underscores = "`" * len(category_header)
|
|
|
|
|
2013-12-25 20:05:01 +01:00
|
|
|
category_file.write("""\
|
|
|
|
%s
|
|
|
|
%s
|
|
|
|
|
2014-10-31 19:20:26 +01:00
|
|
|
.. toctree:: :maxdepth: 1
|
2013-12-25 20:05:01 +01:00
|
|
|
|
|
|
|
""" % (category_header, underscores))
|
2014-11-04 04:02:13 +01:00
|
|
|
sections = []
|
2013-12-25 18:35:41 +01:00
|
|
|
for module in modules:
|
2014-11-04 04:02:13 +01:00
|
|
|
if module in module_map and isinstance(module_map[module], dict):
|
|
|
|
sections.append(module)
|
|
|
|
continue
|
|
|
|
else:
|
|
|
|
print_modules(module, category_file, deprecated, core, options, env, template, outputname, module_map, aliases)
|
2013-12-25 19:23:58 +01:00
|
|
|
|
2014-11-04 05:14:22 +01:00
|
|
|
sections.sort()
|
2014-11-04 04:02:13 +01:00
|
|
|
for section in sections:
|
2014-11-05 00:14:30 +01:00
|
|
|
category_file.write("\n%s\n%s\n\n" % (section.replace("_"," ").title(),'-' * len(section)))
|
2014-11-04 04:02:13 +01:00
|
|
|
category_file.write(".. toctree:: :maxdepth: 1\n\n")
|
2014-10-31 19:20:26 +01:00
|
|
|
|
2014-11-04 05:14:22 +01:00
|
|
|
section_modules = module_map[section].keys()
|
|
|
|
section_modules.sort()
|
|
|
|
#for module in module_map[section]:
|
|
|
|
for module in section_modules:
|
2014-11-04 04:02:13 +01:00
|
|
|
print_modules(module, category_file, deprecated, core, options, env, template, outputname, module_map[section], aliases)
|
2013-12-25 19:23:58 +01:00
|
|
|
|
2014-10-31 20:06:00 +01:00
|
|
|
category_file.write("""\n\n
|
|
|
|
.. note::
|
2014-11-04 23:38:02 +01:00
|
|
|
- %s: This marks a module as deprecated, which means a module is kept for backwards compatibility but usage is discouraged. The module documentation details page may explain more about this rationale.
|
2014-11-29 06:29:09 +01:00
|
|
|
- %s: This marks a module as 'extras', which means it ships with ansible but may be a newer module and possibly (but not necessarily) less actively maintained than 'core' modules.
|
2014-11-04 23:38:02 +01:00
|
|
|
- Tickets filed on modules are filed to different repos than those on the main open source project. Core module tickets should be filed at `ansible/ansible-modules-core on GitHub <http://github.com/ansible/ansible-modules-core>`_, extras tickets to `ansible/ansible-modules-extras on GitHub <http://github.com/ansible/ansible-modules-extras>`_
|
2014-10-31 20:06:00 +01:00
|
|
|
""" % (DEPRECATED, NOTCORE))
|
2013-12-25 19:23:58 +01:00
|
|
|
category_file.close()
|
2013-12-25 18:35:41 +01:00
|
|
|
|
|
|
|
# TODO: end a new category file
|
|
|
|
|
|
|
|
#####################################################################################
|
|
|
|
|
|
|
|
def validate_options(options):
|
|
|
|
''' validate option parser options '''
|
|
|
|
|
|
|
|
if not options.module_dir:
|
|
|
|
print >>sys.stderr, "--module-dir is required"
|
|
|
|
sys.exit(1)
|
|
|
|
if not os.path.exists(options.module_dir):
|
|
|
|
print >>sys.stderr, "--module-dir does not exist: %s" % options.module_dir
|
|
|
|
sys.exit(1)
|
|
|
|
if not options.template_dir:
|
|
|
|
print "--template-dir must be specified"
|
|
|
|
sys.exit(1)
|
2013-04-28 21:03:45 +02:00
|
|
|
|
2013-12-25 18:35:41 +01:00
|
|
|
#####################################################################################
|
2012-09-26 20:41:44 +02:00
|
|
|
|
2013-12-25 18:35:41 +01:00
|
|
|
def main():
|
2012-09-26 20:41:44 +02:00
|
|
|
|
2013-12-25 18:35:41 +01:00
|
|
|
p = generate_parser()
|
2012-09-28 03:34:28 +02:00
|
|
|
|
2013-12-25 18:35:41 +01:00
|
|
|
(options, args) = p.parse_args()
|
|
|
|
validate_options(options)
|
2012-09-26 20:41:44 +02:00
|
|
|
|
2013-12-25 18:35:41 +01:00
|
|
|
env, template, outputname = jinja2_environment(options.template_dir, options.type)
|
2012-10-09 22:04:55 +02:00
|
|
|
|
2013-12-25 18:35:41 +01:00
|
|
|
categories = list_modules(options.module_dir)
|
|
|
|
last_category = None
|
|
|
|
category_names = categories.keys()
|
|
|
|
category_names.sort()
|
2013-12-25 19:38:40 +01:00
|
|
|
|
2013-12-25 19:23:58 +01:00
|
|
|
category_list_path = os.path.join(options.output_dir, "modules_by_category.rst")
|
|
|
|
category_list_file = open(category_list_path, "w")
|
|
|
|
category_list_file.write("Module Index\n")
|
|
|
|
category_list_file.write("============\n")
|
|
|
|
category_list_file.write("\n\n")
|
|
|
|
category_list_file.write(".. toctree::\n")
|
2013-12-26 03:29:54 +01:00
|
|
|
category_list_file.write(" :maxdepth: 1\n\n")
|
2013-12-25 19:38:40 +01:00
|
|
|
|
2013-12-25 18:35:41 +01:00
|
|
|
for category in category_names:
|
2014-11-04 04:02:13 +01:00
|
|
|
if category.startswith("_"):
|
|
|
|
continue
|
2013-12-26 03:29:54 +01:00
|
|
|
category_list_file.write(" list_of_%s_modules\n" % category)
|
2013-12-25 18:35:41 +01:00
|
|
|
process_category(category, categories, options, env, template, outputname)
|
2012-09-26 20:41:44 +02:00
|
|
|
|
2013-12-25 19:23:58 +01:00
|
|
|
category_list_file.close()
|
|
|
|
|
2012-09-26 20:41:44 +02:00
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|