Page MenuHomeSoftware Heritage

D191.id597.diff
No OneTemporary

D191.id597.diff

diff --git a/swh/storage/vault/cookers/base.py b/swh/storage/vault/cookers/base.py
--- a/swh/storage/vault/cookers/base.py
+++ b/swh/storage/vault/cookers/base.py
@@ -52,6 +52,13 @@
self.cache = cache
@abc.abstractmethod
+ def prepare_bundle(self, obj_id):
+ """Implementation of the cooker. Returns the bundle bytes.
+
+ Override this with the cooker implementation.
+ """
+ raise NotImplemented
+
def cook(self, obj_id):
"""Cook the requested object into a bundle
@@ -63,7 +70,15 @@
obj_id: id of the object to be cooked into a bundle.
"""
- pass
+ bundle_content = self.prepare_bundle(obj_id)
+
+ # Cache the bundle
+ self.update_cache(obj_id, bundle_content)
+ # Make a notification that the bundle have been cooked
+ # NOT YET IMPLEMENTED see TODO in function.
+ self.notify_bundle_ready(
+ notif_data='Bundle %s ready' % hashutil.hash_to_hex(obj_id),
+ bundle_id=obj_id)
def update_cache(self, id, bundle_content):
"""Update the cache with id and bundle_content.
@@ -71,11 +86,9 @@
"""
self.cache.add(self.CACHE_TYPE_KEY, id, bundle_content)
- @abc.abstractmethod
def notify_bundle_ready(self, notif_data, bundle_id):
- """Notify the bundle bundle_id is ready.
-
- """
+ # TODO plug this method with the notification method once
+ # done.
pass
diff --git a/swh/storage/vault/cookers/directory.py b/swh/storage/vault/cookers/directory.py
--- a/swh/storage/vault/cookers/directory.py
+++ b/swh/storage/vault/cookers/directory.py
@@ -4,14 +4,13 @@
# See top-level LICENSE file for more information
from .base import BaseVaultCooker, DirectoryBuilder
-from swh.core import hashutil
class DirectoryCooker(BaseVaultCooker):
"""Cooker to create a directory bundle """
CACHE_TYPE_KEY = 'directory'
- def cook(self, obj_id):
+ def prepare_bundle(self, obj_id):
"""Cook the requested directory into a Bundle
Args:
@@ -21,19 +20,5 @@
bytes that correspond to the bundle
"""
- # Create the bytes that corresponds to the compressed
- # directory.
directory_builder = DirectoryBuilder(self.storage)
- bundle_content = directory_builder.get_directory_bytes(obj_id)
- # Cache the bundle
- self.update_cache(obj_id, bundle_content)
- # Make a notification that the bundle have been cooked
- # NOT YET IMPLEMENTED see TODO in function.
- self.notify_bundle_ready(
- notif_data='Bundle %s ready' % hashutil.hash_to_hex(obj_id),
- bundle_id=obj_id)
-
- def notify_bundle_ready(self, notif_data, bundle_id):
- # TODO plug this method with the notification method once
- # done.
- pass
+ return directory_builder.get_directory_bytes(obj_id)
diff --git a/swh/storage/vault/cookers/revision_flat.py b/swh/storage/vault/cookers/revision_flat.py
--- a/swh/storage/vault/cookers/revision_flat.py
+++ b/swh/storage/vault/cookers/revision_flat.py
@@ -15,7 +15,7 @@
"""Cooker to create a directory bundle """
CACHE_TYPE_KEY = 'revision_flat'
- def cook(self, obj_id):
+ def prepare_bundle(self, obj_id):
"""Cook the requested revision into a Bundle
Args:
@@ -33,17 +33,4 @@
revdir.mkdir()
directory_builder.build_directory(revision['directory'],
str(revdir).encode())
- bundle_content = get_tar_bytes(root_tmp,
- hashutil.hash_to_hex(obj_id))
- # Cache the bundle
- self.update_cache(obj_id, bundle_content)
- # Make a notification that the bundle have been cooked
- # NOT YET IMPLEMENTED see TODO in function.
- self.notify_bundle_ready(
- notif_data='Bundle %s ready' % hashutil.hash_to_hex(obj_id),
- bundle_id=obj_id)
-
- def notify_bundle_ready(self, notif_data, bundle_id):
- # TODO plug this method with the notification method once
- # done.
- pass
+ return get_tar_bytes(root_tmp, hashutil.hash_to_hex(obj_id))

File Metadata

Mime Type
text/plain
Expires
Nov 5 2024, 11:48 AM (12 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3220023

Event Timeline