Changeset View
Changeset View
Standalone View
Standalone View
swh/vault/cli.py
Show First 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | def cook( | ||||
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.graph.client import RemoteGraphClient | ||||
from swh.objstorage.factory import get_objstorage | |||||
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"]) | ||||
objstorage = get_objstorage(**conf["objstorage"]) if "objstorage" in conf else None | |||||
graph = RemoteGraphClient(**conf["graph"]) if "graph" in conf else None | 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, graph) | cooker = cooker_cls( | ||||
cooker_name, | |||||
swhid.object_id, | |||||
backend, | |||||
storage, | |||||
graph=graph, | |||||
objstorage=objstorage, | |||||
) | |||||
olasd: At this point it's probably sensible to use all kwargs. | |||||
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 |
At this point it's probably sensible to use all kwargs.