fmap.py: pretty print the object by default
Dumping the structure as a single line makes it hard to read. Format
it for use humans by default and add a --raw option for people who are
using this tool in scripts.
BUG=chromium:982465
TEST=`./fmap.py bin/example.bin` shows human formatted output
TEST=`./fmap.py --raw bin/example.bin` shows one line
Change-Id: I3232cdf104ae6edfbbc03e848166455710653f9d
Reviewed-on: https://chromium-review.googlesource.com/1693884
Tested-by: Mike Frysinger <vapier@chromium.org>
Commit-Ready: Mike Frysinger <vapier@chromium.org>
Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org>
Reviewed-by: Duncan Laurie <dlaurie@google.com>
diff --git a/fmap.py b/fmap.py
index a3ae343..9b635a1 100755
--- a/fmap.py
+++ b/fmap.py
@@ -52,6 +52,7 @@
import argparse
import logging
+import pprint
import struct
import sys
@@ -242,6 +243,8 @@
description=__doc__,
formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument('file', help='The file to decode & print.')
+ parser.add_argument('--raw', action='store_true',
+ help='Dump the object output for scripts.')
return parser
@@ -250,10 +253,15 @@
parser = get_parser()
opts = parser.parse_args(argv)
- print('Decoding FMAP from: %s' % opts.file)
+ if not opts.raw:
+ print('Decoding FMAP from: %s' % opts.file)
blob = open(opts.file, 'rb').read()
obj = fmap_decode(blob)
- print obj
+ if opts.raw:
+ print(obj)
+ else:
+ pp = pprint.PrettyPrinter(indent=2)
+ pp.pprint(obj)
if __name__ == '__main__':