- Notifications
You must be signed in to change notification settings - Fork 406
/
Copy pathcheck_auspice_json.py
31 lines (25 loc) · 1.07 KB
/
check_auspice_json.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
importargparse
importjson
importsys
if__name__=='__main__':
parser=argparse.ArgumentParser(
description="Ensure certain values are present for a given node trait",
formatter_class=argparse.ArgumentDefaultsHelpFormatter
)
parser.add_argument('--json', type=str, metavar="JSON", required=True, help="Auspice JSON")
parser.add_argument('--attr', type=str, metavar="KEY", required=True, help="node attr to collect")
parser.add_argument('--values', type=str, nargs="+", metavar="VALUE", required=True, help="values to check")
args=parser.parse_args()
values_seen=set()
defcollect(node):
v=node.get("node_attrs", {}).get(args.attr, {}).get("value", "")
ifv:
values_seen.add(v)
forchildinnode.get("children", []):
collect(child)
withopen(args.json, "r") asf:
input_json=json.load(f)
collect(input_json["tree"])
ifnotvalues_seen>=set(args.values):
print("Following values missing from JSON:", set(args.values)-values_seen)
sys.exit(1)