Commit 3d113b4f authored by Jérome Perrin's avatar Jérome Perrin Committed by Rafael Monnerat

format-json: change the invocation, we now edit files in-place

parent 5e9fb957
#!/usr/bin/env python
r"""Command-line tool to format software release JSON for slapos.
Inspired by json.tool from python
Inspired by json.tool from python, but enforcing 2 spaces and non-sorted keys.
The files are modified in-place.
Usage::
format-json infile outfile
format-json file1.json [file2.json]
"""
......@@ -16,19 +17,16 @@ import collections
def main():
if len(sys.argv) != 3:
raise SystemExit(sys.argv[0] + " infile outfile")
with open(sys.argv[1], 'rb') as infile:
try:
obj = json.load(infile, object_pairs_hook=collections.OrderedDict)
except ValueError, e:
raise SystemExit(e)
with open(sys.argv[2], 'wb') as outfile:
json.dump(obj, outfile, sort_keys=False, indent=2, separators=(',', ': '))
outfile.write('\n')
for f in sys.argv[1:]:
with open(f, 'rb') as infile:
try:
obj = json.load(infile, object_pairs_hook=collections.OrderedDict)
except ValueError as e:
raise SystemExit(e)
with open(f, 'wb') as outfile:
json.dump(obj, outfile, sort_keys=False, indent=2, separators=(',', ': '))
outfile.write('\n')
if __name__ == '__main__':
main()
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