Publish packaging utility
Browse files- tools/package.py +27 -0
tools/package.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Create a clean, portable source package without local secrets or caches."""
|
| 3 |
+
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
from zipfile import ZIP_DEFLATED, ZipFile
|
| 6 |
+
|
| 7 |
+
ROOT = Path(__file__).resolve().parents[1]
|
| 8 |
+
OUTPUT = ROOT / "cyber-range.zip"
|
| 9 |
+
EXCLUDED_DIRS = {".git", ".vendor", "__pycache__", ".pytest_cache", "superpowers"}
|
| 10 |
+
EXCLUDED_FILES = {".env", OUTPUT.name}
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def included(path: Path) -> bool:
|
| 14 |
+
relative = path.relative_to(ROOT)
|
| 15 |
+
return not any(part in EXCLUDED_DIRS for part in relative.parts) and path.name not in EXCLUDED_FILES
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def main() -> None:
|
| 19 |
+
files = sorted(path for path in ROOT.rglob("*") if path.is_file() and included(path))
|
| 20 |
+
with ZipFile(OUTPUT, "w", compression=ZIP_DEFLATED, compresslevel=9) as archive:
|
| 21 |
+
for path in files:
|
| 22 |
+
archive.write(path, Path("cyber-range") / path.relative_to(ROOT))
|
| 23 |
+
print(f"Created {OUTPUT.name}: {len(files)} files, {OUTPUT.stat().st_size:,} bytes")
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
if __name__ == "__main__":
|
| 27 |
+
main()
|