示例#1
0
def download_registry(general_config, config_root, registry_outfile, network,
                      force):
    """Download the latest registry."""

    # Setup
    emitter = general_config.emitter
    ensure_config_root(config_root)
    github_source = GithubRegistrySource(
        network=network, registry_name=BaseContractRegistry.REGISTRY_NAME)
    source_manager = RegistrySourceManager(sources=[github_source])

    if not force:
        prompt = CONFIRM_MANUAL_REGISTRY_DOWNLOAD.format(source=github_source)
        click.confirm(prompt, abort=True)
    try:
        registry = InMemoryContractRegistry.from_latest_publication(
            source_manager=source_manager, network=network)
    except RegistrySourceManager.NoSourcesAvailable:
        emitter.message(REGISTRY_NOT_AVAILABLE, color="red")
        raise click.Abort

    try:
        output_filepath = registry.commit(filepath=registry_outfile,
                                          overwrite=force)
    except InMemoryContractRegistry.CantOverwriteRegistry:
        emitter.message(CANNOT_OVERWRITE_REGISTRY, color="red")
        raise click.Abort
    emitter.message(
        SUCCESSFUL_REGISTRY_DOWNLOAD.format(output_filepath=output_filepath))
示例#2
0
def download_registry(general_config, config_root, registry_outfile, network,
                      force):
    """
    Download the latest registry.
    """
    # Init
    emitter = general_config.emitter
    _ensure_config_root(config_root)

    github_source = GithubRegistrySource(
        network=network, registry_name=BaseContractRegistry.REGISTRY_NAME)
    source_manager = RegistrySourceManager(sources=[github_source])

    if not force:
        prompt = f"Fetch and download latest contract registry from {github_source}?"
        click.confirm(prompt, abort=True)
    try:
        registry = InMemoryContractRegistry.from_latest_publication(
            source_manager=source_manager, network=network)
    except RegistrySourceManager.NoSourcesAvailable:
        emitter.message("Registry not available.", color="red")
        raise click.Abort

    try:
        output_filepath = registry.commit(filepath=registry_outfile,
                                          overwrite=force)
    except InMemoryContractRegistry.CantOverwriteRegistry:
        emitter.message(
            "Can't overwrite existing registry. Use '--force' to overwrite.",
            color="red")
        raise click.Abort
    emitter.message(
        f"Successfully downloaded latest registry to {output_filepath}")