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