Add a reporter for verbs to track number of storage streams are needed

This commit is contained in:
Joseph Schorr 2018-03-23 14:39:38 -04:00
parent 110366f656
commit dd470bdc9d
7 changed files with 43 additions and 14 deletions

View file

@ -6,6 +6,7 @@ from abc import ABCMeta, abstractmethod
from collections import defaultdict
from six import add_metaclass
from util.abchelpers import nooper
class TarLayerReadException(Exception):
""" Exception raised when reading a layer has failed. """
@ -15,13 +16,26 @@ class TarLayerReadException(Exception):
# 9MB (+ padding below) so that it matches the 10MB expected by Gzip.
CHUNK_SIZE = 1024 * 1024 * 9
@add_metaclass(ABCMeta)
class TarLayerFormatterReporter(object):
@abstractmethod
def report_pass(self, stream_count):
""" Reports a formatting pass. """
pass
@nooper
class NoopReporter(TarLayerFormatterReporter):
pass
@add_metaclass(ABCMeta)
class TarLayerFormat(object):
""" Class which creates a generator of the combined TAR data. """
def __init__(self, tar_stream_getter_iterator, path_prefix=None):
def __init__(self, tar_stream_getter_iterator, path_prefix=None, reporter=None):
self.tar_stream_getter_iterator = tar_stream_getter_iterator
self.path_prefix = path_prefix or ''
self.reporter = reporter or NoopReporter()
def get_generator(self):
for stream_getter in self.tar_stream_getter_iterator():
@ -115,6 +129,7 @@ class TarLayerFormat(object):
# Conduct any post-tar work.
self.after_tar_layer()
self.reporter.report_pass(2 if len(dangling_hard_links) > 0 else 1)
# Last two records are empty in TAR spec.
yield '\0' * 512