Revert "[ARM32/Linux] Copy tests.zip only for CI test and use x86 unittest"
[platform/upstream/coreclr.git] / extract-from-json.py
1 #!/usr/bin/python
2
3 import argparse
4 import json
5 import sys
6
7 def parse_args():
8     parser = argparse.ArgumentParser(
9         description="""Extracts information from a json file by navigating the JSON object using a
10             sequence of property accessors and returning the JSON subtree, or the raw data, found
11             at that location."""
12     )
13
14     parser.add_argument(
15         '-f', '--file',
16         metavar='<project.json>',
17         help="Path to project.json file to parse",
18         required=True,
19     )
20
21     parser.add_argument(
22         'property',
23         metavar='property_name',
24         help="""Name of property to extract using object notation.
25             Pass multiple values to drill down into nested objects (in order).""",
26         nargs='*',
27     )
28
29     parser.add_argument(
30         '-r', '--raw',
31         help="""Dumps the raw object found at the requested location.
32             If omitted, returns a JSON formatted object instead.""",
33         action='store_true',
34         default=False
35     )
36
37     return parser.parse_args()
38
39 def main():
40     args = parse_args()
41
42     with open(args.file) as json_file:
43         selected_property = json.load(json_file)
44
45     for prop in args.property:
46         selected_property = selected_property[prop]
47
48     if args.raw:
49         print(selected_property)
50     else:
51         print(json.dumps(selected_property))
52
53     return 0
54
55 if __name__ == "__main__":
56     sys.exit(main())