json_overview_image_info.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/usr/bin/env python3
  2. from os import getenv, environ
  3. from pathlib import Path
  4. from subprocess import run
  5. from sys import argv
  6. import json
  7. if len(argv) != 2:
  8. print("JSON info files script requires ouput file as argument")
  9. exit(1)
  10. output_path = Path(argv[1])
  11. assert getenv("WORK_DIR"), "$WORK_DIR required"
  12. work_dir = Path(getenv("WORK_DIR"))
  13. output = {}
  14. for json_file in work_dir.glob("*.json"):
  15. image_info = json.loads(json_file.read_text())
  16. if not output:
  17. output.update(image_info)
  18. else:
  19. # get first (and only) profile in json file
  20. device_id = next(iter(image_info["profiles"].keys()))
  21. if device_id not in output["profiles"]:
  22. output["profiles"].update(image_info["profiles"])
  23. else:
  24. output["profiles"][device_id]["images"].append(
  25. image_info["profiles"][device_id]["images"][0]
  26. )
  27. if output:
  28. default_packages, output["arch_packages"] = run(
  29. [
  30. "make",
  31. "--no-print-directory",
  32. "-C",
  33. f"target/linux/{output['target'].split('/')[0]}",
  34. "val.DEFAULT_PACKAGES",
  35. "val.ARCH_PACKAGES",
  36. ],
  37. capture_output=True,
  38. check=True,
  39. env=environ.copy().update({"TOPDIR": Path().cwd()}),
  40. text=True,
  41. ).stdout.splitlines()
  42. output["default_packages"] = default_packages.split()
  43. output_path.write_text(json.dumps(output, sort_keys=True, separators=(",", ":")))
  44. else:
  45. print("JSON info file script could not find any JSON files for target")