def main():
    doc_cli = DocCLI([])
    module_paths = module_loader._get_paths()

    module_keys = ('module', 'short_description', 'options', 'deprecated')

    for path in module_paths:
        doc_cli.find_modules(path)

    result = {
        'modules': [],
        'directives': defaultdict(list),
        'lookup_plugins': [],
    }

    for module in sorted(set(doc_cli.module_list)):
        if module in module_docs.BLACKLIST_MODULES:
            continue
        filename = module_loader.find_plugin(module, mod_type='.py')
        if not filename:
            continue
        if filename.endswith('.ps1'):
            continue
        if os.path.isdir(filename):
            continue
        try:
            doc, plain_examples, return_docs = module_docs.get_docstring(filename)
            filtered_doc = {key: doc.get(key) for key in module_keys}
            result['modules'].append(filtered_doc)
        except Exception:
            pass

    for aclass in (Play, Role, Block, Task):
        aobj = aclass()
        name = aclass.__name__

        for attr in aobj.__dict__['_attributes']:
            if 'private' in attr and attr.private:
                continue
            direct_target = result['directives'][attr]
            direct_target.append(name)
            if attr == 'action':
                local_action = result['directives']['local_action']
                local_action.append(name)
    result['directives']['with_'] = ['Task']

    for lookup in lookup_loader.all():
        name = os.path.splitext(os.path.basename(lookup._original_path))[0]
        result['lookup_plugins'].append(name)

    fn = os.path.join(__path__, '../data/ansible-data.json')
    with codecs.open(fn, 'wb', encoding='utf-8') as f:
        json.dump(result, f, ensure_ascii=False, indent=2)
Example #2
0
    def run(self):
        plugin_type = self.options.get('type')
        if plugin_type in C.DOCUMENTABLE_PLUGINS:
            loader = getattr(plugin_loader, '%s_loader' % plugin_type)
        else:
            raise AnsibleOptionsError("Unknown or undocumentable plugin type: %s" % plugin_type)

        if self.options.get('module_path'):
            for path in self.options.get('module_path'):
                if path:
                    loader.add_directory(path)

        if self.options.get('json_dump'):
            plugin_data = {}
            for plugin_type in C.DOCUMENTABLE_PLUGINS:
                plugin_data[plugin_type] = dict()
                plugin_names = self.get_all_plugins_of_type(plugin_type)
                for plugin_name in plugin_names:
                    plugin_info = self.get_plugin_metadata(plugin_type, plugin_name)
                    if plugin_info is not None:
                        plugin_data[plugin_type][plugin_name] = plugin_info

            return plugin_data

        search_paths = DocCLI.print_paths(loader)
        loader._paths = None
        text = ''
        for plugin in self.args:
            textret = self.format_plugin_doc(plugin, loader, plugin_type, search_paths)

            if textret:
                text += textret

        return text
def main():
    doc_cli = DocCLI([])
    module_paths = module_loader._get_paths()

    module_keys = ('module', 'short_description', 'options', 'deprecated')

    for path in module_paths:
        doc_cli.find_modules(path)

    result = {'modules': [], 'directives': {}, 'lookup_plugins':[]}

    for module in sorted(set(doc_cli.module_list)):
        if module in module_docs.BLACKLIST_MODULES:
            continue
        filename = module_loader.find_plugin(module, mod_type='.py')
        if filename is None:
            continue
        if filename.endswith(".ps1"):
            continue
        if os.path.isdir(filename):
            continue
        try:
            doc, plainexamples, returndocs = module_docs.get_docstring(filename)
            filtered_doc = {key: doc.get(key, None) for key in module_keys}
            result['modules'].append(filtered_doc)
        except:
            pass

    for aclass in (Play, Role, Block, Task):
        aobj = aclass()
        name = type(aobj).__name__

        for attr in aobj.__dict__['_attributes']:
            if 'private' in attr and attr.private:
                continue
            direct_target = result['directives'].setdefault(attr, [])
            direct_target.append(name)
            if attr == 'action':
                local_action = result['directives'].setdefault('local_action', [])
                local_action.append(name)
    result['directives']['with_'] = ['Task']

    for lookup in lookup_loader.all():
        name = os.path.splitext(os.path.basename(lookup._original_path))[0]
        result['lookup_plugins'].append(name)

    print(json.dumps(result))
def test_ttyify(text, expected):
    assert DocCLI.tty_ify(text) == expected
Example #5
0
def test_parsing_all_option():
    doc_cli = DocCLI(['/n/ansible-doc', '-a'])
    doc_cli.parse()
Example #6
0
    BLACKLIST_MODULES = plugin_docs.BLACKLIST['MODULE']
except ImportError:
    from ansible.plugins import lookup_loader, module_loader
    from ansible.utils import module_docs as plugin_docs
    use_old_loader = True
    BLACKLIST_MODULES = plugin_docs.BLACKLIST_MODULES

try:
    from ansible.plugins.loader import fragment_loader
    USE_FRAGMENT_LOADER = True
except ImportError:
    fragment_loader = None
    USE_FRAGMENT_LOADER = False

__main__.display = Display()
doc_cli = DocCLI([])


def get_module_list():
    module_paths = module_loader._get_paths()
    for path in module_paths:
        if use_old_loader:
            doc_cli.find_modules(path)
        else:
            doc_cli.find_plugins(path, 'module')
    module_list = doc_cli.module_list if use_old_loader else doc_cli.plugin_list
    return sorted(set(module_list))


def main():
    module_keys = ('module', 'short_description', 'options', 'deprecated')
Example #7
0
def test_legacy_modules_list():
    args = ['ansible-doc', '-l', 'ansible.legacy', '-t', 'module']
    obj = DocCLI(args=args)
    obj.parse()
    result = obj._list_plugins('module', module_loader)
    assert len(result) == 0
    BLACKLIST_MODULES = plugin_docs.BLACKLIST['MODULE']
except ImportError:
    from ansible.plugins import lookup_loader, module_loader
    from ansible.utils import module_docs as plugin_docs
    use_old_loader = True
    BLACKLIST_MODULES = plugin_docs.BLACKLIST_MODULES

try:
    from ansible.plugins.loader import fragment_loader
    USE_FRAGMENT_LOADER = True
except ImportError:
    fragment_loader = None
    USE_FRAGMENT_LOADER = False

__main__.display = Display()
doc_cli = DocCLI(['ansible atom'])


def get_module_list():
    module_paths = module_loader._get_paths()
    for path in module_paths:
        if use_old_loader:
            doc_cli.find_modules(path)
        else:
            founds = doc_cli.find_plugins(path, 'module')
            if founds:
                doc_cli.plugin_list.update(founds)
    module_list = (
        doc_cli.module_list if use_old_loader else doc_cli.plugin_list)
    return sorted(set(module_list))