Changeset View
Changeset View
Standalone View
Standalone View
swh/vault/cli.py
| Show First 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | def cook( | ||||
| 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.objstorage.factory import get_objstorage | 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) | ||||
| Show All 14 Lines | if cooker_type: | ||||
| ) | ) | ||||
| else: | 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." | ||||
| ) | ) | ||||
| try: | |||||
| from swh.graph.client import RemoteGraphClient # optional dependency | |||||
| graph = RemoteGraphClient(**conf["graph"]) if conf.get("graph") else None | |||||
| except ModuleNotFoundError: | |||||
| if conf.get("graph"): | |||||
| raise EnvironmentError( | |||||
| "Graph configuration required but module is not installed." | |||||
| ) | |||||
| else: | |||||
| graph = None | |||||
| 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 | objstorage = get_objstorage(**conf["objstorage"]) if "objstorage" 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 = cooker_cls( | ||||
| obj_type=cooker_name, | obj_type=cooker_name, | ||||
| obj_id=swhid.object_id, | obj_id=swhid.object_id, | ||||
| backend=backend, | backend=backend, | ||||
| storage=storage, | storage=storage, | ||||
| graph=graph, | graph=graph, | ||||
| objstorage=objstorage, | objstorage=objstorage, | ||||
| ▲ Show 20 Lines • Show All 61 Lines • Show Last 20 Lines | |||||