Skip to content
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

DFReader.py: emit enumeration value name when verbose-dumping #955

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions DFReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,17 +382,32 @@ def dump_verbose(self, f):
f.write(" %s: %s" % (c, val))
except UnicodeDecodeError:
f.write(" %s: %s" % (c, to_string(val)))

# see if this is an enumeration entry, emit enumeration
# entry name if it is
if c in field_metadata_by_name:
fm = field_metadata_by_name[c]
fm_enum = getattr(fm, "enum", None)
if fm_enum is not None:
enum_entry_name = "?????" # default, "not found" value
for entry in fm_enum.iterchildren():
if int(entry.value) == int(val):
enum_entry_name = entry.get('name')
break

f.write(f" ({enum_entry_name})")

# Append the unit to the output
unit = self.fmt.get_unit(c)
if unit == "":
# No unit specified - just output the newline
f.write("\n")
elif unit.startswith("rad"):
if unit.startswith("rad"):
# For rad or rad/s, add the degrees conversion too
f.write(" %s (%s %s)\n" % (unit, math.degrees(val), unit.replace("rad","deg")))
f.write(" %s (%s %s)" % (unit, math.degrees(val), unit.replace("rad","deg")))
else:
# Append the unit
f.write(" %s\n" % (unit))
f.write(" %s" % (unit))

# output the newline
f.write("\n")

# if this is a bitmask then print out all bits set:
if c in field_metadata_by_name:
Expand Down
Loading