def process_file()

in update-imported-docs/update-imported-docs.py [0:0]


def process_file(src, dst, repo_path, repo_dir, root_dir, gen_absolute_links):
    """Process a file element.

    :param src: A string containing the relative path of a source file. The
        string may contain wildcard characters such as '*' or '?'.
    :param dst: The path for the destination file. The string can be a
        directory name or a file name.
    :param repo_path:
    :param repo_dir:
    :param root_dir:
    :param gen_absolute_links:
    """
    pattern = os.path.join(repo_dir, repo_path, src)
    dst_path = os.path.join(root_dir, dst)

    for src in glob.glob(pattern):
        # we don't dive into subdirectories
        if not os.path.isfile(src):
            print("[Error] skipping non-regular path {}".format(src))
            continue

        content = ""
        try:
            with open(src, "r") as srcFile:
                content = srcFile.read()
        except Exception as ex:
            print("[Error] failed in reading source file: ".format(ex))
            continue

        dst = dst_path
        if dst_path.endswith("/"):
            base_name = os.path.basename(src)
            dst = os.path.join(dst, base_name)

        try:
            print("Writing doc: " + dst)
            with open(dst, "w") as dstFile:
                if gen_absolute_links:
                    src_dir = os.path.dirname(src)
                    remote_prefix = repo_path + "/tree/master"
                    content = process_links(content, remote_prefix, src_dir)
                if dst.endswith("kubectl.md"):
                    print("Processing kubectl links")
                    content = process_kubectl_links(content)
                dstFile.write(content)
        except Exception as ex:
            print("[Error] failed in writing target file {}: {}".format(dst, ex))
            continue