Changeset View
Changeset View
Standalone View
Standalone View
swh/provenance/__init__.py
from .archive import ArchiveInterface | from typing import TYPE_CHECKING | ||||
from .postgresql.archive import ArchivePostgreSQL | |||||
from .postgresql.db_utils import connect | from .postgresql.db_utils import connect | ||||
from .storage.archive import ArchiveStorage | |||||
from .provenance import ProvenanceInterface | if TYPE_CHECKING: | ||||
from swh.provenance.archive import ArchiveInterface | |||||
from swh.provenance.provenance import ProvenanceInterface | |||||
def get_archive(cls: str, **kwargs) -> ArchiveInterface: | def get_archive(cls: str, **kwargs) -> "ArchiveInterface": | ||||
if cls == "api": | if cls == "api": | ||||
from swh.provenance.storage.archive import ArchiveStorage | |||||
return ArchiveStorage(**kwargs["storage"]) | return ArchiveStorage(**kwargs["storage"]) | ||||
elif cls == "direct": | elif cls == "direct": | ||||
from swh.provenance.postgresql.archive import ArchivePostgreSQL | |||||
conn = connect(kwargs["db"]) | conn = connect(kwargs["db"]) | ||||
return ArchivePostgreSQL(conn) | return ArchivePostgreSQL(conn) | ||||
else: | else: | ||||
raise NotImplementedError | raise NotImplementedError | ||||
def get_provenance(cls: str, **kwargs) -> ProvenanceInterface: | def get_provenance(cls: str, **kwargs) -> "ProvenanceInterface": | ||||
if cls == "local": | if cls == "local": | ||||
conn = connect(kwargs["db"]) | conn = connect(kwargs["db"]) | ||||
if kwargs.get("with_path", True): | if kwargs.get("with_path", True): | ||||
from .postgresql.provenance_with_path import ProvenanceWithPathDB | from swh.provenance.postgresql.provenancedb_with_path import ( | ||||
ProvenanceWithPathDB, | |||||
) | |||||
return ProvenanceWithPathDB(conn) | return ProvenanceWithPathDB(conn) | ||||
else: | else: | ||||
from .postgresql.provenance_without_path import ProvenanceWithoutPathDB | from swh.provenance.postgresql.provenancedb_without_path import ( | ||||
ProvenanceWithoutPathDB, | |||||
) | |||||
return ProvenanceWithoutPathDB(conn) | return ProvenanceWithoutPathDB(conn) | ||||
else: | else: | ||||
raise NotImplementedError | raise NotImplementedError |