Files
NODEDC_MISSION_CORE/simulation/ai-polygon/build_bundle.py
T
DCCONSTRUCTIONS d0e5f90952 Preserve installed operator workspace before consolidation
Local preservation snapshot, not a new deployment or simulation acceptance.
2026-10-08 09:59:51 +03:00

47 lines
1.6 KiB
Python

"""Package current source plus simulation adapters into a digest-addressed archive."""
import argparse
import hashlib
import json
import tarfile
from pathlib import Path
root = Path(__file__).resolve().parents[2]
parser = argparse.ArgumentParser()
parser.add_argument("--output", type=Path, required=True)
args = parser.parse_args()
args.output.mkdir(parents=True, exist_ok=True)
files = sorted(
p
for folder in (root / "src", root / "simulation/ai-polygon")
for p in folder.rglob("*")
if p.is_file() and not p.is_symlink() and "__pycache__" not in p.parts
)
files.extend((root / "apps/control-station/public/vendor/playcanvas/draco/1.5.7").glob("*"))
# The canonical Rover 006 asset is shared with PlayCanvas, not a second model.
for profile in (root / "simulation/ai-polygon/robots").glob("*.json"):
asset = root / json.loads(profile.read_text())["visual"]["source"]
if asset not in files:
files.append(asset)
manifest = {
p.relative_to(root).as_posix(): hashlib.sha256(p.read_bytes()).hexdigest() for p in files
}
encoded = json.dumps(manifest, sort_keys=True, indent=2).encode()
identity = hashlib.sha256(encoded).hexdigest()
path = args.output / ("ai-polygon-" + identity[:16] + ".tgz")
with tarfile.open(path, "w:gz") as archive:
for p in files:
archive.add(p, arcname=p.relative_to(root).as_posix(), recursive=False)
manifest_path = path.with_suffix(".manifest.json")
manifest_path.write_bytes(encoded)
print(
json.dumps(
{
"bundle": str(path),
"identity": identity,
"sha256": hashlib.sha256(path.read_bytes()).hexdigest(),
"files": len(files),
}
)
)