Skip to content

Conversation

@oliver
Copy link
Contributor

@oliver oliver commented Jan 6, 2025

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 like diff and grep to analyze parsed files.

Copy link
Owner

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice tool!

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}")
Copy link
Owner

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.

Copy link
Contributor Author

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.


# Open file and create parser
for filename in filenames:
print(f"File: {filename}")
Copy link
Owner

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,
})
Copy link
Owner

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.

value_display = f": {field.display}"
size_display = ""
if options["display_size"]:
size_display = f", {field.size}b"
Copy link
Owner

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"



def printFieldSet(field_set, args, options={}, indent=0):
indent_string = " " * indent
Copy link
Owner

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?

@vstinner vstinner merged commit 4167dec into vstinner:main Jan 7, 2025
2 checks passed
@vstinner
Copy link
Owner

vstinner commented Jan 7, 2025

Merged, thank you.

You may write a short documentation in https://hachoir.readthedocs.io/en/latest/ (in the docs/ directory).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants