Pretty print json output when writing to a file

It's the opposite of fun to read a single line of json output
when generating the graph results, so if using the -o option
to write to a file, indent the output for readability.

Change-Id: I091ee2ade51def2d59cdeadb792e56746f8882a2
This commit is contained in:
Matt Riedemann 2016-03-09 15:43:52 -05:00
parent 4b42cef7f5
commit 4cdc4be2e6
1 changed files with 3 additions and 1 deletions

View File

@ -231,7 +231,9 @@ def main():
out = sys.stdout
try:
out.write(json.dumps(jsondata))
# indent the json output if we're writing to a file
indent = 4 if args.output else None
out.write(json.dumps(jsondata, indent=indent))
finally:
out.close()