#!/usr/bin/env python3 """Create a clean, portable source package without local secrets or caches.""" from pathlib import Path from zipfile import ZIP_DEFLATED, ZipFile ROOT = Path(__file__).resolve().parents[1] OUTPUT = ROOT / "cyber-range.zip" EXCLUDED_DIRS = {".git", ".vendor", "__pycache__", ".pytest_cache", "superpowers"} EXCLUDED_FILES = {".env", OUTPUT.name} def included(path: Path) -> bool: relative = path.relative_to(ROOT) return not any(part in EXCLUDED_DIRS for part in relative.parts) and path.name not in EXCLUDED_FILES def main() -> None: files = sorted(path for path in ROOT.rglob("*") if path.is_file() and included(path)) with ZipFile(OUTPUT, "w", compression=ZIP_DEFLATED, compresslevel=9) as archive: for path in files: archive.write(path, Path("cyber-range") / path.relative_to(ROOT)) print(f"Created {OUTPUT.name}: {len(files)} files, {OUTPUT.stat().st_size:,} bytes") if __name__ == "__main__": main()