From e5b430cb8c7c30b144f6ab5c8699187597f34e0a Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Sat, 5 Apr 2025 17:59:35 -0500 Subject: [PATCH] scripts: Adopted -q/--quiet in most debug scripts This can be useful when you just want to check for errors. The only exception being dbgblock.py/dbgcat.py, since these don't really have a concept of an error. --- scripts/dbgbtree.py | 40 +++++++++++++++---------- scripts/dbgmtree.py | 73 ++++++++++++++++++++++++++------------------- scripts/dbgrbyd.py | 22 +++++++++----- 3 files changed, 80 insertions(+), 55 deletions(-) diff --git a/scripts/dbgbtree.py b/scripts/dbgbtree.py index e953b140..6e2df604 100755 --- a/scripts/dbgbtree.py +++ b/scripts/dbgbtree.py @@ -1681,6 +1681,7 @@ def main(disk, roots=None, *, trunk=None, block_size=None, block_count=None, + quiet=False, color='auto', **args): # figure out what color should be @@ -1724,11 +1725,12 @@ def main(disk, roots=None, *, btree = Btree.fetch(bd, roots, trunk) # print some information about the btree - print('btree %s w%d, rev %08x, cksum %08x' % ( - btree.addr(), - btree.weight, - btree.rev, - btree.cksum)) + if not quiet: + print('btree %s w%d, rev %08x, cksum %08x' % ( + btree.addr(), + btree.weight, + btree.rev, + btree.cksum)) # precompute tree renderings t_width = 0 @@ -1792,7 +1794,7 @@ def main(disk, roots=None, *, path=True, depth=args.get('depth')): # print inner branches if requested - if args.get('inner'): + if args.get('inner') and not quiet: for d, (bid_, rbyd_, rid_, name_) in pathdelta( path, ppath): dbg_branch(d, bid_, rbyd_, rid_, name_) @@ -1800,20 +1802,22 @@ def main(disk, roots=None, *, # corrupted? try to keep printing the tree if not rbyd: - print('%04x.%04x: %*s%s%s%s' % ( - rbyd.block, rbyd.trunk, - t_width, '', - '\x1b[31m' if color else '', - '(corrupted rbyd %s)' % rbyd.addr(), - '\x1b[m' if color else '')) + if not quiet: + print('%04x.%04x: %*s%s%s%s' % ( + rbyd.block, rbyd.trunk, + t_width, '', + '\x1b[31m' if color else '', + '(corrupted rbyd %s)' % rbyd.addr(), + '\x1b[m' if color else '')) prbyd = None corrupted = True continue - for rid, name in rbyd.rids(): - bid_ = bid-(rbyd.weight-1) + rid - # show the leaf entry/branch - dbg_branch(len(path), bid_, rbyd, rid, name) + if not quiet: + for rid, name in rbyd.rids(): + bid_ = bid-(rbyd.weight-1) + rid + # show the leaf entry/branch + dbg_branch(len(path), bid_, rbyd, rid, name) if args.get('error_on_corrupt') and corrupted: sys.exit(2) @@ -1845,6 +1849,10 @@ if __name__ == "__main__": '--block-count', type=lambda x: int(x, 0), help="Block count in blocks.") + parser.add_argument( + '-q', '--quiet', + action='store_true', + help="Don't show anything, useful when checking for errors.") parser.add_argument( '--color', choices=['never', 'always', 'auto'], diff --git a/scripts/dbgmtree.py b/scripts/dbgmtree.py index 86ca1644..a6ea902e 100755 --- a/scripts/dbgmtree.py +++ b/scripts/dbgmtree.py @@ -2800,6 +2800,7 @@ def main(disk, mroots=None, *, trunk=None, block_size=None, block_count=None, + quiet=False, color='auto', **args): # figure out what color should be @@ -2844,11 +2845,12 @@ def main(disk, mroots=None, *, depth=args.get('depth')) # print some information about the mtree - print('mtree %s w%s.%s, rev %08x, cksum %08x' % ( - mtree.addr(), - mtree.mbweightrepr(), mtree.mrweightrepr(), - mtree.rev, - mtree.cksum)) + if not quiet: + print('mtree %s w%s.%s, rev %08x, cksum %08x' % ( + mtree.addr(), + mtree.mbweightrepr(), mtree.mrweightrepr(), + mtree.rev, + mtree.cksum)) # precompute tree renderings t_width = 0 @@ -2976,7 +2978,7 @@ def main(disk, mroots=None, *, path=True, depth=args.get('depth')): # print inner branches if requested - if args.get('inner'): + if args.get('inner') and not quiet: for d, (bid_, rbyd_, rid_, name_) in pathdelta( # skip the mrootchain path[len(mtree.mrootchain):], @@ -2989,14 +2991,15 @@ def main(disk, mroots=None, *, if isinstance(mdir, Mdir): # corrupted? if not mdir: - print('{%s}: %s%s%s' % ( - ','.join('%04x' % block - for block in mdir.blocks), - '\x1b[31m' if color else '', - '(corrupted %s %s)' % ( - 'mroot' if mdir.mid == -1 else 'mdir', - mdir.addr()), - '\x1b[m' if color else '')) + if not quiet: + print('{%s}: %s%s%s' % ( + ','.join('%04x' % block + for block in mdir.blocks), + '\x1b[31m' if color else '', + '(corrupted %s %s)' % ( + 'mroot' if mdir.mid == -1 else 'mdir', + mdir.addr()), + '\x1b[m' if color else '')) pmdir = None corrupted = True continue @@ -3004,39 +3007,43 @@ def main(disk, mroots=None, *, # cycle detected? if mdir.mid == -1: if mdir in mrootseen: - print('{%s}: %s%s%s' % ( - ','.join('%04x' % block - for block in mdir.blocks), - '\x1b[31m' if color else '', - '(mroot cycle detected %s)' % mdir.addr(), - '\x1b[m' if color else '')) + if not quiet: + print('{%s}: %s%s%s' % ( + ','.join('%04x' % block + for block in mdir.blocks), + '\x1b[31m' if color else '', + '(mroot cycle detected %s)' % mdir.addr(), + '\x1b[m' if color else '')) pmdir = None corrupted = True continue mrootseen.add(mdir) # show the mdir - dbg_mdir(len(path), mdir) + if not quiet: + dbg_mdir(len(path), mdir) # btree node? else: bid, rbyd = mdir # corrupted? try to keep printing the tree if not rbyd: - print('%11s: %*s%s%s%s' % ( - '%04x.%04x' % (rbyd.block, rbyd.trunk), - t_width, '', - '\x1b[31m' if color else '', - '(corrupted rbyd %s)' % rbyd.addr(), - '\x1b[m' if color else '')) + if not quiet: + print('%11s: %*s%s%s%s' % ( + '%04x.%04x' % (rbyd.block, rbyd.trunk), + t_width, '', + '\x1b[31m' if color else '', + '(corrupted rbyd %s)' % rbyd.addr(), + '\x1b[m' if color else '')) pmdir = None corrupted = True continue - for rid, name in rbyd.rids(): - bid_ = bid-(rbyd.weight-1) + rid - # show the leaf entry/branch - dbg_branch(len(path), bid_, rbyd, rid, name) + if not quiet: + for rid, name in rbyd.rids(): + bid_ = bid-(rbyd.weight-1) + rid + # show the leaf entry/branch + dbg_branch(len(path), bid_, rbyd, rid, name) if args.get('error_on_corrupt') and corrupted: sys.exit(2) @@ -3068,6 +3075,10 @@ if __name__ == "__main__": '--block-count', type=lambda x: int(x, 0), help="Block count in blocks.") + parser.add_argument( + '-q', '--quiet', + action='store_true', + help="Don't show anything, useful when checking for errors.") parser.add_argument( '--color', choices=['never', 'always', 'auto'], diff --git a/scripts/dbgrbyd.py b/scripts/dbgrbyd.py index 192fa2fc..72631713 100755 --- a/scripts/dbgrbyd.py +++ b/scripts/dbgrbyd.py @@ -1673,6 +1673,7 @@ def main(disk, blocks=None, *, trunk=None, block_size=None, block_count=None, + quiet=False, color='auto', **args): # figure out what color should be @@ -1715,18 +1716,19 @@ def main(disk, blocks=None, *, rbyd = Rbyd.fetch(bd, blocks, trunk) # print some information about the rbyd - print('rbyd %s w%d, rev %08x, size %d, cksum %08x' % ( - rbyd.addr(), - rbyd.weight, - rbyd.rev, - rbyd.eoff, - rbyd.cksum)) + if not quiet: + print('rbyd %s w%d, rev %08x, size %d, cksum %08x' % ( + rbyd.addr(), + rbyd.weight, + rbyd.rev, + rbyd.eoff, + rbyd.cksum)) - if args.get('log'): + if args.get('log') and not quiet: dbg_log(rbyd, color=color, **args) - else: + elif not quiet: dbg_tree(rbyd, color=color, **args) @@ -1761,6 +1763,10 @@ if __name__ == "__main__": '--block-count', type=lambda x: int(x, 0), help="Block count in blocks.") + parser.add_argument( + '-q', '--quiet', + action='store_true', + help="Don't show anything, useful when checking for errors.") parser.add_argument( '--color', choices=['never', 'always', 'auto'],