Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/interface.py
# Copyright (C) 2015-2020 The Software Heritage developers | # Copyright (C) 2015-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 | ||||
import datetime | import datetime | ||||
from enum import Enum | from enum import Enum | ||||
from typing import Dict, Iterable, List, Optional, Tuple, TypeVar, Union | from typing import Any, Dict, Iterable, List, Optional, Sequence, Tuple, TypeVar, Union | ||||
from swh.core.api import remote_api_endpoint | from swh.core.api import remote_api_endpoint | ||||
from swh.core.api.classes import PagedResult as CorePagedResult | from swh.core.api.classes import PagedResult as CorePagedResult | ||||
from swh.model.identifiers import SWHID | from swh.model.identifiers import SWHID | ||||
from swh.model.model import ( | from swh.model.model import ( | ||||
Content, | Content, | ||||
Directory, | Directory, | ||||
▲ Show 20 Lines • Show All 268 Lines • ▼ Show 20 Lines | def content_missing_per_sha1_git(self, contents): | ||||
contents (List): An iterable of content id (sha1_git) | contents (List): An iterable of content id (sha1_git) | ||||
Yields: | Yields: | ||||
missing contents sha1_git | missing contents sha1_git | ||||
""" | """ | ||||
... | ... | ||||
@remote_api_endpoint("content/present") | @remote_api_endpoint("content/present") | ||||
def content_find(self, content): | def content_find(self, content: Dict[str, Any]) -> Sequence[Content]: | ||||
"""Find a content hash in db. | """Find a content hash in db. | ||||
Args: | Args: | ||||
content: a dictionary representing one content hash, mapping | content: a dictionary representing one content hash, mapping | ||||
checksum algorithm names (see swh.model.hashutil.ALGORITHMS) to | checksum algorithm names (see swh.model.hashutil.ALGORITHMS) to | ||||
checksum values | checksum values | ||||
Returns: | |||||
a triplet (sha1, sha1_git, sha256) if the content exist | |||||
or None otherwise. | |||||
Raises: | Raises: | ||||
ValueError: in case the key of the dictionary is not sha1, sha1_git | ValueError: in case the key of the dictionary is not sha1, sha1_git | ||||
nor sha256. | nor sha256. | ||||
Returns: | |||||
an iterable of Content objects matching the search criteria if the | |||||
content exist. Empty iterable otherwise. | |||||
""" | """ | ||||
... | ... | ||||
@remote_api_endpoint("content/get_random") | @remote_api_endpoint("content/get_random") | ||||
def content_get_random(self) -> Sha1Git: | def content_get_random(self) -> Sha1Git: | ||||
"""Finds a random content id. | """Finds a random content id. | ||||
Returns: | Returns: | ||||
▲ Show 20 Lines • Show All 974 Lines • Show Last 20 Lines |