Bug 1857841 - pt 3. Add a new page kind named "fresh" r=glandium
[gecko.git] / tools / github-sync / read-json.py
blob87264d7df4dffadaea6b620ca05cebbba0b705ae
1 #!/usr/bin/env python3
3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 import json
8 import sys
10 j = json.load(sys.stdin)
11 components = sys.argv[1].split("/")
14 def next_match(json_fragment, components):
15 if len(components) == 0:
16 yield json_fragment
17 else:
18 component = components[0]
19 if type(json_fragment) == list:
20 if component == "*":
21 for item in json_fragment:
22 yield from next_match(item, components[1:])
23 else:
24 component = int(component)
25 if component >= len(j):
26 sys.exit(1)
27 yield from next_match(json_fragment[component], components[1:])
28 elif type(json_fragment) == dict:
29 if component == "*":
30 for key in sorted(json_fragment.keys()):
31 yield from next_match(json_fragment[key], components[1:])
32 elif component not in json_fragment:
33 sys.exit(1)
34 else:
35 yield from next_match(json_fragment[component], components[1:])
38 for match in list(next_match(j, components)):
39 if type(match) == dict:
40 print(" ".join(match.keys()))
41 else:
42 print(match)