Changeset View
Changeset View
Standalone View
Standalone View
swh/vault/cli.py
Show First 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | @click.option( | ||||
metavar="CONFIGFILE", | metavar="CONFIGFILE", | ||||
type=click.Path(exists=True, dir_okay=False,), | type=click.Path(exists=True, dir_okay=False,), | ||||
help="Configuration file.", | help="Configuration file.", | ||||
) | ) | ||||
@click.argument("swhid", type=SwhidParamType()) | @click.argument("swhid", type=SwhidParamType()) | ||||
@click.argument("outfile", type=click.File("wb")) | @click.argument("outfile", type=click.File("wb")) | ||||
@click.option( | @click.option( | ||||
"--cooker-type", | "--cooker-type", | ||||
type=click.Choice(["flat", "gitfast"]), | type=click.Choice(["flat", "gitfast", "git_bare"]), | ||||
help="Selects which cooker to use, when there is more than one available " | help="Selects which cooker to use, when there is more than one available " | ||||
"for the given object type.", | "for the given object type.", | ||||
) | ) | ||||
@click.pass_context | @click.pass_context | ||||
def cook( | def cook( | ||||
ctx, | ctx, | ||||
config_file: str, | config_file: str, | ||||
swhid: CoreSWHID, | swhid: CoreSWHID, | ||||
outfile: io.RawIOBase, | outfile: io.RawIOBase, | ||||
cooker_type: Optional[str], | cooker_type: Optional[str], | ||||
): | ): | ||||
""" | """ | ||||
Runs a vault cooker for a single object (identified by a SWHID), | Runs a vault cooker for a single object (identified by a SWHID), | ||||
and outputs it to the given file. | and outputs it to the given file. | ||||
""" | """ | ||||
from swh.core import config | from swh.core import config | ||||
from swh.graph.client import RemoteGraphClient | |||||
from swh.storage import get_storage | from swh.storage import get_storage | ||||
from .cookers import COOKER_TYPES, get_cooker_cls | from .cookers import COOKER_TYPES, get_cooker_cls | ||||
from .in_memory_backend import InMemoryVaultBackend | from .in_memory_backend import InMemoryVaultBackend | ||||
conf = config.read(config_file) | conf = config.read(config_file) | ||||
supported_object_types = {name.split("_")[0] for name in COOKER_TYPES} | supported_object_types = {name.split("_")[0] for name in COOKER_TYPES} | ||||
Show All 15 Lines | else: | ||||
if cooker_name not in COOKER_TYPES: | if cooker_name not in COOKER_TYPES: | ||||
raise click.ClickException( | raise click.ClickException( | ||||
f"{swhid.object_type.name.lower()} objects need " | f"{swhid.object_type.name.lower()} objects need " | ||||
f"an explicit --cooker-type." | f"an explicit --cooker-type." | ||||
) | ) | ||||
backend = InMemoryVaultBackend() | backend = InMemoryVaultBackend() | ||||
storage = get_storage(**conf["storage"]) | storage = get_storage(**conf["storage"]) | ||||
graph = RemoteGraphClient(**conf["graph"]) if "graph" in conf else None | |||||
cooker_cls = get_cooker_cls(cooker_name) | cooker_cls = get_cooker_cls(cooker_name) | ||||
cooker = cooker_cls(cooker_name, swhid.object_id, backend, storage) | cooker = cooker_cls(cooker_name, swhid.object_id, backend, storage, graph) | ||||
cooker.cook() | cooker.cook() | ||||
bundle = backend.fetch(cooker_name, swhid.object_id) | bundle = backend.fetch(cooker_name, swhid.object_id) | ||||
assert bundle, "Cooker did not write a bundle to the backend." | assert bundle, "Cooker did not write a bundle to the backend." | ||||
outfile.write(bundle) | outfile.write(bundle) | ||||
@vault.command(name="rpc-serve") | @vault.command(name="rpc-serve") | ||||
▲ Show 20 Lines • Show All 52 Lines • Show Last 20 Lines |