Changeset View
Changeset View
Standalone View
Standalone View
swh/vault/cookers/base.py
Show First 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | def __init__(self, config, obj_type, obj_id): | ||||
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: | ||||
storage: the storage object | storage: the storage object | ||||
cache: the cache where to store the bundle | cache: the cache where to store the bundle | ||||
obj_id: id of the object to be cooked into a bundle. | obj_id: id of the object to be cooked into a bundle. | ||||
""" | """ | ||||
self.config = config | |||||
self.obj_type = obj_type | |||||
self.obj_id = hashutil.hash_to_bytes(obj_id) | |||||
def __enter__(self): | |||||
# Imported here to avoid circular dependency | # Imported here to avoid circular dependency | ||||
from swh.vault.backend import VaultBackend | from swh.vault.backend import VaultBackend | ||||
self.backend = VaultBackend(self.config) | |||||
self.storage = get_storage(**self.config['storage']) | |||||
return self | |||||
self.storage = get_storage(**config['storage']) | def __exit__(self, *_): | ||||
self.backend = VaultBackend(config) | self.backend.close() | ||||
self.obj_type = obj_type | |||||
self.obj_id = hashutil.hash_to_bytes(obj_id) | |||||
@abc.abstractmethod | @abc.abstractmethod | ||||
def check_exists(self): | def check_exists(self): | ||||
"""Checks that the requested object exists and can be cooked. | """Checks that the requested object exists and can be cooked. | ||||
Override this in the cooker implementation. | Override this in the cooker implementation. | ||||
""" | """ | ||||
raise NotImplemented | raise NotImplemented | ||||
▲ Show 20 Lines • Show All 157 Lines • Show Last 20 Lines |