docs: PEP8 compliance (#24681)

- Make PEP8 compliant
pull/4420/head
Dag Wieers 2017-05-30 19:08:25 +02:00 committed by John R Barker
parent 44121352fe
commit 47738eb1dd
5 changed files with 131 additions and 151 deletions

View File

@ -16,22 +16,21 @@
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>. # along with Ansible. If not, see <http://www.gnu.org/licenses/>.
#
from __future__ import print_function from __future__ import print_function
__metaclass__ = type __metaclass__ = type
import os
import glob
import sys
import yaml
import re
import optparse
import datetime
import cgi import cgi
import datetime
import glob
import optparse
import os
import re
import sys
import warnings import warnings
from collections import defaultdict import yaml
from collections import defaultdict
from jinja2 import Environment, FileSystemLoader from jinja2 import Environment, FileSystemLoader
from six import iteritems from six import iteritems
@ -63,7 +62,7 @@ _URL = re.compile(r"U\(([^)]+)\)")
_CONST = re.compile(r"C\(([^)]+)\)") _CONST = re.compile(r"C\(([^)]+)\)")
DEPRECATED = b" (D)" DEPRECATED = b" (D)"
#####################################################################################
def rst_ify(text): def rst_ify(text):
''' convert symbols like I(this is in italics) to valid restructured text ''' ''' convert symbols like I(this is in italics) to valid restructured text '''
@ -79,7 +78,6 @@ def rst_ify(text):
return t return t
#####################################################################################
def html_ify(text): def html_ify(text):
''' convert symbols like I(this is in italics) to valid HTML ''' ''' convert symbols like I(this is in italics) to valid HTML '''
@ -94,21 +92,17 @@ def html_ify(text):
return t return t
#####################################################################################
def rst_fmt(text, fmt): def rst_fmt(text, fmt):
''' helper for Jinja2 to do format strings ''' ''' helper for Jinja2 to do format strings '''
return fmt % (text) return fmt % (text)
#####################################################################################
def rst_xline(width, char="="): def rst_xline(width, char="="):
''' return a restructured text line of a given length ''' ''' return a restructured text line of a given length '''
return char * width return char * width
#####################################################################################
def write_data(text, options, outputname, module): def write_data(text, options, outputname, module):
''' dumps module output to a file or the screen, as requested ''' ''' dumps module output to a file or the screen, as requested '''
@ -122,8 +116,6 @@ def write_data(text, options, outputname, module):
else: else:
print(text) print(text)
#####################################################################################
def list_modules(module_dir, depth=0): def list_modules(module_dir, depth=0):
''' returns a hash of categories, each category being a hash of module names to file paths ''' ''' returns a hash of categories, each category being a hash of module names to file paths '''
@ -176,7 +168,6 @@ def list_modules(module_dir, depth=0):
return module_info, categories, aliases return module_info, categories, aliases
#####################################################################################
def generate_parser(): def generate_parser():
''' generate an optparse parser ''' ''' generate an optparse parser '''
@ -197,15 +188,13 @@ def generate_parser():
p.add_option('-V', action='version', help='Show version number and exit') p.add_option('-V', action='version', help='Show version number and exit')
return p return p
#####################################################################################
def jinja2_environment(template_dir, typ): def jinja2_environment(template_dir, typ):
env = Environment(loader=FileSystemLoader(template_dir), env = Environment(loader=FileSystemLoader(template_dir),
variable_start_string="@{", variable_start_string="@{",
variable_end_string="}@", variable_end_string="}@",
trim_blocks=True, trim_blocks=True)
)
env.globals['xline'] = rst_xline env.globals['xline'] = rst_xline
if typ == 'rst': if typ == 'rst':
@ -220,7 +209,7 @@ def jinja2_environment(template_dir, typ):
return env, template, outputname return env, template, outputname
#####################################################################################
def too_old(added): def too_old(added):
if not added: if not added:
return False return False
@ -233,6 +222,7 @@ def too_old(added):
return False return False
return (added_float < TO_OLD_TO_BE_NOTABLE) return (added_float < TO_OLD_TO_BE_NOTABLE)
def process_module(module, options, env, template, outputname, module_map, aliases): def process_module(module, options, env, template, outputname, module_map, aliases):
fname = module_map[module] fname = module_map[module]
@ -271,7 +261,7 @@ def process_module(module, options, env, template, outputname, module_map, alias
all_keys = [] all_keys = []
if not 'version_added' in doc: if 'version_added' not in doc:
sys.exit("*** ERROR: missing version_added in: %s ***\n" % module) sys.exit("*** ERROR: missing version_added in: %s ***\n" % module)
added = 0 added = 0
@ -289,7 +279,7 @@ def process_module(module, options, env, template, outputname, module_map, alias
# don't show version added information if it's too old to be called out # 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']): if 'version_added' in doc['options'][k] and too_old(doc['options'][k]['version_added']):
del doc['options'][k]['version_added'] del doc['options'][k]['version_added']
if not 'description' in doc['options'][k]: if 'description' not in doc['options'][k]:
raise AnsibleError("Missing required description for option %s in %s " % (k, module)) raise AnsibleError("Missing required description for option %s in %s " % (k, module))
required_value = doc['options'][k].get('required', False) required_value = doc['options'][k].get('required', False)
@ -328,7 +318,6 @@ def process_module(module, options, env, template, outputname, module_map, alias
write_data(text, options, outputname, module) write_data(text, options, outputname, module)
return doc['short_description'] return doc['short_description']
#####################################################################################
def print_modules(module, category_file, deprecated, options, env, template, outputname, module_map, aliases): def print_modules(module, category_file, deprecated, options, env, template, outputname, module_map, aliases):
modstring = module modstring = module
@ -340,9 +329,10 @@ def print_modules(module, category_file, deprecated, options, env, template, out
category_file.write(b" %s - %s <%s_module>\n" % (to_bytes(modstring), to_bytes(rst_ify(module_map[module][1])), to_bytes(modname))) category_file.write(b" %s - %s <%s_module>\n" % (to_bytes(modstring), to_bytes(rst_ify(module_map[module][1])), to_bytes(modname)))
def process_category(category, categories, options, env, template, outputname): def process_category(category, categories, options, env, template, outputname):
### FIXME: # FIXME:
# We no longer conceptually deal with a mapping of category names to # We no longer conceptually deal with a mapping of category names to
# modules to file paths. Instead we want several different records: # modules to file paths. Instead we want several different records:
# (1) Mapping of module names to file paths (what's presently used # (1) Mapping of module names to file paths (what's presently used
@ -424,7 +414,6 @@ def process_category(category, categories, options, env, template, outputname):
# TODO: end a new category file # TODO: end a new category file
#####################################################################################
def validate_options(options): def validate_options(options):
''' validate option parser options ''' ''' validate option parser options '''
@ -436,7 +425,6 @@ def validate_options(options):
if not options.template_dir: if not options.template_dir:
sys.exit("--template-dir must be specified") sys.exit("--template-dir must be specified")
#####################################################################################
def main(): def main():
@ -465,9 +453,7 @@ def main():
for category in category_names: for category in category_names:
category_list_file.write(b" list_of_%s_modules\n" % to_bytes(category)) category_list_file.write(b" list_of_%s_modules\n" % to_bytes(category))
#
# Import all the docs into memory # Import all the docs into memory
#
module_map = mod_info.copy() module_map = mod_info.copy()
for modname in module_map: for modname in module_map:
@ -477,11 +463,10 @@ def main():
else: else:
categories['all'][modname] = (categories['all'][modname], result) categories['all'][modname] = (categories['all'][modname], result)
#
# Render all the docs to rst via category pages # Render all the docs to rst via category pages
#
for category in category_names: for category in category_names:
process_category(category, categories, options, env, template, outputname) process_category(category, categories, options, env, template, outputname)
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View File

@ -1,11 +1,6 @@
contrib/inventory/freeipa.py contrib/inventory/freeipa.py
contrib/inventory/rackhd.py contrib/inventory/rackhd.py
contrib/inventory/vmware_inventory.py contrib/inventory/vmware_inventory.py
docs/api/conf.py
docs/bin/dump_keywords.py
docs/bin/plugin_formatter.py
docs/docsite/rst/conf.py
docs/docsite/rst/intro_inventory.rst
lib/ansible/cli/__init__.py lib/ansible/cli/__init__.py
lib/ansible/cli/adhoc.py lib/ansible/cli/adhoc.py
lib/ansible/cli/console.py lib/ansible/cli/console.py