Commit ede3f1a1 authored by Jérome Perrin's avatar Jérome Perrin

format-json: python3 support

parent 5442c76f
...@@ -10,7 +10,7 @@ Usage:: ...@@ -10,7 +10,7 @@ Usage::
""" """
import os from __future__ import print_function
import sys import sys
import json import json
import collections import collections
...@@ -19,15 +19,15 @@ import collections ...@@ -19,15 +19,15 @@ import collections
def main(): def main():
exit_code = 0 exit_code = 0
for f in sys.argv[1:]: for f in sys.argv[1:]:
print 'Processing %s' % (f,) print('Processing', f,)
with open(f, 'rb') as infile: with open(f) as infile:
try: try:
obj = json.load(infile, object_pairs_hook=collections.OrderedDict) obj = json.load(infile, object_pairs_hook=collections.OrderedDict)
except ValueError as e: except ValueError as e:
exit_code = 1 exit_code = 1
print e print(e, file=sys.stderr)
else: else:
with open(f, 'wb') as outfile: with open(f, 'w') as outfile:
json.dump(obj, outfile, sort_keys=False, indent=2, separators=(',', ': ')) json.dump(obj, outfile, sort_keys=False, indent=2, separators=(',', ': '))
outfile.write('\n') outfile.write('\n')
sys.exit(exit_code) sys.exit(exit_code)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment