From a78fdde32c8b17b43aa1c94778c45effbbcbb100 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Tue, 28 Jul 2015 14:29:43 -0400 Subject: [PATCH] better handling for weird doc corner cases (abscense of options, bad text objects, etc) also updated extras to get some docfixes on the module side --- hacking/module_formatter.py | 25 +++++++++++++++++-------- lib/ansible/modules/extras | 2 +- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/hacking/module_formatter.py b/hacking/module_formatter.py index 31fea52973d..7ce08139389 100755 --- a/hacking/module_formatter.py +++ b/hacking/module_formatter.py @@ -36,6 +36,7 @@ from jinja2 import Environment, FileSystemLoader from ansible.utils import module_docs from ansible.utils.vars import merge_hash +from ansible.errors import AnsibleError ##################################################################################### # constants and paths @@ -67,11 +68,14 @@ NOTCORE = " (E)" def rst_ify(text): ''' convert symbols like I(this is in italics) to valid restructured text ''' - t = _ITALIC.sub(r'*' + r"\1" + r"*", text) - t = _BOLD.sub(r'**' + r"\1" + r"**", t) - t = _MODULE.sub(r':ref:`' + r"\1 <\1>" + r"`", t) - t = _URL.sub(r"\1", t) - t = _CONST.sub(r'``' + r"\1" + r"``", t) + try: + t = _ITALIC.sub(r'*' + r"\1" + r"*", text) + t = _BOLD.sub(r'**' + r"\1" + r"**", t) + t = _MODULE.sub(r':ref:`' + r"\1 <\1>" + r"`", t) + t = _URL.sub(r"\1", t) + t = _CONST.sub(r'``' + r"\1" + r"``", t) + except Exception as e: + raise AnsibleError("Could not process (%s) : %s" % (str(text), str(e))) return t @@ -286,7 +290,7 @@ def process_module(module, options, env, template, outputname, module_map, alias if too_old(added): del doc['version_added'] - if 'options' in doc: + if 'options' in doc and doc['options']: for (k,v) in doc['options'].iteritems(): # 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']): @@ -308,7 +312,12 @@ def process_module(module, options, env, template, outputname, module_map, alias # here is where we build the table of contents... - text = template.render(doc) + try: + import q + q(doc) + text = template.render(doc) + except Exception as e: + raise AnsibleError("Failed to render doc for %s: %s" % (fname, str(e))) write_data(text, options, outputname, module) return doc['short_description'] @@ -326,7 +335,7 @@ def print_modules(module, category_file, deprecated, core, options, env, templat 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)) + category_file.write(" %s - %s <%s_module>\n" % (modstring, rst_ify(result), module)) def process_category(category, categories, options, env, template, outputname): diff --git a/lib/ansible/modules/extras b/lib/ansible/modules/extras index 1d06ee6e2d6..e30d8b84fe7 160000 --- a/lib/ansible/modules/extras +++ b/lib/ansible/modules/extras @@ -1 +1 @@ -Subproject commit 1d06ee6e2d6da6de158c538cf451aa075384c450 +Subproject commit e30d8b84fe7ff3be427a46ff67629cce55252594