-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add hachoir-list tool #102
Conversation
Not sure if these options are really useful, but they are easy to implement, and we remain consistent with hachoir-urwid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice tool!
hachoir/listtool.py
Outdated
size_display = "" | ||
if options["display_size"]: | ||
size_display = f", {field.size}b" | ||
print(f"{indent_string}{field.name} <{field.__class__.__name__}{size_display}> ({field.description}){value_display}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to hide the description by default, and only show it if --descr
(new) option is used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added --description
; the on command line the option names can be shortened as long as they are unique.
hachoir/listtool.py
Outdated
|
||
# Open file and create parser | ||
for filename in filenames: | ||
print(f"File: {filename}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be possible to omit the filename if there is a single filename?
printFieldSet(parser, values, { | ||
"display_size": values.display_size, | ||
"display_value": values.display_value, | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there is more than one file, it would be nice to have a newline at the end for readability.
hachoir/listtool.py
Outdated
value_display = f": {field.display}" | ||
size_display = "" | ||
if options["display_size"]: | ||
size_display = f", {field.size}b" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be possible to format a number of bytes using B? Something like:
if size % 8 == 0:
return "{size // 8}B"
else:
return "{size}b"
hachoir/listtool.py
Outdated
|
||
|
||
def printFieldSet(field_set, args, options={}, indent=0): | ||
indent_string = " " * indent |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add --indent
command line option to configure the indentation size?
By default the description is now hidden.
Also, add newlines between files.
Merged, thank you. You may write a short documentation in https://hachoir.readthedocs.io/en/latest/ (in the |
This adds the
hachoir-list
command-line tool which just prints all parsed fields. This text output allows to e.g. use normal shell tools likediff
andgrep
to analyze parsed files.