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:
+24
-16
@@ -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,11 +1725,12 @@ 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
|
||||||
print('btree %s w%d, rev %08x, cksum %08x' % (
|
if not quiet:
|
||||||
btree.addr(),
|
print('btree %s w%d, rev %08x, cksum %08x' % (
|
||||||
btree.weight,
|
btree.addr(),
|
||||||
btree.rev,
|
btree.weight,
|
||||||
btree.cksum))
|
btree.rev,
|
||||||
|
btree.cksum))
|
||||||
|
|
||||||
# precompute tree renderings
|
# precompute tree renderings
|
||||||
t_width = 0
|
t_width = 0
|
||||||
@@ -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,20 +1802,22 @@ 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:
|
||||||
print('%04x.%04x: %*s%s%s%s' % (
|
if not quiet:
|
||||||
rbyd.block, rbyd.trunk,
|
print('%04x.%04x: %*s%s%s%s' % (
|
||||||
t_width, '',
|
rbyd.block, rbyd.trunk,
|
||||||
'\x1b[31m' if color else '',
|
t_width, '',
|
||||||
'(corrupted rbyd %s)' % rbyd.addr(),
|
'\x1b[31m' if color else '',
|
||||||
'\x1b[m' if color else ''))
|
'(corrupted rbyd %s)' % rbyd.addr(),
|
||||||
|
'\x1b[m' if color else ''))
|
||||||
prbyd = None
|
prbyd = None
|
||||||
corrupted = True
|
corrupted = True
|
||||||
continue
|
continue
|
||||||
|
|
||||||
for rid, name in rbyd.rids():
|
if not quiet:
|
||||||
bid_ = bid-(rbyd.weight-1) + rid
|
for rid, name in rbyd.rids():
|
||||||
# show the leaf entry/branch
|
bid_ = bid-(rbyd.weight-1) + rid
|
||||||
dbg_branch(len(path), bid_, rbyd, rid, name)
|
# show the leaf entry/branch
|
||||||
|
dbg_branch(len(path), bid_, rbyd, rid, name)
|
||||||
|
|
||||||
if args.get('error_on_corrupt') and corrupted:
|
if args.get('error_on_corrupt') and corrupted:
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
@@ -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'],
|
||||||
|
|||||||
+42
-31
@@ -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,11 +2845,12 @@ 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
|
||||||
print('mtree %s w%s.%s, rev %08x, cksum %08x' % (
|
if not quiet:
|
||||||
mtree.addr(),
|
print('mtree %s w%s.%s, rev %08x, cksum %08x' % (
|
||||||
mtree.mbweightrepr(), mtree.mrweightrepr(),
|
mtree.addr(),
|
||||||
mtree.rev,
|
mtree.mbweightrepr(), mtree.mrweightrepr(),
|
||||||
mtree.cksum))
|
mtree.rev,
|
||||||
|
mtree.cksum))
|
||||||
|
|
||||||
# precompute tree renderings
|
# precompute tree renderings
|
||||||
t_width = 0
|
t_width = 0
|
||||||
@@ -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,14 +2991,15 @@ def main(disk, mroots=None, *,
|
|||||||
if isinstance(mdir, Mdir):
|
if isinstance(mdir, Mdir):
|
||||||
# corrupted?
|
# corrupted?
|
||||||
if not mdir:
|
if not mdir:
|
||||||
print('{%s}: %s%s%s' % (
|
if not quiet:
|
||||||
','.join('%04x' % block
|
print('{%s}: %s%s%s' % (
|
||||||
for block in mdir.blocks),
|
','.join('%04x' % block
|
||||||
'\x1b[31m' if color else '',
|
for block in mdir.blocks),
|
||||||
'(corrupted %s %s)' % (
|
'\x1b[31m' if color else '',
|
||||||
'mroot' if mdir.mid == -1 else 'mdir',
|
'(corrupted %s %s)' % (
|
||||||
mdir.addr()),
|
'mroot' if mdir.mid == -1 else 'mdir',
|
||||||
'\x1b[m' if color else ''))
|
mdir.addr()),
|
||||||
|
'\x1b[m' if color else ''))
|
||||||
pmdir = None
|
pmdir = None
|
||||||
corrupted = True
|
corrupted = True
|
||||||
continue
|
continue
|
||||||
@@ -3004,39 +3007,43 @@ 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:
|
||||||
print('{%s}: %s%s%s' % (
|
if not quiet:
|
||||||
','.join('%04x' % block
|
print('{%s}: %s%s%s' % (
|
||||||
for block in mdir.blocks),
|
','.join('%04x' % block
|
||||||
'\x1b[31m' if color else '',
|
for block in mdir.blocks),
|
||||||
'(mroot cycle detected %s)' % mdir.addr(),
|
'\x1b[31m' if color else '',
|
||||||
'\x1b[m' if color else ''))
|
'(mroot cycle detected %s)' % mdir.addr(),
|
||||||
|
'\x1b[m' if color else ''))
|
||||||
pmdir = None
|
pmdir = None
|
||||||
corrupted = True
|
corrupted = True
|
||||||
continue
|
continue
|
||||||
mrootseen.add(mdir)
|
mrootseen.add(mdir)
|
||||||
|
|
||||||
# show the mdir
|
# show the mdir
|
||||||
dbg_mdir(len(path), mdir)
|
if not quiet:
|
||||||
|
dbg_mdir(len(path), mdir)
|
||||||
|
|
||||||
# btree node?
|
# btree node?
|
||||||
else:
|
else:
|
||||||
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:
|
||||||
print('%11s: %*s%s%s%s' % (
|
if not quiet:
|
||||||
'%04x.%04x' % (rbyd.block, rbyd.trunk),
|
print('%11s: %*s%s%s%s' % (
|
||||||
t_width, '',
|
'%04x.%04x' % (rbyd.block, rbyd.trunk),
|
||||||
'\x1b[31m' if color else '',
|
t_width, '',
|
||||||
'(corrupted rbyd %s)' % rbyd.addr(),
|
'\x1b[31m' if color else '',
|
||||||
'\x1b[m' if color else ''))
|
'(corrupted rbyd %s)' % rbyd.addr(),
|
||||||
|
'\x1b[m' if color else ''))
|
||||||
pmdir = None
|
pmdir = None
|
||||||
corrupted = True
|
corrupted = True
|
||||||
continue
|
continue
|
||||||
|
|
||||||
for rid, name in rbyd.rids():
|
if not quiet:
|
||||||
bid_ = bid-(rbyd.weight-1) + rid
|
for rid, name in rbyd.rids():
|
||||||
# show the leaf entry/branch
|
bid_ = bid-(rbyd.weight-1) + rid
|
||||||
dbg_branch(len(path), bid_, rbyd, rid, name)
|
# show the leaf entry/branch
|
||||||
|
dbg_branch(len(path), bid_, rbyd, rid, name)
|
||||||
|
|
||||||
if args.get('error_on_corrupt') and corrupted:
|
if args.get('error_on_corrupt') and corrupted:
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
@@ -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'],
|
||||||
|
|||||||
+14
-8
@@ -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,18 +1716,19 @@ 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
|
||||||
print('rbyd %s w%d, rev %08x, size %d, cksum %08x' % (
|
if not quiet:
|
||||||
rbyd.addr(),
|
print('rbyd %s w%d, rev %08x, size %d, cksum %08x' % (
|
||||||
rbyd.weight,
|
rbyd.addr(),
|
||||||
rbyd.rev,
|
rbyd.weight,
|
||||||
rbyd.eoff,
|
rbyd.rev,
|
||||||
rbyd.cksum))
|
rbyd.eoff,
|
||||||
|
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'],
|
||||||
|
|||||||
Reference in New Issue
Block a user