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.
This commit is contained in:
Christopher Haster
2025-04-05 17:59:35 -05:00
parent 5682fd6163
commit e5b430cb8c
3 changed files with 80 additions and 55 deletions
+9 -1
View File
@@ -1681,6 +1681,7 @@ def main(disk, roots=None, *,
trunk=None, trunk=None,
block_size=None, block_size=None,
block_count=None, block_count=None,
quiet=False,
color='auto', color='auto',
**args): **args):
# figure out what color should be # figure out what color should be
@@ -1724,6 +1725,7 @@ def main(disk, roots=None, *,
btree = Btree.fetch(bd, roots, trunk) btree = Btree.fetch(bd, roots, trunk)
# print some information about the btree # print some information about the btree
if not quiet:
print('btree %s w%d, rev %08x, cksum %08x' % ( print('btree %s w%d, rev %08x, cksum %08x' % (
btree.addr(), btree.addr(),
btree.weight, btree.weight,
@@ -1792,7 +1794,7 @@ def main(disk, roots=None, *,
path=True, path=True,
depth=args.get('depth')): depth=args.get('depth')):
# print inner branches if requested # print inner branches if requested
if args.get('inner'): if args.get('inner') and not quiet:
for d, (bid_, rbyd_, rid_, name_) in pathdelta( for d, (bid_, rbyd_, rid_, name_) in pathdelta(
path, ppath): path, ppath):
dbg_branch(d, bid_, rbyd_, rid_, name_) dbg_branch(d, bid_, rbyd_, rid_, name_)
@@ -1800,6 +1802,7 @@ def main(disk, roots=None, *,
# corrupted? try to keep printing the tree # corrupted? try to keep printing the tree
if not rbyd: if not rbyd:
if not quiet:
print('%04x.%04x: %*s%s%s%s' % ( print('%04x.%04x: %*s%s%s%s' % (
rbyd.block, rbyd.trunk, rbyd.block, rbyd.trunk,
t_width, '', t_width, '',
@@ -1810,6 +1813,7 @@ def main(disk, roots=None, *,
corrupted = True corrupted = True
continue continue
if not quiet:
for rid, name in rbyd.rids(): for rid, name in rbyd.rids():
bid_ = bid-(rbyd.weight-1) + rid bid_ = bid-(rbyd.weight-1) + rid
# show the leaf entry/branch # show the leaf entry/branch
@@ -1845,6 +1849,10 @@ if __name__ == "__main__":
'--block-count', '--block-count',
type=lambda x: int(x, 0), type=lambda x: int(x, 0),
help="Block count in blocks.") 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( parser.add_argument(
'--color', '--color',
choices=['never', 'always', 'auto'], choices=['never', 'always', 'auto'],
+12 -1
View File
@@ -2800,6 +2800,7 @@ def main(disk, mroots=None, *,
trunk=None, trunk=None,
block_size=None, block_size=None,
block_count=None, block_count=None,
quiet=False,
color='auto', color='auto',
**args): **args):
# figure out what color should be # figure out what color should be
@@ -2844,6 +2845,7 @@ def main(disk, mroots=None, *,
depth=args.get('depth')) depth=args.get('depth'))
# print some information about the mtree # print some information about the mtree
if not quiet:
print('mtree %s w%s.%s, rev %08x, cksum %08x' % ( print('mtree %s w%s.%s, rev %08x, cksum %08x' % (
mtree.addr(), mtree.addr(),
mtree.mbweightrepr(), mtree.mrweightrepr(), mtree.mbweightrepr(), mtree.mrweightrepr(),
@@ -2976,7 +2978,7 @@ def main(disk, mroots=None, *,
path=True, path=True,
depth=args.get('depth')): depth=args.get('depth')):
# print inner branches if requested # print inner branches if requested
if args.get('inner'): if args.get('inner') and not quiet:
for d, (bid_, rbyd_, rid_, name_) in pathdelta( for d, (bid_, rbyd_, rid_, name_) in pathdelta(
# skip the mrootchain # skip the mrootchain
path[len(mtree.mrootchain):], path[len(mtree.mrootchain):],
@@ -2989,6 +2991,7 @@ def main(disk, mroots=None, *,
if isinstance(mdir, Mdir): if isinstance(mdir, Mdir):
# corrupted? # corrupted?
if not mdir: if not mdir:
if not quiet:
print('{%s}: %s%s%s' % ( print('{%s}: %s%s%s' % (
','.join('%04x' % block ','.join('%04x' % block
for block in mdir.blocks), for block in mdir.blocks),
@@ -3004,6 +3007,7 @@ def main(disk, mroots=None, *,
# cycle detected? # cycle detected?
if mdir.mid == -1: if mdir.mid == -1:
if mdir in mrootseen: if mdir in mrootseen:
if not quiet:
print('{%s}: %s%s%s' % ( print('{%s}: %s%s%s' % (
','.join('%04x' % block ','.join('%04x' % block
for block in mdir.blocks), for block in mdir.blocks),
@@ -3016,6 +3020,7 @@ def main(disk, mroots=None, *,
mrootseen.add(mdir) mrootseen.add(mdir)
# show the mdir # show the mdir
if not quiet:
dbg_mdir(len(path), mdir) dbg_mdir(len(path), mdir)
# btree node? # btree node?
@@ -3023,6 +3028,7 @@ def main(disk, mroots=None, *,
bid, rbyd = mdir bid, rbyd = mdir
# corrupted? try to keep printing the tree # corrupted? try to keep printing the tree
if not rbyd: if not rbyd:
if not quiet:
print('%11s: %*s%s%s%s' % ( print('%11s: %*s%s%s%s' % (
'%04x.%04x' % (rbyd.block, rbyd.trunk), '%04x.%04x' % (rbyd.block, rbyd.trunk),
t_width, '', t_width, '',
@@ -3033,6 +3039,7 @@ def main(disk, mroots=None, *,
corrupted = True corrupted = True
continue continue
if not quiet:
for rid, name in rbyd.rids(): for rid, name in rbyd.rids():
bid_ = bid-(rbyd.weight-1) + rid bid_ = bid-(rbyd.weight-1) + rid
# show the leaf entry/branch # show the leaf entry/branch
@@ -3068,6 +3075,10 @@ if __name__ == "__main__":
'--block-count', '--block-count',
type=lambda x: int(x, 0), type=lambda x: int(x, 0),
help="Block count in blocks.") 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( parser.add_argument(
'--color', '--color',
choices=['never', 'always', 'auto'], choices=['never', 'always', 'auto'],
+8 -2
View File
@@ -1673,6 +1673,7 @@ def main(disk, blocks=None, *,
trunk=None, trunk=None,
block_size=None, block_size=None,
block_count=None, block_count=None,
quiet=False,
color='auto', color='auto',
**args): **args):
# figure out what color should be # figure out what color should be
@@ -1715,6 +1716,7 @@ def main(disk, blocks=None, *,
rbyd = Rbyd.fetch(bd, blocks, trunk) rbyd = Rbyd.fetch(bd, blocks, trunk)
# print some information about the rbyd # print some information about the rbyd
if not quiet:
print('rbyd %s w%d, rev %08x, size %d, cksum %08x' % ( print('rbyd %s w%d, rev %08x, size %d, cksum %08x' % (
rbyd.addr(), rbyd.addr(),
rbyd.weight, rbyd.weight,
@@ -1722,11 +1724,11 @@ def main(disk, blocks=None, *,
rbyd.eoff, rbyd.eoff,
rbyd.cksum)) rbyd.cksum))
if args.get('log'): if args.get('log') and not quiet:
dbg_log(rbyd, dbg_log(rbyd,
color=color, color=color,
**args) **args)
else: elif not quiet:
dbg_tree(rbyd, dbg_tree(rbyd,
color=color, color=color,
**args) **args)
@@ -1761,6 +1763,10 @@ if __name__ == "__main__":
'--block-count', '--block-count',
type=lambda x: int(x, 0), type=lambda x: int(x, 0),
help="Block count in blocks.") 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( parser.add_argument(
'--color', '--color',
choices=['never', 'always', 'auto'], choices=['never', 'always', 'auto'],