# HG changeset patch # User Franz Glasner # Date 1743418659 -7200 # Node ID 0049f486e1cdf33658bec6d3c598a58de494fcc2 # Parent 7620142aacd1eb116490cf2db4f1b2e7f0e88ddd treesum: Also provide the WriterBase with flags when printing sizes diff -r 7620142aacd1 -r 0049f486e1cd cutils/treesum.py --- a/cutils/treesum.py Mon Mar 31 09:02:43 2025 +0200 +++ b/cutils/treesum.py Mon Mar 31 12:57:39 2025 +0200 @@ -560,6 +560,8 @@ with out_cm as outfp: writer = writerstyle(outfp, + size_only=opts.size_only, + print_size=opts.print_size, use_base64=opts.base64, grouping_separator=opts.grouping_separator ) @@ -1298,7 +1300,7 @@ class WriterBase(object): - """Base class for all treesum digest file writers. + """(Abstract) base class for all treesum digest file writers. Wraps an output file pointer for a binary file. @@ -1319,9 +1321,15 @@ DEFAULT_GROUPING_SEPARATOR = "" """Disable the thousands separator in case no subclass redefines it""" - def __init__(self, outfp, use_base64=False, grouping_separator=None, + def __init__(self, outfp, size_only=False, print_size=False, + use_base64=False, grouping_separator=None, size_column_width=None): + # Poor man's abstract abstract class implemenetation + assert self.__class__ is not WriterBase + self._outfp = outfp + self.size_only = size_only + self.print_size = print_size self.use_base64 = use_base64 self.grouping_separator = (grouping_separator if grouping_separator is not None @@ -1329,6 +1337,24 @@ self.size_column_width = size_column_width or 0 self.reset_crc() + def write_size(self, filename, sz): + """ + + If `sz` is `None` then this is signals an error because a size is + required. + + """ + raise NotImplementedError("write_size") + + def write_file_digest(self, algorithm, filename, digest, size=None): + """ + + If `size` is `None` and the output of a size is required then this + is an error signal. + + """ + raise NotImplementedError("write_file_digest") + @property def crc(self): return self._crc