comparison cutils/treesum.py @ 306:ebddfdbc3f7a

treesum: use a callback to print parsed .treesum output file infos
author Franz Glasner <fzglas.hg@dom66.de>
date Wed, 05 Mar 2025 14:05:38 +0100
parents 73d13be531b5
children 64df94bf4659
comparison
equal deleted inserted replaced
305:6c212e407524 306:ebddfdbc3f7a
1517 self._current_algo_digest_size = h.digest_size 1517 self._current_algo_digest_size = h.digest_size
1518 return self._current_algo_digest_size 1518 return self._current_algo_digest_size
1519 1519
1520 1520
1521 def print_treesum_digestfile_infos(opts): 1521 def print_treesum_digestfile_infos(opts):
1522 print_infos_for_digestfile(opts.digest_files, opts.print_only_last_block) 1522 get_infos_from_digestfile(
1523 1523 opts.digest_files,
1524 1524 print_block_data,
1525 def print_infos_for_digestfile(digest_files, print_only_last_block=True): 1525 opts.print_only_last_block)
1526
1527
1528 def get_infos_from_digestfile(digest_files, block_handler,
1529 only_last_block=True):
1526 for fn in digest_files: 1530 for fn in digest_files:
1527 if fn == "-": 1531 if fn == "-":
1528 if util.PY2: 1532 if util.PY2:
1529 reader = TreesumReader.from_binary_buffer(sys.stdin) 1533 reader = TreesumReader.from_binary_buffer(sys.stdin)
1530 else: 1534 else:
1578 size = record[2] 1582 size = record[2]
1579 else: 1583 else:
1580 algorithm = record[0] 1584 algorithm = record[0]
1581 digest = record[2] 1585 digest = record[2]
1582 size = record[3] 1586 size = record[3]
1583 if not print_only_last_block: 1587 if not only_last_block:
1584 print_block_data( 1588 block_handler(
1585 block_no, 1589 block_no,
1586 root, generator, fsencoding, flags, 1590 root, generator, fsencoding, flags,
1587 fnmatch_filters, 1591 fnmatch_filters,
1588 comments, errors, algorithm, digest, size) 1592 comments, errors, algorithm, digest, size)
1589 root = generator = flags = fsencoding = algorithm \ 1593 root = generator = flags = fsencoding = algorithm \
1590 = digest = size = None 1594 = digest = size = None
1591 errors = set() 1595 errors = set()
1592 comments = [] 1596 comments = []
1593 in_block = False 1597 in_block = False
1594 if print_only_last_block: 1598 if only_last_block:
1595 if not in_block: 1599 if not in_block:
1596 if digest is not None or size is not None: 1600 if digest is not None or size is not None:
1597 print_block_data( 1601 block_handler(
1598 block_no, 1602 block_no,
1599 root, generator, fsencoding, flags, fnmatch_filters, 1603 root, generator, fsencoding, flags, fnmatch_filters,
1600 comments, errors, algorithm, digest, size) 1604 comments, errors, algorithm, digest, size)
1601 else: 1605 else:
1602 logging.warning("missing block end") 1606 logging.warning("missing block end")