예제 #1
0
    def _get_plugin_list_descriptions(self, loader):

        descs = {}
        plugins = self._get_plugin_list_filenames(loader)
        for plugin in plugins.keys():

            filename = plugins[plugin]

            doc = None
            try:
                doc = read_docstub(filename)
            except Exception:
                display.warning("%s has a documentation formatting error" %
                                plugin)
                continue

            if not doc or not isinstance(doc, dict):
                with open(filename) as f:
                    metadata = extract_metadata(module_data=f.read())
                if metadata[0]:
                    if 'removed' not in metadata[0].get('status', []):
                        display.warning(
                            "%s parsing did not produce documentation." %
                            plugin)
                    else:
                        continue
                desc = 'UNDOCUMENTED'
            else:
                desc = doc.get('short_description',
                               'INVALID SHORT DESCRIPTION').strip()

            descs[plugin] = desc

        return descs
예제 #2
0
    def _get_plugin_list_descriptions(self, loader):

        descs = {}
        plugins = self._get_plugin_list_filenames(loader)
        for plugin in plugins.keys():

            filename = plugins[plugin]

            doc = None
            try:
                doc = read_docstub(filename)
            except Exception:
                display.warning("%s has a documentation formatting error" %
                                plugin)
                continue

            if not doc or not isinstance(doc, dict):
                desc = 'UNDOCUMENTED'
            else:
                desc = doc.get('short_description',
                               'INVALID SHORT DESCRIPTION').strip()

            descs[plugin] = desc

        return descs
예제 #3
0
def get_docstub(filename, fragment_loader, verbose=False, ignore_errors=False):
    """
    When only short_description is needed, load a stub of the full DOCUMENTATION string to speed up operation.
    """

    data = read_docstub(filename, verbose=verbose, ignore_errors=ignore_errors)

    if data.get('doc', False):
        add_fragments(data['doc'], filename, fragment_loader=fragment_loader)

    return data['doc'], data['plainexamples'], data['returndocs'], data[
        'metadata']
예제 #4
0
    def get_plugin_list_text(self, loader):
        columns = display.columns
        displace = max(len(x) for x in self.plugin_list)
        linelimit = columns - displace - 5
        text = []
        deprecated = []
        for plugin in sorted(self.plugin_list):

            try:
                # if the module lives in a non-python file (eg, win_X.ps1), require the corresponding python file for docs
                filename = loader.find_plugin(plugin, mod_type='.py', ignore_deprecated=True, check_aliases=True)

                if filename is None:
                    continue
                if filename.endswith(".ps1"):
                    continue
                if os.path.isdir(filename):
                    continue

                doc = None
                try:
                    doc = read_docstub(filename)
                except Exception:
                    display.warning("%s has a documentation formatting error" % plugin)
                    continue

                if not doc or not isinstance(doc, dict):
                    with open(filename) as f:
                        metadata = extract_metadata(module_data=f.read())
                    if metadata[0]:
                        if 'removed' not in metadata[0].get('status', []):
                            display.warning("%s parsing did not produce documentation." % plugin)
                        else:
                            continue
                    desc = 'UNDOCUMENTED'
                else:
                    desc = self.tty_ify(doc.get('short_description', 'INVALID SHORT DESCRIPTION').strip())

                if len(desc) > linelimit:
                    desc = desc[:linelimit] + '...'

                if plugin.startswith('_'):  # Handle deprecated
                    deprecated.append("%-*s %-*.*s" % (displace, plugin[1:], linelimit, len(desc), desc))
                else:
                    text.append("%-*s %-*.*s" % (displace, plugin, linelimit, len(desc), desc))
            except Exception as e:
                raise AnsibleError("Failed reading docs at %s: %s" % (plugin, to_native(e)), orig_exc=e)

        if len(deprecated) > 0:
            text.append("\nDEPRECATED:")
            text.extend(deprecated)
        return "\n".join(text)