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.
This commit is contained in:
+27
-8
@@ -10,6 +10,7 @@ import functools as ft
|
|||||||
import itertools as it
|
import itertools as it
|
||||||
import math as mt
|
import math as mt
|
||||||
import os
|
import os
|
||||||
|
import shlex
|
||||||
import shutil
|
import shutil
|
||||||
import struct
|
import struct
|
||||||
|
|
||||||
@@ -952,8 +953,6 @@ def main(disk, mroots=None, *,
|
|||||||
block_size=None,
|
block_size=None,
|
||||||
block_count=None,
|
block_count=None,
|
||||||
block=None,
|
block=None,
|
||||||
off=None,
|
|
||||||
size=None,
|
|
||||||
mdirs=False,
|
mdirs=False,
|
||||||
btrees=False,
|
btrees=False,
|
||||||
datas=False,
|
datas=False,
|
||||||
@@ -1005,6 +1004,13 @@ def main(disk, mroots=None, *,
|
|||||||
block_count = block_count_
|
block_count = block_count_
|
||||||
|
|
||||||
# try to simplify the block/off/size arguments a bit
|
# 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):
|
if not isinstance(block, tuple):
|
||||||
block = block,
|
block = block,
|
||||||
if isinstance(off, tuple) and len(off) == 1:
|
if isinstance(off, tuple) and len(off) == 1:
|
||||||
@@ -1419,25 +1425,38 @@ 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(
|
# subparser for block arguments
|
||||||
'-@', '--block',
|
blockparser = argparse.ArgumentParser(
|
||||||
|
prog="%s -@/--block" % parser.prog,
|
||||||
|
allow_abbrev=False)
|
||||||
|
blockparser.add_argument(
|
||||||
|
'block',
|
||||||
nargs='?',
|
nargs='?',
|
||||||
type=lambda x: tuple(
|
type=lambda x: tuple(
|
||||||
rbydaddr(x) if x.strip() else None
|
rbydaddr(x) if x.strip() else None
|
||||||
for x in x.split(',')),
|
for x in x.split(',')),
|
||||||
help="Optional block to show, may be a range.")
|
help="Block address, may be a range.")
|
||||||
parser.add_argument(
|
blockparser.add_argument(
|
||||||
'--off',
|
'--off',
|
||||||
type=lambda x: tuple(
|
type=lambda x: tuple(
|
||||||
int(x, 0) if x.strip() else None
|
int(x, 0) if x.strip() else None
|
||||||
for x in x.split(',')),
|
for x in x.split(',')),
|
||||||
help="Show a specific offset, may be a range.")
|
help="Show a specific offset, may be a range.")
|
||||||
parser.add_argument(
|
blockparser.add_argument(
|
||||||
'--size',
|
'-n', '--size',
|
||||||
type=lambda x: tuple(
|
type=lambda x: tuple(
|
||||||
int(x, 0) if x.strip() else None
|
int(x, 0) if x.strip() else None
|
||||||
for x in x.split(',')),
|
for x in x.split(',')),
|
||||||
help="Show this many bytes, may be a range.")
|
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(
|
parser.add_argument(
|
||||||
'--mdirs',
|
'--mdirs',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
|
|||||||
@@ -1948,6 +1948,7 @@ if __name__ == "__main__":
|
|||||||
def parse(value):
|
def parse(value):
|
||||||
import copy
|
import copy
|
||||||
subparser = copy.deepcopy(parser)
|
subparser = copy.deepcopy(parser)
|
||||||
|
subparser.prog = "%s --subplot" % parser.prog
|
||||||
next(a for a in subparser._actions
|
next(a for a in subparser._actions
|
||||||
if '--width' in a.option_strings).type = float
|
if '--width' in a.option_strings).type = float
|
||||||
next(a for a in subparser._actions
|
next(a for a in subparser._actions
|
||||||
|
|||||||
@@ -1479,6 +1479,7 @@ if __name__ == "__main__":
|
|||||||
def parse(value):
|
def parse(value):
|
||||||
import copy
|
import copy
|
||||||
subparser = copy.deepcopy(parser)
|
subparser = copy.deepcopy(parser)
|
||||||
|
subparser.prog = "%s --subplot" % parser.prog
|
||||||
next(a for a in subparser._actions
|
next(a for a in subparser._actions
|
||||||
if '--output' in a.option_strings).required = False
|
if '--output' in a.option_strings).required = False
|
||||||
next(a for a in subparser._actions
|
next(a for a in subparser._actions
|
||||||
|
|||||||
+27
-8
@@ -20,6 +20,7 @@ import itertools as it
|
|||||||
import math as mt
|
import math as mt
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
import shlex
|
||||||
import shutil
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
import threading as th
|
import threading as th
|
||||||
@@ -659,8 +660,6 @@ def main(path='-', *,
|
|||||||
block_count=None,
|
block_count=None,
|
||||||
block_cycles=None,
|
block_cycles=None,
|
||||||
block=None,
|
block=None,
|
||||||
off=None,
|
|
||||||
size=None,
|
|
||||||
reads=False,
|
reads=False,
|
||||||
progs=False,
|
progs=False,
|
||||||
erases=False,
|
erases=False,
|
||||||
@@ -719,6 +718,13 @@ def main(path='-', *,
|
|||||||
block_count = block_count_
|
block_count = block_count_
|
||||||
|
|
||||||
# try to simplify the block/off/size arguments a bit
|
# 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):
|
if not isinstance(block, tuple):
|
||||||
block = block,
|
block = block,
|
||||||
if isinstance(off, tuple) and len(off) == 1:
|
if isinstance(off, tuple) and len(off) == 1:
|
||||||
@@ -1085,25 +1091,38 @@ if __name__ == "__main__":
|
|||||||
type=lambda x: int(x, 0),
|
type=lambda x: int(x, 0),
|
||||||
help="Assumed maximum number of erase cycles when measuring "
|
help="Assumed maximum number of erase cycles when measuring "
|
||||||
"wear.")
|
"wear.")
|
||||||
parser.add_argument(
|
# subparser for block arguments
|
||||||
'-@', '--block',
|
blockparser = argparse.ArgumentParser(
|
||||||
|
prog="%s -@/--block" % parser.prog,
|
||||||
|
allow_abbrev=False)
|
||||||
|
blockparser.add_argument(
|
||||||
|
'block',
|
||||||
nargs='?',
|
nargs='?',
|
||||||
type=lambda x: tuple(
|
type=lambda x: tuple(
|
||||||
rbydaddr(x) if x.strip() else None
|
rbydaddr(x) if x.strip() else None
|
||||||
for x in x.split(',')),
|
for x in x.split(',')),
|
||||||
help="Optional block to show, may be a range.")
|
help="Block address, may be a range.")
|
||||||
parser.add_argument(
|
blockparser.add_argument(
|
||||||
'--off',
|
'--off',
|
||||||
type=lambda x: tuple(
|
type=lambda x: tuple(
|
||||||
int(x, 0) if x.strip() else None
|
int(x, 0) if x.strip() else None
|
||||||
for x in x.split(',')),
|
for x in x.split(',')),
|
||||||
help="Show a specific offset, may be a range.")
|
help="Show a specific offset, may be a range.")
|
||||||
parser.add_argument(
|
blockparser.add_argument(
|
||||||
'--size',
|
'-n', '--size',
|
||||||
type=lambda x: tuple(
|
type=lambda x: tuple(
|
||||||
int(x, 0) if x.strip() else None
|
int(x, 0) if x.strip() else None
|
||||||
for x in x.split(',')),
|
for x in x.split(',')),
|
||||||
help="Show this many bytes, may be a range.")
|
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(
|
parser.add_argument(
|
||||||
'--reads',
|
'--reads',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
|
|||||||
Reference in New Issue
Block a user