Changeset View
Changeset View
Standalone View
Standalone View
swh/vault/cookers/base.py
Show First 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | class BaseVaultCooker(metaclass=abc.ABCMeta): | ||||
def __init__( | def __init__( | ||||
self, | self, | ||||
swhid: CoreSWHID, | swhid: CoreSWHID, | ||||
backend, | backend, | ||||
storage: StorageInterface, | storage: StorageInterface, | ||||
graph=None, | graph=None, | ||||
objstorage=None, | objstorage=None, | ||||
max_bundle_size: int = MAX_BUNDLE_SIZE, | max_bundle_size: int = MAX_BUNDLE_SIZE, | ||||
thread_pool_size: int = 10, | |||||
): | ): | ||||
"""Initialize the cooker. | """Initialize the cooker. | ||||
The type of the object represented by the id depends on the | The type of the object represented by the id depends on the | ||||
concrete class. Very likely, each type of bundle will have its | concrete class. Very likely, each type of bundle will have its | ||||
own cooker class. | own cooker class. | ||||
Args: | Args: | ||||
swhid: id of the object to be cooked into a bundle. | swhid: id of the object to be cooked into a bundle. | ||||
backend: the vault backend (swh.vault.backend.VaultBackend). | backend: the vault backend (swh.vault.backend.VaultBackend). | ||||
""" | """ | ||||
self.check_object_type(swhid.object_type) | self.check_object_type(swhid.object_type) | ||||
self.swhid = swhid | self.swhid = swhid | ||||
self.obj_id = swhid.object_id | self.obj_id = swhid.object_id | ||||
self.backend = backend | self.backend = backend | ||||
self.storage = storage | self.storage = storage | ||||
self.objstorage = objstorage | self.objstorage = objstorage | ||||
self.graph = graph | self.graph = graph | ||||
self.max_bundle_size = max_bundle_size | self.max_bundle_size = max_bundle_size | ||||
self.thread_pool_size = thread_pool_size | |||||
@classmethod | @classmethod | ||||
def check_object_type(cls, object_type: ObjectType) -> None: | def check_object_type(cls, object_type: ObjectType) -> None: | ||||
if object_type not in cls.SUPPORTED_OBJECT_TYPES: | if object_type not in cls.SUPPORTED_OBJECT_TYPES: | ||||
raise ValueError(f"{cls.__name__} does not support {object_type} objects.") | raise ValueError(f"{cls.__name__} does not support {object_type} objects.") | ||||
@abc.abstractmethod | @abc.abstractmethod | ||||
def check_exists(self): | def check_exists(self): | ||||
▲ Show 20 Lines • Show All 57 Lines • Show Last 20 Lines |