Ejemplo n.º 1
0
def _load_collections(invocation):
    """
    Special loader that ensures that `ansible_collections` exist as a module path for import
    Goes through all collection path possibilities and stores paths to installed collections
    Stores them on the current invocation to later be passed to the master service
    """
    for collection_path in list_collection_dirs():
        invocation._extra_sys_paths.add(collection_path.decode('utf-8'))
Ejemplo n.º 2
0
def add_collection_plugins(plugin_list, plugin_type, coll_filter=None):

    # TODO: take into account runtime.yml once implemented
    b_colldirs = list_collection_dirs(coll_filter=coll_filter)
    for b_path in b_colldirs:
        path = to_text(b_path, errors='surrogate_or_strict')
        collname = _get_collection_name_from_path(b_path)
        ptype = C.COLLECTION_PTYPE_COMPAT.get(plugin_type, plugin_type)
        plugin_list.update(DocCLI.find_plugins(os.path.join(path, 'plugins', ptype), plugin_type, collection=collname))
Ejemplo n.º 3
0
def main(args):
    parser = argparse.ArgumentParser(
        prog=args[0], description='Bulk extraction of Ansible plugin docs.')
    parser.add_argument('args',
                        nargs='*',
                        help='Collection filter',
                        metavar='collection_filter')
    parser.add_argument('--pretty',
                        action='store_true',
                        help='Pretty-print JSON')
    opt_help.add_basedir_options(parser)

    arguments = parser.parse_args(args[1:])

    basedir = arguments.basedir
    coll_filter = arguments.args or None

    if basedir:
        AnsibleCollectionConfig.playbook_paths = basedir

    result = {
        'plugins': {},
        'collections': {},
    }

    # Export plugin docs
    for plugin_type in C.DOCUMENTABLE_PLUGINS:
        result['plugins'][plugin_type] = load_all_plugins(
            plugin_type, basedir, coll_filter)

    # Export role docs
    RoleMixin = getattr(doc, 'RoleMixin', None)
    if RoleMixin is not None:
        result['plugins']['role'] = load_all_roles(RoleMixin, basedir,
                                                   coll_filter)
    else:
        result['plugins']['role'] = {}

    # Export collection data
    b_colldirs = list_collection_dirs(
        coll_filter=ansible_doc_coll_filter(coll_filter))
    for b_path in b_colldirs:
        meta = load_collection_meta(b_path)
        collection_name = '{0}.{1}'.format(meta['namespace'], meta['name'])
        if match_filter(collection_name, coll_filter):
            result['collections'][collection_name] = meta
    if match_filter('ansible.builtin', coll_filter):
        result['collections']['ansible.builtin'] = {
            'path': os.path.dirname(ansible_release.__file__),
            'version': ansible_release.__version__,
        }

    print(
        json.dumps(result,
                   cls=AnsibleJSONEncoder,
                   sort_keys=True,
                   indent=4 if arguments.pretty else None))
Ejemplo n.º 4
0
def add_collection_plugins(plugin_list, plugin_type, coll_filter=None):

    # TODO: take into account routing.yml once implemented
    colldirs = list_collection_dirs(coll_filter=coll_filter)
    for path in colldirs:
        collname = get_collection_name_from_path(path)
        ptype = C.COLLECTION_PTYPE_COMPAT.get(plugin_type, plugin_type)
        plugin_list.update(
            DocCLI.find_plugins(os.path.join(path, 'plugins', ptype),
                                plugin_type, collname))