From 9b03933f2d5aa51b822a75b54efb758a00032b54 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Fri, 14 Mar 2025 17:52:02 -0500 Subject: [PATCH] scripts: tracebd.py/dbgbmap.py: Made off range a subparser of block range So: - before: ./scripts/dbgbmap.py disk -b4096 -@0 -n16,32 - after: ./scripts/dbgbmap.py disk -b4096 -@'0 -n16,32' This is mainly to avoid the naming conflict between -n/--size and -n/--lines, while also separating out the namespaces a bit. It's probably not the most intuitive CLI UI, but --off and -n/--size are probably infrequent arguments at this level of script anyways. --- scripts/dbgbmap.py | 35 +++++++++++++++++++++++++++-------- scripts/plot.py | 1 + scripts/plotmpl.py | 1 + scripts/tracebd.py | 35 +++++++++++++++++++++++++++-------- 4 files changed, 56 insertions(+), 16 deletions(-) diff --git a/scripts/dbgbmap.py b/scripts/dbgbmap.py index 102ace94..0898dd0a 100755 --- a/scripts/dbgbmap.py +++ b/scripts/dbgbmap.py @@ -10,6 +10,7 @@ import functools as ft import itertools as it import math as mt import os +import shlex import shutil import struct @@ -952,8 +953,6 @@ def main(disk, mroots=None, *, block_size=None, block_count=None, block=None, - off=None, - size=None, mdirs=False, btrees=False, datas=False, @@ -1005,6 +1004,13 @@ def main(disk, mroots=None, *, block_count = block_count_ # try to simplify the block/off/size arguments a bit + if not isinstance(block, dict): + block = {'block': block} + block, off, size = ( + block.get('block'), + block.get('off'), + block.get('size')) + if not isinstance(block, tuple): block = block, if isinstance(off, tuple) and len(off) == 1: @@ -1419,25 +1425,38 @@ if __name__ == "__main__": '--block-count', type=lambda x: int(x, 0), help="Block count in blocks.") - parser.add_argument( - '-@', '--block', + # subparser for block arguments + blockparser = argparse.ArgumentParser( + prog="%s -@/--block" % parser.prog, + allow_abbrev=False) + blockparser.add_argument( + 'block', nargs='?', type=lambda x: tuple( rbydaddr(x) if x.strip() else None for x in x.split(',')), - help="Optional block to show, may be a range.") - parser.add_argument( + help="Block address, may be a range.") + blockparser.add_argument( '--off', type=lambda x: tuple( int(x, 0) if x.strip() else None for x in x.split(',')), help="Show a specific offset, may be a range.") - parser.add_argument( - '--size', + blockparser.add_argument( + '-n', '--size', type=lambda x: tuple( int(x, 0) if x.strip() else None for x in x.split(',')), help="Show this many bytes, may be a range.") + parser.add_argument( + '-@', '--block', + type=lambda x: {k: v + for k, v in vars(blockparser.parse_intermixed_args( + shlex.split(x))).items() + if v is not None}, + help="Optional block to show, may be a range. Can also include " + "--off and -n/--size flags to indicate a range inside the " + "block, both which may also be ranges.") parser.add_argument( '--mdirs', action='store_true', diff --git a/scripts/plot.py b/scripts/plot.py index c775d0cb..6827c529 100755 --- a/scripts/plot.py +++ b/scripts/plot.py @@ -1948,6 +1948,7 @@ if __name__ == "__main__": def parse(value): import copy subparser = copy.deepcopy(parser) + subparser.prog = "%s --subplot" % parser.prog next(a for a in subparser._actions if '--width' in a.option_strings).type = float next(a for a in subparser._actions diff --git a/scripts/plotmpl.py b/scripts/plotmpl.py index b6242e2e..514fcada 100755 --- a/scripts/plotmpl.py +++ b/scripts/plotmpl.py @@ -1479,6 +1479,7 @@ if __name__ == "__main__": def parse(value): import copy subparser = copy.deepcopy(parser) + subparser.prog = "%s --subplot" % parser.prog next(a for a in subparser._actions if '--output' in a.option_strings).required = False next(a for a in subparser._actions diff --git a/scripts/tracebd.py b/scripts/tracebd.py index 6bf572cc..2214e41f 100755 --- a/scripts/tracebd.py +++ b/scripts/tracebd.py @@ -20,6 +20,7 @@ import itertools as it import math as mt import os import re +import shlex import shutil import sys import threading as th @@ -659,8 +660,6 @@ def main(path='-', *, block_count=None, block_cycles=None, block=None, - off=None, - size=None, reads=False, progs=False, erases=False, @@ -719,6 +718,13 @@ def main(path='-', *, block_count = block_count_ # try to simplify the block/off/size arguments a bit + if not isinstance(block, dict): + block = {'block': block} + block, off, size = ( + block.get('block'), + block.get('off'), + block.get('size')) + if not isinstance(block, tuple): block = block, if isinstance(off, tuple) and len(off) == 1: @@ -1085,25 +1091,38 @@ if __name__ == "__main__": type=lambda x: int(x, 0), help="Assumed maximum number of erase cycles when measuring " "wear.") - parser.add_argument( - '-@', '--block', + # subparser for block arguments + blockparser = argparse.ArgumentParser( + prog="%s -@/--block" % parser.prog, + allow_abbrev=False) + blockparser.add_argument( + 'block', nargs='?', type=lambda x: tuple( rbydaddr(x) if x.strip() else None for x in x.split(',')), - help="Optional block to show, may be a range.") - parser.add_argument( + help="Block address, may be a range.") + blockparser.add_argument( '--off', type=lambda x: tuple( int(x, 0) if x.strip() else None for x in x.split(',')), help="Show a specific offset, may be a range.") - parser.add_argument( - '--size', + blockparser.add_argument( + '-n', '--size', type=lambda x: tuple( int(x, 0) if x.strip() else None for x in x.split(',')), help="Show this many bytes, may be a range.") + parser.add_argument( + '-@', '--block', + type=lambda x: {k: v + for k, v in vars(blockparser.parse_intermixed_args( + shlex.split(x))).items() + if v is not None}, + help="Optional block to show, may be a range. Can also include " + "--off and -n/--size flags to indicate a range inside the " + "block, both which may also be ranges.") parser.add_argument( '--reads', action='store_true',