Пример #1
0
def create_antsibull_docs(files, plugin_type=None):
    """Creates the necessary docs for all files in a directory

    Args:
        files ([Path.Glob]): Glob of files from a specific directory.
        plugin_type ([str], optional): Create the proper documentation for the plugin type. Defaults to None.
    """
    for f in files:
        file_name = re.search(r"(?:.+\/)(\S+)\.py", str(f)).group(1)
        if file_name in ["netbox_interface"]:
            continue

        print(file_name)
        if plugin_type is not None:
            file_path = Path(f"plugins/{plugin_type}/{file_name}/")
        else:
            file_path = Path(f"plugins/modules/{file_name}/")

        file_path.mkdir(mode=744, exist_ok=True)

        if plugin_type is not None:
            args_string = f"junk plugin --dest-dir {file_path} --plugin-type {plugin_type} netbox.netbox.{file_name}"
        else:
            args_string = f"junk plugin --dest-dir {file_path} --plugin-type module netbox.netbox.{file_name}"
        args = args_string.split(" ")
        try:
            antsibull_docs.run(args)
        except Exception as e:
            sys.exit(1)
Пример #2
0
def generate_base_docs(args):
    """Regenerate the documentation for all plugins listed in the plugin_to_collection_file."""
    # imports here so that they don't cause unnecessary deps for all of the plugins
    from antsibull.cli import antsibull_docs

    with TemporaryDirectory() as tmp_dir:
        #
        # Construct a deps file with our version of ansible_base in it
        #
        modified_deps_file = os.path.join(tmp_dir, 'ansible.deps')

        # The _ansible_version doesn't matter since we're only building docs for base
        deps_file_contents = {
            '_ansible_version': ansible_base__version__,
            '_ansible_base_version': ansible_base__version__
        }

        with open(modified_deps_file, 'w') as f:
            f.write(yaml.dump(deps_file_contents))

        # Generate the plugin rst
        return antsibull_docs.run([
            'antsibull-docs', 'stable', '--deps-file', modified_deps_file,
            '--ansible-base-source',
            str(args.top_dir), '--dest-dir', args.output_dir
        ])
Пример #3
0
def create_antsibull_docs(files, plugin_type=None):
    """Creates the necessary docs for all files in a directory

    Args:
        files ([Path.Glob]): Glob of files from a specific directory.
        plugin_type ([str], optional): Create the proper documentation for the plugin type. Defaults to None.
    """
    for f in files:
        file_name = re.search(r"(?:.+\/)(\S+)\.py", str(f)).group(1)
        if plugin_type is not None:
            args_string = f"junk plugin --dest-dir plugins/{plugin_type}/{file_name}/ --plugin-type {plugin_type} netbox.netbox.{file_name}"
        else:
            args_string = f"junk plugin --dest-dir plugins/modules/{file_name}/ --plugin-type module netbox.netbox.{file_name}"
        args = args_string.split(" ")
        try:
            run(args)
        except:
            sys.exit(1)
Пример #4
0
def generate_full_docs(args):
    """Regenerate the documentation for all plugins listed in the plugin_to_collection_file."""
    # imports here so that they don't cause unnecessary deps for all of the plugins
    import sh
    from antsibull.cli import antsibull_docs
    from packaging.version import Version

    ansible_base_ver = Version(ansible_base__version__)
    ansible_base_major_ver = '{0}.{1}'.format(ansible_base_ver.major,
                                              ansible_base_ver.minor)

    with TemporaryDirectory() as tmp_dir:
        sh.git([
            'clone', 'https://github.com/ansible-community/ansible-build-data'
        ],
               _cwd=tmp_dir)
        # This is wrong.  Once ansible and ansible-base major.minor versions get out of sync this
        # will stop working.  We probably need to walk all subdirectories in reverse version order
        # looking for the latest ansible version which uses something compatible with
        # ansible_base_major_ver.
        deps_files = glob.glob(
            os.path.join(tmp_dir, 'ansible-build-data', ansible_base_major_ver,
                         '*.deps'))
        if not deps_files:
            raise Exception('No deps files exist for version {0}'.format(
                ansible_base_major_ver))

        # Find the latest version of the deps file for this version
        latest = None
        latest_ver = Version('0')
        for filename in deps_files:
            with open(filename, 'r') as f:
                deps_data = yaml.safe_load(f.read())
            new_version = Version(deps_data['_ansible_version'])
            if new_version > latest_ver:
                latest_ver = new_version
                latest = filename

        # Make a copy of the deps file so that we can set the ansible-base version to use
        modified_deps_file = os.path.join(tmp_dir, 'ansible.deps')
        shutil.copyfile(latest, modified_deps_file)

        # Put our version of ansible-base into the deps file
        with open(modified_deps_file, 'r') as f:
            deps_data = yaml.safe_load(f.read())

        deps_data['_ansible_base_version'] = ansible_base__version__

        with open(modified_deps_file, 'w') as f:
            f.write(yaml.dump(deps_data))

        # Generate the plugin rst
        return antsibull_docs.run([
            'antsibull-docs', 'stable', '--deps-file', modified_deps_file,
            '--ansible-base-cache',
            str(args.top_dir), '--dest-dir', args.output_dir
        ])
Пример #5
0
def generate_full_docs(args):
    """Regenerate the documentation for all plugins listed in the plugin_to_collection_file."""
    # imports here so that they don't cause unnecessary deps for all of the plugins
    import sh
    from antsibull.cli import antsibull_docs

    with TemporaryDirectory() as tmp_dir:
        sh.git([
            'clone', 'https://github.com/ansible-community/ansible-build-data'
        ],
               _cwd=tmp_dir)
        # If we want to validate that the ansible version and ansible-base branch version match,
        # this would be the place to do it.

        build_data_working = os.path.join(tmp_dir, 'ansible-build-data')
        if args.ansible_build_data:
            build_data_working = args.ansible_build_data

        ansible_version = args.ansible_version
        if ansible_version is None:
            ansible_version = find_latest_ansible_dir(build_data_working)
            params = [
                'devel', '--pieces-file',
                os.path.join(ansible_version, 'ansible.in')
            ]
        else:
            latest_filename = find_latest_deps_file(build_data_working,
                                                    ansible_version)

            # Make a copy of the deps file so that we can set the ansible-base version we'll use
            modified_deps_file = os.path.join(tmp_dir, 'ansible.deps')
            shutil.copyfile(latest_filename, modified_deps_file)

            # Put our version of ansible-base into the deps file
            with open(modified_deps_file, 'r') as f:
                deps_data = yaml.safe_load(f.read())

            deps_data['_ansible_base_version'] = ansible_base__version__

            with open(modified_deps_file, 'w') as f:
                f.write(yaml.dump(deps_data))

            params = ['stable', '--deps-file', modified_deps_file]

        # Generate the plugin rst
        return antsibull_docs.run(['antsibull-docs'] + params + [
            '--ansible-base-source',
            str(args.top_dir), '--dest-dir', args.output_dir
        ])