Skip to content

Commit

Permalink
More tests and docs for hexdump and xxd
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Zoppi <[email protected]>
  • Loading branch information
TexZK committed Mar 2, 2024
1 parent ac6761c commit a6e414e
Show file tree
Hide file tree
Showing 16 changed files with 344 additions and 92 deletions.
57 changes: 57 additions & 0 deletions docs/_autosummary/hexrec.utils.SparseMemoryIO.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
SparseMemoryIO
==============

.. currentmodule:: hexrec.utils

.. autoclass:: SparseMemoryIO
:members:
:inherited-members:
:private-members:
:special-members:




.. rubric:: Attributes

.. autosummary::

~SparseMemoryIO.closed
~SparseMemoryIO.memory






.. rubric:: Methods

.. autosummary::
:nosignatures:

~SparseMemoryIO.__init__
~SparseMemoryIO.close
~SparseMemoryIO.detach
~SparseMemoryIO.fileno
~SparseMemoryIO.flush
~SparseMemoryIO.getbuffer
~SparseMemoryIO.getvalue
~SparseMemoryIO.isatty
~SparseMemoryIO.peek
~SparseMemoryIO.read
~SparseMemoryIO.read1
~SparseMemoryIO.readable
~SparseMemoryIO.readinto
~SparseMemoryIO.readinto1
~SparseMemoryIO.readline
~SparseMemoryIO.readlines
~SparseMemoryIO.seek
~SparseMemoryIO.seekable
~SparseMemoryIO.skip_data
~SparseMemoryIO.skip_hole
~SparseMemoryIO.tell
~SparseMemoryIO.truncate
~SparseMemoryIO.writable
~SparseMemoryIO.write
~SparseMemoryIO.writelines

9 changes: 9 additions & 0 deletions docs/_autosummary/hexrec.utils.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@



.. rubric:: Classes

.. autosummary::
:toctree:
:template: custom-class-template.rst
:nosignatures:

SparseMemoryIO




Expand Down
57 changes: 35 additions & 22 deletions src/hexrec/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def parse_args(self, ctx, args):
FILE_PATH_IN = click.Path(dir_okay=False, allow_dash=True, readable=True, exists=True)
FILE_PATH_OUT = click.Path(dir_okay=False, allow_dash=True, writable=True)

RECORD_FORMAT_CHOICE = click.Choice(list(sorted(FILE_TYPES.keys())))
FORMAT_CHOICE = click.Choice(list(sorted(FILE_TYPES.keys())))

