예제 #1
0
# Copy the repo into a temporary directory, removing the build and deps, and
# perform generation there. This is because the docker command may be a
# cross-compile whose build environment should be isolated from the current
# git clone.
with tempfile.TemporaryDirectory() as tmpdir:
    repository = pathlib.Path(tmpdir) / "repo"
    shutil.copytree(os.getcwd(), repository)
    shutil.rmtree(repository / "_build", ignore_errors=True)
    shutil.rmtree(repository / "deps", ignore_errors=True)

    image = "gcr.io/cloud-devrel-public-resources/elixir19"
    generate_command = "scripts/generate_client.sh"
    command = [
        "docker", "run", "--rm", f"-v{repository}:/workspace",
        "-v/var/run/docker.sock:/var/run/docker.sock", "-e",
        f"USER_GROUP={os.getuid()}:{os.getgid()}", "-w", "/workspace", image,
        generate_command
    ]

    if extra_args():
        command.extend(extra_args())

    log.debug(f"Running: {' '.join(command)}")

    shell.run(command, cwd=repository, hide_output=False)

    # Copy the resulting clients directory back into the git clone.
    shutil.rmtree("clients", ignore_errors=True)
    shutil.move(repository / "clients", "clients")
        client_name = existing_client.split("/")[1]
        if client_name not in services_by_id:
            print(f"deleting entire service: {client_name}")
            shutil.rmtree(f"clients/{client_name}", ignore_errors=True)
        elif version not in services_by_id[client_name]:
            print(f"deleting {version} of {client_name}")
            shutil.rmtree(f"clients/{client_name}/{version}")
            remove(f"clients/{client_name}/{version}.metadata.json")


def generate_services(services):
    for service in services:
        generate_service(service)


if extra_args():
    api_name = extra_args()[0]
    if api_name == "README":
        services = all_services()
        generate_service_list(services)
        remove_unused_services(services)
    else:
        discoveries = all_discoveries()
        discoveries = [
            discovery for discovery in discoveries
            if discovery.startswith(api_name)
        ]
        generate_services(discoveries)
else:
    discoveries = all_discoveries()
    generate_services(discoveries)