Changeset View
Changeset View
Standalone View
Standalone View
swh/provenance/__init__.py
from __future__ import annotations | ||||||||||
from typing import TYPE_CHECKING | from typing import TYPE_CHECKING | |||||||||
if TYPE_CHECKING: | if TYPE_CHECKING: | |||||||||
from .archive import ArchiveInterface | from .archive import ArchiveInterface | |||||||||
from .provenance import ProvenanceInterface, ProvenanceStorageInterface | from .provenance 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`. | ||||||||||
vlorentz: Docstrings must be in ReST (because they are used by Sphinx), not Markdown; and ReST uses… | ||||||||||
Args: | ||||||||||
cls: archive's class, either 'api' or 'direct' | ||||||||||
args: dictionary of arguments passed to the archive class constructor | ||||||||||
Returns: | ||||||||||
an instance of archive object (either using swh.storage API or direct | ||||||||||
queries to the archive's database) | ||||||||||
Raises: | ||||||||||
ValueError if passed an unknown archive class. | ||||||||||
""" | ||||||||||
if cls == "api": | if cls == "api": | |||||||||
from swh.storage import get_storage | from swh.storage import get_storage | |||||||||
from .storage.archive import ArchiveStorage | from .storage.archive import ArchiveStorage | |||||||||
return ArchiveStorage(get_storage(**kwargs["storage"])) | return ArchiveStorage(get_storage(**kwargs["storage"])) | |||||||||
elif cls == "direct": | elif cls == "direct": | |||||||||
from swh.core.db import BaseDb | from swh.core.db import BaseDb | |||||||||
from .postgresql.archive import ArchivePostgreSQL | from .postgresql.archive import ArchivePostgreSQL | |||||||||
return ArchivePostgreSQL(BaseDb.connect(**kwargs["db"]).conn) | return ArchivePostgreSQL(BaseDb.connect(**kwargs["db"]).conn) | |||||||||
else: | else: | |||||||||
raise NotImplementedError | raise ValueError | |||||||||
def get_provenance(**kwargs) -> ProvenanceInterface: | ||||||||||
"""Get an provenance object with arguments `args`. | ||||||||||
vlorentzUnsubmitted Done Inline Actionsditto vlorentz: ditto | ||||||||||
def get_provenance(**kwargs) -> "ProvenanceInterface": | Args: | |||||||||
args: dictionary of arguments to retrieve a swh.provenance.storage | ||||||||||
class (see `get_provenance_storage` for details) | ||||||||||
vlorentzUnsubmitted Done Inline Actions
this will link to the function's documentation vlorentz: this will link to the function's documentation | ||||||||||
Returns: | ||||||||||
an instance of provenance object | ||||||||||
""" | ||||||||||
from .backend import ProvenanceBackend | from .backend import ProvenanceBackend | |||||||||
return ProvenanceBackend(get_provenance_storage(**kwargs)) | return ProvenanceBackend(get_provenance_storage(**kwargs)) | |||||||||
def get_provenance_storage(cls: str, **kwargs) -> "ProvenanceStorageInterface": | def get_provenance_storage(cls: str, **kwargs) -> ProvenanceStorageInterface: | |||||||||
"""Get an archive object of class `cls` with arguments `args`. | ||||||||||
Args: | ||||||||||
cls: storage's class, only 'local' is currently supported | ||||||||||
args: dictionary of arguments passed to the storage class constructor | ||||||||||
Returns: | ||||||||||
an instance of storage object | ||||||||||
Raises: | ||||||||||
ValueError if passed an unknown archive class. | ||||||||||
vlorentzUnsubmitted Done Inline Actions
bug no big deal, it's a very common object vlorentz: bug no big deal, it's a very common object | ||||||||||
""" | ||||||||||
if cls == "local": | if cls == "local": | |||||||||
from swh.core.db import BaseDb | from swh.core.db import BaseDb | |||||||||
from .postgresql.provenancedb_base import ProvenanceDBBase | from .postgresql.provenancedb_base import ProvenanceDBBase | |||||||||
conn = BaseDb.connect(**kwargs["db"]).conn | conn = BaseDb.connect(**kwargs["db"]).conn | |||||||||
flavor = ProvenanceDBBase(conn).flavor | if ProvenanceDBBase(conn).flavor == "with-path": | |||||||||
if flavor == "with-path": | ||||||||||
from .postgresql.provenancedb_with_path import ProvenanceWithPathDB | from .postgresql.provenancedb_with_path import ProvenanceWithPathDB | |||||||||
return ProvenanceWithPathDB(conn) | return ProvenanceWithPathDB(conn) | |||||||||
else: | else: | |||||||||
from .postgresql.provenancedb_without_path import ProvenanceWithoutPathDB | from .postgresql.provenancedb_without_path import ProvenanceWithoutPathDB | |||||||||
return ProvenanceWithoutPathDB(conn) | return ProvenanceWithoutPathDB(conn) | |||||||||
else: | else: | |||||||||
raise NotImplementedError | raise ValueError |
Docstrings must be in ReST (because they are used by Sphinx), not Markdown; and ReST uses single backquotes for links
(ditto for the other occurences below)