Changeset View
Changeset View
Standalone View
Standalone View
swh/provenance/__init__.py
# Copyright (C) 2021 The Software Heritage developers | # Copyright (C) 2021 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 | ||||
from typing import TYPE_CHECKING | from typing import TYPE_CHECKING | ||||
import warnings | |||||
if TYPE_CHECKING: | if TYPE_CHECKING: | ||||
from .archive import ArchiveInterface | from .archive import ArchiveInterface | ||||
from .interface import ProvenanceInterface, ProvenanceStorageInterface | from .interface import ProvenanceInterface, ProvenanceStorageInterface | ||||
def get_archive(cls: str, **kwargs) -> ArchiveInterface: | def get_archive(cls: str, **kwargs) -> ArchiveInterface: | ||||
"""Get an archive object of class ``cls`` with arguments ``args``. | """Get an archive object of class ``cls`` with arguments ``args``. | ||||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | Args: | ||||
args: dictionary of arguments passed to the storage class constructor | args: dictionary of arguments passed to the storage class constructor | ||||
Returns: | Returns: | ||||
an instance of storage object | an instance of storage object | ||||
Raises: | Raises: | ||||
:cls:`ValueError` if passed an unknown archive class. | :cls:`ValueError` if passed an unknown archive class. | ||||
""" | """ | ||||
if cls == "local": | if cls in ["local", "postgresql"]: | ||||
douardda: please keep support for the former name with a deprecation warning | |||||
from swh.core.db import BaseDb | from swh.core.db import BaseDb | ||||
from .postgresql.provenancedb import ProvenanceDB | from .postgresql.provenance import ProvenanceStoragePostgreSql | ||||
if cls == "local": | |||||
warnings.warn( | |||||
'"local" class is deprecated for provenance storage, please ' | |||||
'use "postgresql" class instead.', | |||||
DeprecationWarning, | |||||
) | |||||
conn = BaseDb.connect(**kwargs["db"]).conn | conn = BaseDb.connect(**kwargs["db"]).conn | ||||
raise_on_commit = kwargs.get("raise_on_commit", False) | raise_on_commit = kwargs.get("raise_on_commit", False) | ||||
return ProvenanceDB(conn, raise_on_commit) | return ProvenanceStoragePostgreSql(conn, raise_on_commit) | ||||
elif cls == "remote": | elif cls == "remote": | ||||
from .api.client import RemoteProvenanceStorage | from .api.client import RemoteProvenanceStorage | ||||
storage = RemoteProvenanceStorage(**kwargs) | storage = RemoteProvenanceStorage(**kwargs) | ||||
assert isinstance(storage, ProvenanceStorageInterface) | assert isinstance(storage, ProvenanceStorageInterface) | ||||
return storage | return storage | ||||
else: | else: | ||||
raise ValueError | raise ValueError |
please keep support for the former name with a deprecation warning