|
| 1 | +# chmod +x zip_ssd_mosaic_deployment.py |
| 2 | +#!/usr/bin/env python3 |
| 3 | + |
| 4 | + |
| 5 | +# cd /workspaces/ssd-data-model/admin/tools-ssd_workflow/admin/ |
| 6 | +# python zip_ssd_mosaic_deployment.py |
| 7 | +# # or after chmod: |
| 8 | +# ./zip_ssd_mosaic_deployment.py |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | +import zipfile |
| 13 | +from pathlib import Path |
| 14 | +from datetime import date |
| 15 | + |
| 16 | + |
| 17 | +def main() -> None: |
| 18 | + # Fixed path inside the Codespace workspace |
| 19 | + live_dir = Path("/workspaces/ssd-data-model/deployment_extracts/mosaic/live").resolve() |
| 20 | + |
| 21 | + if not live_dir.is_dir(): |
| 22 | + raise SystemExit(f"Live directory not found: {live_dir}") |
| 23 | + |
| 24 | + # Filename like 2025-11-18-ssd_mosaic_deployment_download.zip |
| 25 | + today_str = date.today().strftime("%Y-%m-%d") |
| 26 | + zip_name = f"{today_str}-ssd_mosaic_deployment_download.zip" |
| 27 | + zip_path = live_dir / zip_name |
| 28 | + |
| 29 | + # Collect files to zip, skipping any existing deployment zip bundles |
| 30 | + files_to_zip = [] |
| 31 | + for path in live_dir.rglob("*"): |
| 32 | + if path.is_file(): |
| 33 | + # Avoid including current or earlier deployment bundles |
| 34 | + if path.name.endswith("ssd_mosaic_deployment_download.zip"): |
| 35 | + continue |
| 36 | + files_to_zip.append(path) |
| 37 | + |
| 38 | + if not files_to_zip: |
| 39 | + raise SystemExit(f"No files to zip in {live_dir}") |
| 40 | + |
| 41 | + # mode="w" will create or replace the zip file |
| 42 | + with zipfile.ZipFile(zip_path, mode="w", compression=zipfile.ZIP_DEFLATED) as zf: |
| 43 | + for file_path in files_to_zip: |
| 44 | + # Store paths relative to the live directory |
| 45 | + arcname = file_path.relative_to(live_dir) |
| 46 | + zf.write(file_path, arcname) |
| 47 | + |
| 48 | + print(f"Created zip: {zip_path}") |
| 49 | + |
| 50 | + |
| 51 | +if __name__ == "__main__": |
| 52 | + main() |
0 commit comments