#!/usr/bin/env python3 import hashlib import sys import pathlib import urllib.request import yaml SCRIPT = pathlib.Path(__file__) FW = SCRIPT.parent ESPRESSIF_MODULE = FW / "zephyrproject/modules/hal/espressif" MODULE_YAML = ESPRESSIF_MODULE / "zephyr/module.yml" BLOBS = ESPRESSIF_MODULE / "zephyr/blobs" def main() -> None: text = MODULE_YAML.read_text() data = yaml.safe_load(text) for entry in data["blobs"]: url = entry["url"] checksum = entry["sha256"] path = entry["path"] get_blob( url=url, checksum=checksum, path=path, ) def get_blob(url, checksum, path): sys.stdout.write(f"Downloading {path} ...") with urllib.request.urlopen(url) as conn: content = conn.read() sys.stdout.write(" done\n") sha256 = hashlib.sha256() sha256.update(content) calculated = sha256.hexdigest() if calculated == checksum: print("Checksum matched.") else: print(f"Checksum mismatch for {path}!") print(f"Expected: {checksum}") print(f"Got: {calculated}") target: pathlib.Path = BLOBS / path target.parent.mkdir(exist_ok=True, parents=True) target.write_bytes(content) print(f"Saved to {path}") if __name__ == "__main__": main()