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

whisper-info: add --json output option #210

Merged
merged 2 commits into from
May 8, 2017
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: 16 additions & 11 deletions bin/whisper-info.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import sys
import signal
import optparse
import json

try:
import whisper
Expand All @@ -17,7 +18,9 @@
# OS=windows
pass

option_parser = optparse.OptionParser(usage='''%prog path [field]''')
option_parser = optparse.OptionParser(usage='''%prog [options] path [field]''')
option_parser.add_option('--json', default=False, action='store_true',
help="Output results in JSON form")
(options, args) = option_parser.parse_args()

if len(args) < 1:
Expand Down Expand Up @@ -45,14 +48,16 @@
print(info[field])
sys.exit(0)


archives = info.pop('archives')
for key, value in info.items():
print('%s: %s' % (key, value))
print

for i, archive in enumerate(archives):
print('Archive %d' % i)
for key, value in archive.items():
if options.json:
print(json.dumps(info, indent=2, separators=(',', ': ')))
else:
archives = info.pop('archives')
for key, value in info.items():
print('%s: %s' % (key, value))
print
print('')

for i, archive in enumerate(archives):
print('Archive %d' % i)
for key, value in archive.items():
print('%s: %s' % (key, value))
print('')