Mercurial > hgrepos > Python > apps > py-cutils
comparison cutils/treesum.py @ 336:0049f486e1cd
treesum: Also provide the WriterBase with flags when printing sizes
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 31 Mar 2025 12:57:39 +0200 |
| parents | 7620142aacd1 |
| children | e89eb63fc319 |
comparison
equal
deleted
inserted
replaced
| 335:7620142aacd1 | 336:0049f486e1cd |
|---|---|
| 558 else: | 558 else: |
| 559 raise NotImplementedError("`output_style'") | 559 raise NotImplementedError("`output_style'") |
| 560 | 560 |
| 561 with out_cm as outfp: | 561 with out_cm as outfp: |
| 562 writer = writerstyle(outfp, | 562 writer = writerstyle(outfp, |
| 563 size_only=opts.size_only, | |
| 564 print_size=opts.print_size, | |
| 563 use_base64=opts.base64, | 565 use_base64=opts.base64, |
| 564 grouping_separator=opts.grouping_separator | 566 grouping_separator=opts.grouping_separator |
| 565 ) | 567 ) |
| 566 for d in opts.directories: | 568 for d in opts.directories: |
| 567 V1DirectoryTreesumGenerator( | 569 V1DirectoryTreesumGenerator( |
| 1296 return modestr | 1298 return modestr |
| 1297 | 1299 |
| 1298 | 1300 |
| 1299 class WriterBase(object): | 1301 class WriterBase(object): |
| 1300 | 1302 |
| 1301 """Base class for all treesum digest file writers. | 1303 """(Abstract) base class for all treesum digest file writers. |
| 1302 | 1304 |
| 1303 Wraps an output file pointer for a binary file. | 1305 Wraps an output file pointer for a binary file. |
| 1304 | 1306 |
| 1305 Provides low-level methods to write data lines. These methods must be | 1307 Provides low-level methods to write data lines. These methods must be |
| 1306 used if the CRC is to be updated also. | 1308 used if the CRC is to be updated also. |
| 1317 separator for you OS as bytes""" | 1319 separator for you OS as bytes""" |
| 1318 | 1320 |
| 1319 DEFAULT_GROUPING_SEPARATOR = "" | 1321 DEFAULT_GROUPING_SEPARATOR = "" |
| 1320 """Disable the thousands separator in case no subclass redefines it""" | 1322 """Disable the thousands separator in case no subclass redefines it""" |
| 1321 | 1323 |
| 1322 def __init__(self, outfp, use_base64=False, grouping_separator=None, | 1324 def __init__(self, outfp, size_only=False, print_size=False, |
| 1325 use_base64=False, grouping_separator=None, | |
| 1323 size_column_width=None): | 1326 size_column_width=None): |
| 1327 # Poor man's abstract abstract class implemenetation | |
| 1328 assert self.__class__ is not WriterBase | |
| 1329 | |
| 1324 self._outfp = outfp | 1330 self._outfp = outfp |
| 1331 self.size_only = size_only | |
| 1332 self.print_size = print_size | |
| 1325 self.use_base64 = use_base64 | 1333 self.use_base64 = use_base64 |
| 1326 self.grouping_separator = (grouping_separator | 1334 self.grouping_separator = (grouping_separator |
| 1327 if grouping_separator is not None | 1335 if grouping_separator is not None |
| 1328 else self.DEFAULT_GROUPING_SEPARATOR) | 1336 else self.DEFAULT_GROUPING_SEPARATOR) |
| 1329 self.size_column_width = size_column_width or 0 | 1337 self.size_column_width = size_column_width or 0 |
| 1330 self.reset_crc() | 1338 self.reset_crc() |
| 1339 | |
| 1340 def write_size(self, filename, sz): | |
| 1341 """ | |
| 1342 | |
| 1343 If `sz` is `None` then this is signals an error because a size is | |
| 1344 required. | |
| 1345 | |
| 1346 """ | |
| 1347 raise NotImplementedError("write_size") | |
| 1348 | |
| 1349 def write_file_digest(self, algorithm, filename, digest, size=None): | |
| 1350 """ | |
| 1351 | |
| 1352 If `size` is `None` and the output of a size is required then this | |
| 1353 is an error signal. | |
| 1354 | |
| 1355 """ | |
| 1356 raise NotImplementedError("write_file_digest") | |
| 1331 | 1357 |
| 1332 @property | 1358 @property |
| 1333 def crc(self): | 1359 def crc(self): |
| 1334 return self._crc | 1360 return self._crc |
| 1335 | 1361 |
