4 from pathlib
import Path
9 print("JSON info files script requires ouput file as argument")
12 output_path
= Path(argv
[1])
14 assert getenv("WORK_DIR"), "$WORK_DIR required"
16 work_dir
= Path(getenv("WORK_DIR"))
18 assert work_dir
.is_dir(), "$WORK_DIR not a directory"
22 for json_file
in work_dir
.glob("*.json"):
23 image_info
= json
.loads(json_file
.read_text())
25 output
.update(image_info
)
27 # get first (and only) profile in json file
28 device_id
= next(iter(image_info
["profiles"].keys()))
29 if device_id
not in output
["profiles"]:
30 output
["profiles"].update(image_info
["profiles"])
32 output
["profiles"][device_id
]["images"].append(
33 image_info
["profiles"][device_id
]["images"][0]
37 output_path
.write_text(json
.dumps(output
, sort_keys
=True, separators
=(",", ":")))
39 print("JSON info file script could not find any JSON files for target")