James Feist | 3cb5fec | 2018-01-23 14:41:51 -0800 | [diff] [blame] | 1 | #!/usr/bin/python3 |
| 2 | # all arguments to this script are considered as json files |
| 3 | # and attempted to be formatted alphabetically |
| 4 | |
| 5 | import json |
| 6 | from sys import argv |
| 7 | |
| 8 | for file in argv[1:]: |
James Feist | c4e5694 | 2019-04-19 12:15:19 -0700 | [diff] [blame] | 9 | print("formatting file {}".format(file)) |
| 10 | with open(file) as f: |
| 11 | j = json.load(f) |
James Feist | 3cb5fec | 2018-01-23 14:41:51 -0800 | [diff] [blame] | 12 | |
James Feist | c4e5694 | 2019-04-19 12:15:19 -0700 | [diff] [blame] | 13 | if isinstance(j, list): |
| 14 | for item in j: |
| 15 | item["Exposes"] = sorted(item["Exposes"], key=lambda k: k["Type"]) |
| 16 | else: |
| 17 | j["Exposes"] = sorted(j["Exposes"], key=lambda k: k["Type"]) |
| 18 | |
| 19 | with open(file, 'w') as f: |
| 20 | f.write(json.dumps(j, indent=4, sort_keys=True, separators=(',', ': '))) |