create_delivery_r2_zip.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/usr/bin/env python3
  2. """Create Deflate Level 9 Delivery Package for PROD2U-MIN-20261009.r2."""
  3. import hashlib
  4. import os
  5. import zipfile
  6. from pathlib import Path
  7. ROOT = Path("/workspace/cpld-temperature-control")
  8. OUT_ZIP = ROOT / "prod2u-final-delivery-20261009.r2.zip"
  9. EXCLUDE_DIRS = {
  10. ".git",
  11. "__pycache__",
  12. ".pytest_cache",
  13. ".mypy_cache",
  14. "scratch",
  15. "tmp",
  16. }
  17. EXCLUDE_EXTS = {
  18. ".pyc",
  19. ".vvp",
  20. ".vpi",
  21. }
  22. def main():
  23. print(f"Creating {OUT_ZIP} with compression level 9...")
  24. if OUT_ZIP.exists():
  25. OUT_ZIP.unlink()
  26. file_count = 0
  27. with zipfile.ZipFile(OUT_ZIP, "w", compression=zipfile.ZIP_DEFLATED, compresslevel=9) as zf:
  28. for root, dirs, files in os.walk(ROOT):
  29. dirs[:] = [d for d in dirs if d not in EXCLUDE_DIRS and not d.startswith(".")]
  30. for f in files:
  31. if f.endswith(".zip") or any(f.endswith(ext) for ext in EXCLUDE_EXTS):
  32. continue
  33. path = Path(root) / f
  34. rel_path = path.relative_to(ROOT)
  35. zf.write(path, arcname=str(rel_path))
  36. file_count += 1
  37. size = OUT_ZIP.stat().st_size
  38. sha256 = hashlib.sha256(OUT_ZIP.read_bytes()).hexdigest()
  39. print(f"Package created: {OUT_ZIP}")
  40. print(f"Files: {file_count}, Size: {size:,} bytes")
  41. print(f"SHA-256: {sha256}")
  42. # Write package info
  43. pkg_info = Path("/workspace/cpld-temperature-control/receipts/PACKAGE-INFO.json")
  44. pkg_info.write_text(f'{{\n "package": "{OUT_ZIP.name}",\n "size_bytes": {size},\n "files_count": {file_count},\n "sha256": "{sha256}"\n}}\n')
  45. if __name__ == "__main__":
  46. main()