DATA_FMT_FORMATTERS: Mapping[str, Callable[[bytes], bytes]] = {
'ascii': lambda b: b,
Expand Down Expand Up @@ -313,11 +313,11 @@ def main() -> None:
# ----------------------------------------------------------------------------

@main.command()
@click.option('-i', '--input-format', type=RECORD_FORMAT_CHOICE, help="""
@click.option('-i', '--input-format', type=FORMAT_CHOICE, help="""
Forces the input file format.
Required for the standard input.
""")
@click.option('-o', '--output-format', type=RECORD_FORMAT_CHOICE, help="""
@click.option('-o', '--output-format', type=FORMAT_CHOICE, help="""
Forces the output file format.
By default it is that of the input file.
""")
Expand Down Expand Up @@ -361,11 +361,11 @@ def clear(
# ----------------------------------------------------------------------------

@main.command()
@click.option('-i', '--input-format', type=RECORD_FORMAT_CHOICE, help="""
@click.option('-i', '--input-format', type=FORMAT_CHOICE, help="""
Forces the input file format.
Required for the standard input.
""")
@click.option('-o', '--output-format', type=RECORD_FORMAT_CHOICE, help="""
@click.option('-o', '--output-format', type=FORMAT_CHOICE, help="""
Forces the output file format.
By default it is that of the input file.
""")
Expand Down Expand Up @@ -400,11 +400,11 @@ def convert(
# ----------------------------------------------------------------------------

@main.command()
@click.option('-i', '--input-format', type=RECORD_FORMAT_CHOICE, help="""
@click.option('-i', '--input-format', type=FORMAT_CHOICE, help="""
Forces the input file format.
Required for the standard input.
""")
@click.option('-o', '--output-format', type=RECORD_FORMAT_CHOICE, help="""
@click.option('-o', '--output-format', type=FORMAT_CHOICE, help="""
Forces the output file format.
By default it is that of the input file.
""")
Expand Down Expand Up @@ -456,11 +456,11 @@ def crop(
# ----------------------------------------------------------------------------

@main.command()
@click.option('-i', '--input-format', type=RECORD_FORMAT_CHOICE, help="""
@click.option('-i', '--input-format', type=FORMAT_CHOICE, help="""
Forces the input file format.
Required for the standard input.
""")
@click.option('-o', '--output-format', type=RECORD_FORMAT_CHOICE, help="""
@click.option('-o', '--output-format', type=FORMAT_CHOICE, help="""
Forces the output file format.
By default it is that of the input file.
""")
Expand Down Expand Up @@ -504,11 +504,11 @@ def delete(
# ----------------------------------------------------------------------------

@main.command()
@click.option('-i', '--input-format', type=RECORD_FORMAT_CHOICE, help="""
@click.option('-i', '--input-format', type=FORMAT_CHOICE, help="""
Forces the input file format.
Required for the standard input.
""")
@click.option('-o', '--output-format', type=RECORD_FORMAT_CHOICE, help="""
@click.option('-o', '--output-format', type=FORMAT_CHOICE, help="""
Forces the output file format.
By default it is that of the input file.
""")
Expand Down Expand Up @@ -556,11 +556,11 @@ def fill(
# ----------------------------------------------------------------------------

@main.command()
@click.option('-i', '--input-format', type=RECORD_FORMAT_CHOICE, help="""
@click.option('-i', '--input-format', type=FORMAT_CHOICE, help="""
Forces the input file format.
Required for the standard input.
""")
@click.option('-o', '--output-format', type=RECORD_FORMAT_CHOICE, help="""
@click.option('-o', '--output-format', type=FORMAT_CHOICE, help="""
Forces the output file format.
By default it is that of the input file.
""")
Expand Down Expand Up @@ -674,7 +674,7 @@ def flood(
@click.option('-U', '--upper', 'upper', is_flag=True, help="""
Uses upper case hex letters on address and data.
""")
@click.option('-I', '--input-format', type=RECORD_FORMAT_CHOICE, help="""
@click.option('-I', '--input-format', type=FORMAT_CHOICE, help="""
Forces the input file format.
Required for the standard input.
""")
Expand All @@ -696,7 +696,7 @@ def hexdump(
skip: Optional[int],
no_squeezing: bool,
upper: bool,
input_format: Optional[str], # TODO:
input_format: Optional[str],
) -> None:
r"""Display file contents in hexadecimal, decimal, octal, or ascii.
Expand Down Expand Up @@ -729,6 +729,11 @@ def hexdump(
for param, value in hexdump.ordered_options
if (param.name in kwargs) and value]

if input_format:
input_type = guess_input_type(infile, input_format)
input_file = input_type.load(infile)
infile = input_file.memory

hexdump_core(
infile=infile,
length=length,
Expand Down Expand Up @@ -801,7 +806,7 @@ def hexdump(
@click.option('-U', '--upper', 'upper', is_flag=True, help="""
Uses upper case hex letters on address and data.
""")
@click.option('-I', '--input-format', type=RECORD_FORMAT_CHOICE, help="""
@click.option('-I', '--input-format', type=FORMAT_CHOICE, help="""
Forces the input file format.
Required for the standard input.
""")
Expand All @@ -822,7 +827,7 @@ def hd(
skip: Optional[int],
no_squeezing: bool,
upper: bool,
input_format: Optional[str], # TODO:
input_format: Optional[str],
) -> None:
r"""Display file contents in hexadecimal, decimal, octal, or ascii.
Expand Down Expand Up @@ -856,6 +861,11 @@ def hd(
format_order.insert(0, 'canonical')
kwargs['canonical'] = True

if input_format:
input_type = guess_input_type(infile, input_format)
input_file = input_type.load(infile)
infile = input_file.memory

hexdump_core(
infile=infile,
length=length,
Expand All @@ -870,11 +880,11 @@ def hd(
# ----------------------------------------------------------------------------

@main.command()
@click.option('-i', '--input-format', type=RECORD_FORMAT_CHOICE, help="""
@click.option('-i', '--input-format', type=FORMAT_CHOICE, help="""
Forces the input file format for all input files.
Required for the standard input.
""")
@click.option('-o', '--output-format', type=RECORD_FORMAT_CHOICE, help="""
@click.option('-o', '--output-format', type=FORMAT_CHOICE, help="""
Forces the output file format.
By default it is that of the input file.
""")
Expand Down Expand Up @@ -918,11 +928,11 @@ def merge(
# ----------------------------------------------------------------------------

@main.command()
@click.option('-i', '--input-format', type=RECORD_FORMAT_CHOICE, help="""
@click.option('-i', '--input-format', type=FORMAT_CHOICE, help="""
Forces the input file format.
Required for the standard input.
""")
@click.option('-o', '--output-format', type=RECORD_FORMAT_CHOICE, help="""
@click.option('-o', '--output-format', type=FORMAT_CHOICE, help="""
Forces the output file format.
By default it is that of the input file.
""")
Expand Down Expand Up @@ -960,7 +970,7 @@ def shift(
# ----------------------------------------------------------------------------

@main.command()
@click.option('-i', '--input-format', type=RECORD_FORMAT_CHOICE, help="""
@click.option('-i', '--input-format', type=FORMAT_CHOICE, help="""
Forces the input file format.
Required for the standard input.
""")
Expand Down Expand Up @@ -1230,6 +1240,9 @@ def xxd(
Some parameters were changed to satisfy the POSIX-like command line parser.
"""

infile = None if infile == '-' else infile
outfile = None if outfile == '-' else outfile

xxd_core(
infile=infile,
outfile=outfile,
Expand Down
Loading

0 comments on commit a6e414e

Please sign in to comment.