json_overview_image_info.py 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/usr/bin/env python3
  2. import json
  3. from pathlib import Path
  4. from os import getenv
  5. from sys import argv
  6. if len(argv) != 2:
  7. print("JSON info files script requires ouput file as argument")
  8. exit(1)
  9. output_path = Path(argv[1])
  10. assert getenv("WORK_DIR"), "$WORK_DIR required"
  11. work_dir = Path(getenv("WORK_DIR"))
  12. output = {}
  13. for json_file in work_dir.glob("*.json"):
  14. image_info = json.loads(json_file.read_text())
  15. if not output:
  16. output.update(image_info)
  17. else:
  18. # get first (and only) profile in json file
  19. device_id = next(iter(image_info["profiles"].keys()))
  20. if device_id not in output["profiles"]:
  21. output["profiles"].update(image_info["profiles"])
  22. else:
  23. output["profiles"][device_id]["images"].append(
  24. image_info["profiles"][device_id]["images"][0]
  25. )
  26. if output:
  27. output_path.write_text(json.dumps(output, sort_keys=True, separators=(",", ":")))
  28. else:
  29. print("JSON info file script could not find any JSON files for target")