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
+13 -5
View File
@@ -1,9 +1,10 @@
#!/usr/bin/env python3
import bisect
import itertools as it
import math as m
import os
import struct
import bisect
COLORS = [
'34', # blue
@@ -91,7 +92,7 @@ def tagrepr(tag, id, size, off=None):
if off is not None
else '-%d' % off)
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, *,
color=False,
@@ -527,7 +528,7 @@ def show_tree(block_size, data, rev, trunk, weight, *,
line))
def main(disk, block_size, block1, block2=None, *,
def main(disk, block_size=None, block1=0, block2=None, *,
trunk=None,
color='auto',
**args):
@@ -539,9 +540,14 @@ def main(disk, block_size, block1, block2=None, *,
else:
color = False
# read each block
blocks = [block for block in [block1, block2] if block is not None]
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
blocks = [block for block in [block1, block2] if block is not None]
datas = []
for block in blocks:
f.seek(block * block_size)
@@ -640,10 +646,12 @@ if __name__ == "__main__":
help="File containing the block device.")
parser.add_argument(
'block_size',
nargs='?',
type=lambda x: int(x, 0),
help="Block size in bytes.")
parser.add_argument(
'block1',
nargs='?',
type=lambda x: int(x, 0),
help="Block address of the first metadata block.")
parser.add_argument(
+17 -2
View File
@@ -140,6 +140,8 @@ def main(command, *,
sleep=None,
keep_open=False,
keep_open_paths=None,
buffer=False,
ignore_errors=False,
exit_on_error=False):
returncode = 0
try:
@@ -151,7 +153,7 @@ def main(command, *,
ring = LinesIO(lines)
try:
# run the command under a pseudoterminal
# run the command under a pseudoterminal
mpty, spty = pty.openpty()
# forward terminal size
@@ -179,14 +181,19 @@ def main(command, *,
break
ring.write(line)
if not cat:
if not cat and not buffer and not ignore_errors:
ring.draw()
mpty.close()
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:
returncode = proc.returncode
break
except OSError as e:
if e.errno != errno.ETXTBSY:
raise
@@ -256,6 +263,14 @@ if __name__ == "__main__":
dest='keep_open_paths',
action='append',
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(
'-e', '--exit-on-error',
action='store_true',