Some script tweaks around dbgrbyd.py

- Fixed off-by-one id for unknown tags.

- Allowed block_size and block to go unspecified, assumes the block
  device is one big block in that case.

- Added --buffer and --ignore-errors to watch.py, making it a bit better
  for watching slow and sometimes error scripts, such as dbgrbyd.py when
  watching a block device under test.
This commit is contained in:
Christopher Haster
2023-02-10 19:33:58 -06:00
parent f7dbaf7707
commit 27248ad3b6
2 changed files with 30 additions and 7 deletions
+12 -4
View File
@@ -1,9 +1,10 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import bisect
import itertools as it import itertools as it
import math as m import math as m
import os
import struct import struct
import bisect
COLORS = [ COLORS = [
'34', # blue '34', # blue
@@ -91,7 +92,7 @@ def tagrepr(tag, id, size, off=None):
if off is not None if off is not None
else '-%d' % off) else '-%d' % off)
else: else:
return '0x%04x id%d %d' % (tag, id-1, size) return '0x%04x id%d %d' % (tag, id, size)
def show_log(block_size, data, rev, off, *, def show_log(block_size, data, rev, off, *,
color=False, color=False,
@@ -527,7 +528,7 @@ def show_tree(block_size, data, rev, trunk, weight, *,
line)) line))
def main(disk, block_size, block1, block2=None, *, def main(disk, block_size=None, block1=0, block2=None, *,
trunk=None, trunk=None,
color='auto', color='auto',
**args): **args):
@@ -539,9 +540,14 @@ def main(disk, block_size, block1, block2=None, *,
else: else:
color = False color = False
with open(disk, 'rb') as f:
# if block_size is omitted, assume the block device is one big block
if block_size is None:
f.seek(0, os.SEEK_END)
block_size = f.tell()
# read each block # read each block
blocks = [block for block in [block1, block2] if block is not None] blocks = [block for block in [block1, block2] if block is not None]
with open(disk, 'rb') as f:
datas = [] datas = []
for block in blocks: for block in blocks:
f.seek(block * block_size) f.seek(block * block_size)
@@ -640,10 +646,12 @@ if __name__ == "__main__":
help="File containing the block device.") help="File containing the block device.")
parser.add_argument( parser.add_argument(
'block_size', 'block_size',
nargs='?',
type=lambda x: int(x, 0), type=lambda x: int(x, 0),
help="Block size in bytes.") help="Block size in bytes.")
parser.add_argument( parser.add_argument(
'block1', 'block1',
nargs='?',
type=lambda x: int(x, 0), type=lambda x: int(x, 0),
help="Block address of the first metadata block.") help="Block address of the first metadata block.")
parser.add_argument( parser.add_argument(
+16 -1
View File
@@ -140,6 +140,8 @@ def main(command, *,
sleep=None, sleep=None,
keep_open=False, keep_open=False,
keep_open_paths=None, keep_open_paths=None,
buffer=False,
ignore_errors=False,
exit_on_error=False): exit_on_error=False):
returncode = 0 returncode = 0
try: try:
@@ -179,14 +181,19 @@ def main(command, *,
break break
ring.write(line) ring.write(line)
if not cat: if not cat and not buffer and not ignore_errors:
ring.draw() ring.draw()
mpty.close() mpty.close()
proc.wait() proc.wait()
if ((buffer or ignore_errors)
and not (ignore_errors and proc.returncode != 0)):
ring.draw()
if exit_on_error and proc.returncode != 0: if exit_on_error and proc.returncode != 0:
returncode = proc.returncode returncode = proc.returncode
break break
except OSError as e: except OSError as e:
if e.errno != errno.ETXTBSY: if e.errno != errno.ETXTBSY:
raise raise
@@ -256,6 +263,14 @@ if __name__ == "__main__":
dest='keep_open_paths', dest='keep_open_paths',
action='append', action='append',
help="Use this path for inotify. Defaults to guessing.") help="Use this path for inotify. Defaults to guessing.")
parser.add_argument(
'-b', '--buffer',
action='store_true',
help="Wait until command finishes to show the output.")
parser.add_argument(
'-i', '--ignore-errors',
action='store_true',
help="Only show output after successful runs. Implies --buffer.")
parser.add_argument( parser.add_argument(
'-e', '--exit-on-error', '-e', '--exit-on-error',
action='store_true', action='store_true',