scripts: Adopted double-indent on multiline expressions
This matches the style used in C, which is good for consistency:
a_really_long_function_name(
double_indent_after_first_newline(
single_indent_nested_newlines))
We were already doing this for multiline control-flow statements, simply
because I'm not sure how else you could indent this without making
things really confusing:
if a_really_long_function_name(
double_indent_after_first_newline(
single_indent_nested_newlines)):
do_the_thing()
This was the only real difference style-wise between the Python code and
C code, so now both should be following roughly the same style (80 cols,
double-indent multiline exprs, prefix multiline binary ops, etc).
This commit is contained in:
+51
-49
@@ -66,12 +66,12 @@ def rbydaddr(s):
|
||||
def xxd(data, width=16):
|
||||
for i in range(0, len(data), width):
|
||||
yield '%-*s %-*s' % (
|
||||
3*width,
|
||||
' '.join('%02x' % b for b in data[i:i+width]),
|
||||
width,
|
||||
''.join(
|
||||
b if b >= ' ' and b <= '~' else '.'
|
||||
for b in map(chr, data[i:i+width])))
|
||||
3*width,
|
||||
' '.join('%02x' % b for b in data[i:i+width]),
|
||||
width,
|
||||
''.join(
|
||||
b if b >= ' ' and b <= '~' else '.'
|
||||
for b in map(chr, data[i:i+width])))
|
||||
|
||||
def crc32c(data, crc=0):
|
||||
crc ^= 0xffffffff
|
||||
@@ -99,7 +99,7 @@ def main(disk, block=None, *,
|
||||
|
||||
if len(block) > 1:
|
||||
print("error: more than one block address?",
|
||||
file=sys.stderr)
|
||||
file=sys.stderr)
|
||||
sys.exit(-1)
|
||||
|
||||
block = block[0]
|
||||
@@ -112,17 +112,18 @@ def main(disk, block=None, *,
|
||||
|
||||
# block may also encode an offset
|
||||
block, off, size = (
|
||||
block[0] if isinstance(block, tuple) else block,
|
||||
off[0] if isinstance(off, tuple)
|
||||
else off if off is not None
|
||||
else size[0] if isinstance(size, tuple) and len(size) > 1
|
||||
else block[1] if isinstance(block, tuple)
|
||||
else None,
|
||||
size[1] - size[0] if isinstance(size, tuple) and len(size) > 1
|
||||
else size[0] if isinstance(size, tuple)
|
||||
else size if size is not None
|
||||
else off[1] - off[0] if isinstance(off, tuple) and len(off) > 1
|
||||
else block_size)
|
||||
block[0] if isinstance(block, tuple) else block,
|
||||
off[0] if isinstance(off, tuple)
|
||||
else off if off is not None
|
||||
else size[0] if isinstance(size, tuple) and len(size) > 1
|
||||
else block[1] if isinstance(block, tuple)
|
||||
else None,
|
||||
size[1] - size[0] if isinstance(size, tuple) and len(size) > 1
|
||||
else size[0] if isinstance(size, tuple)
|
||||
else size if size is not None
|
||||
else off[1] - off[0]
|
||||
if isinstance(off, tuple) and len(off) > 1
|
||||
else block_size)
|
||||
|
||||
# read the block
|
||||
f.seek((block * block_size) + (off or 0))
|
||||
@@ -133,50 +134,51 @@ def main(disk, block=None, *,
|
||||
|
||||
# print the header
|
||||
print('block %s, size %d, cksum %08x' % (
|
||||
'0x%x.%x' % (block, off)
|
||||
if off is not None
|
||||
else '0x%x' % block,
|
||||
size,
|
||||
cksum))
|
||||
'0x%x.%x' % (block, off)
|
||||
if off is not None
|
||||
else '0x%x' % block,
|
||||
size,
|
||||
cksum))
|
||||
|
||||
# render the hex view
|
||||
for o, line in enumerate(xxd(data)):
|
||||
print('%08x: %s' % ((off or 0) + 16*o, line))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import argparse
|
||||
import sys
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Debug block devices.",
|
||||
allow_abbrev=False)
|
||||
description="Debug block devices.",
|
||||
allow_abbrev=False)
|
||||
parser.add_argument(
|
||||
'disk',
|
||||
help="File containing the block device.")
|
||||
'disk',
|
||||
help="File containing the block device.")
|
||||
parser.add_argument(
|
||||
'block',
|
||||
nargs='?',
|
||||
type=rbydaddr,
|
||||
help="Block address.")
|
||||
'block',
|
||||
nargs='?',
|
||||
type=rbydaddr,
|
||||
help="Block address.")
|
||||
parser.add_argument(
|
||||
'-b', '--block-size',
|
||||
type=bdgeom,
|
||||
help="Block size/geometry in bytes.")
|
||||
'-b', '--block-size',
|
||||
type=bdgeom,
|
||||
help="Block size/geometry in bytes.")
|
||||
parser.add_argument(
|
||||
'--block-count',
|
||||
type=lambda x: int(x, 0),
|
||||
help="Block count in blocks.")
|
||||
'--block-count',
|
||||
type=lambda x: int(x, 0),
|
||||
help="Block count in blocks.")
|
||||
parser.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.")
|
||||
'--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(
|
||||
'-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.")
|
||||
'-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.")
|
||||
sys.exit(main(**{k: v
|
||||
for k, v in vars(parser.parse_intermixed_args()).items()
|
||||
if v is not None}))
|
||||
for k, v in vars(parser.parse_intermixed_args()).items()
|
||||
if v is not None}))
|
||||
|
||||
Reference in New Issue
Block a user