Changeset View
Changeset View
Standalone View
Standalone View
swh/vault/cookers/__init__.py
# Copyright (C) 2017-2020 The Software Heritage developers | # Copyright (C) 2017-2020 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
from __future__ import annotations | from __future__ import annotations | ||||
import os | import os | ||||
from typing import Any, Dict | from typing import Any, Dict | ||||
from swh.core.config import load_named_config | from swh.core.config import load_named_config | ||||
from swh.core.config import read as read_config | from swh.core.config import read as read_config | ||||
from swh.graph.client import RemoteGraphClient | |||||
from swh.storage import get_storage | from swh.storage import get_storage | ||||
from swh.vault import get_vault | from swh.vault import get_vault | ||||
from swh.vault.cookers.base import DEFAULT_CONFIG, DEFAULT_CONFIG_PATH | from swh.vault.cookers.base import DEFAULT_CONFIG, DEFAULT_CONFIG_PATH | ||||
from swh.vault.cookers.directory import DirectoryCooker | from swh.vault.cookers.directory import DirectoryCooker | ||||
from swh.vault.cookers.git_bare import GitBareCooker | |||||
from swh.vault.cookers.revision_flat import RevisionFlatCooker | from swh.vault.cookers.revision_flat import RevisionFlatCooker | ||||
from swh.vault.cookers.revision_gitfast import RevisionGitfastCooker | from swh.vault.cookers.revision_gitfast import RevisionGitfastCooker | ||||
COOKER_TYPES = { | COOKER_TYPES = { | ||||
"directory": DirectoryCooker, | "directory": DirectoryCooker, | ||||
"revision_flat": RevisionFlatCooker, | "revision_flat": RevisionFlatCooker, | ||||
"revision_gitfast": RevisionGitfastCooker, | "revision_gitfast": RevisionGitfastCooker, | ||||
"revision_git_bare": GitBareCooker, | |||||
"directory_git_bare": GitBareCooker, | |||||
} | } | ||||
def get_cooker_cls(obj_type): | def get_cooker_cls(obj_type): | ||||
return COOKER_TYPES[obj_type] | return COOKER_TYPES[obj_type] | ||||
def check_config(cfg: Dict[str, Any]) -> Dict[str, Any]: | def check_config(cfg: Dict[str, Any]) -> Dict[str, Any]: | ||||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | else: | ||||
cfg = load_named_config(DEFAULT_CONFIG_PATH, DEFAULT_CONFIG) | cfg = load_named_config(DEFAULT_CONFIG_PATH, DEFAULT_CONFIG) | ||||
cooker_cls = get_cooker_cls(obj_type) | cooker_cls = get_cooker_cls(obj_type) | ||||
cfg = check_config(cfg) | cfg = check_config(cfg) | ||||
vcfg = cfg["vault"] | vcfg = cfg["vault"] | ||||
storage = get_storage(**vcfg.pop("storage")) | storage = get_storage(**vcfg.pop("storage")) | ||||
backend = get_vault(**vcfg) | backend = get_vault(**vcfg) | ||||
graph = RemoteGraphClient(**vcfg["graph"]) if "graph" in vcfg else None | |||||
return cooker_cls( | return cooker_cls( | ||||
obj_type, | obj_type, | ||||
obj_id, | obj_id, | ||||
backend=backend, | backend=backend, | ||||
storage=storage, | storage=storage, | ||||
graph=graph, | |||||
max_bundle_size=cfg["max_bundle_size"], | max_bundle_size=cfg["max_bundle_size"], | ||||
) | ) |