blob: 6b14bd5a9d695f9c3824a87af953281653545f74 [file] [log] [blame]
James Feist3cb5fec2018-01-23 14:41:51 -08001#!/usr/bin/python3
2# all arguments to this script are considered as json files
3# and attempted to be formatted alphabetically
4
5import json
James Feist5ffd8b42019-10-25 11:22:10 -07006import os
James Feist3cb5fec2018-01-23 14:41:51 -08007from sys import argv
8
James Feist5ffd8b42019-10-25 11:22:10 -07009files = argv[1:]
10
11for file in files[:]:
12 if os.path.isdir(file):
13 files.remove(file)
14 for f in os.listdir(file):
15 files.append(os.path.join(file, f))
16
17for file in files:
James Feistc4e56942019-04-19 12:15:19 -070018 print("formatting file {}".format(file))
19 with open(file) as f:
20 j = json.load(f)
James Feist3cb5fec2018-01-23 14:41:51 -080021
James Feistc4e56942019-04-19 12:15:19 -070022 if isinstance(j, list):
23 for item in j:
24 item["Exposes"] = sorted(item["Exposes"], key=lambda k: k["Type"])
25 else:
26 j["Exposes"] = sorted(j["Exposes"], key=lambda k: k["Type"])
27
28 with open(file, 'w') as f:
29 f.write(json.dumps(j, indent=4, sort_keys=True, separators=(',', ': ')))