Changeset View
Changeset View
Standalone View
Standalone View
swh/objstorage/objstorage.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 abc | import abc | ||||
import bz2 | import bz2 | ||||
from itertools import dropwhile, islice | from itertools import dropwhile, islice | ||||
import lzma | import lzma | ||||
from typing import Callable, Dict, Iterable, Iterator, List, Optional | from typing import Callable, Dict, Iterator, List, Optional | ||||
import zlib | import zlib | ||||
from swh.model import hashutil | from swh.model import hashutil | ||||
from .constants import DEFAULT_LIMIT, ID_HASH_ALGO | from .constants import DEFAULT_LIMIT, ID_HASH_ALGO | ||||
from .exc import ObjNotFoundError | from .exc import ObjNotFoundError | ||||
from .interface import ObjId, ObjStorageInterface | from .interface import ObjId, ObjStorageInterface | ||||
▲ Show 20 Lines • Show All 97 Lines • ▼ Show 20 Lines | ) -> Iterator[Optional[bytes]]: | ||||
except ObjNotFoundError: | except ObjNotFoundError: | ||||
yield None | yield None | ||||
@abc.abstractmethod | @abc.abstractmethod | ||||
def delete(self, obj_id: ObjId): | def delete(self, obj_id: ObjId): | ||||
if not self.allow_delete: | if not self.allow_delete: | ||||
raise PermissionError("Delete is not allowed.") | raise PermissionError("Delete is not allowed.") | ||||
def get_random(self, batch_size: int) -> Iterable[ObjId]: | |||||
pass | |||||
def list_content( | def list_content( | ||||
self: ObjStorageInterface, | self: ObjStorageInterface, | ||||
last_obj_id: Optional[ObjId] = None, | last_obj_id: Optional[ObjId] = None, | ||||
limit: int = DEFAULT_LIMIT, | limit: int = DEFAULT_LIMIT, | ||||
) -> Iterator[ObjId]: | ) -> Iterator[ObjId]: | ||||
it = iter(self) | it = iter(self) | ||||
if last_obj_id is not None: | if last_obj_id is not None: | ||||
it = dropwhile(last_obj_id.__ge__, it) | it = dropwhile(last_obj_id.__ge__, it) | ||||
return islice(it, limit) | return islice(it, limit) |