"""Copy Orisys wheel sensor JSON configs and sensors/ bundles into the repo.""" from __future__ import annotations import shutil import sys from pathlib import Path def wheel_config_dir() -> Path: import orisys inner_pkg = Path(orisys.__file__).resolve().parent for candidate in (inner_pkg / "configs", inner_pkg.parent / "configs"): if candidate.is_dir() and any(candidate.glob("*.json")): return candidate return inner_pkg.parent / "configs" def wheel_sensors_dir() -> Path | None: import orisys inner_pkg = Path(orisys.__file__).resolve().parent for candidate in (inner_pkg / "sensors", inner_pkg.parent / "sensors"): if candidate.is_dir() and any(candidate.iterdir()): return candidate return None def sync_configs(repo_root: Path) -> int: src = wheel_config_dir() if not src.is_dir(): print(f"Orisys wheel configs directory not found: {src}", file=sys.stderr) return 1 dst = repo_root / "config" dst.mkdir(parents=True, exist_ok=True) copied = 0 for path in sorted(src.glob("*.json")): if path.stem.lower() == "options": continue shutil.copy2(path, dst / path.name) copied += 1 print(f"Synced {copied} config(s) from {src} to {dst}") return 0 def sync_sensor_bundles(repo_root: Path) -> int: src = wheel_sensors_dir() if src is None or not src.is_dir(): print("Orisys wheel sensors/ directory not found; skipping bundle sync") return 0 dst = repo_root / "sensors" dst.mkdir(parents=True, exist_ok=True) copied = 0 for bundle_dir in sorted(p for p in src.iterdir() if p.is_dir()): target = dst / bundle_dir.name if target.exists(): shutil.rmtree(target) shutil.copytree(bundle_dir, target) copied += 1 print(f"Synced {copied} sensor bundle(s) from {src} to {dst}") return 0 def main() -> int: repo_root = Path(__file__).resolve().parents[1] code = sync_configs(repo_root) if code != 0: return code return sync_sensor_bundles(repo_root) if __name__ == "__main__": raise SystemExit(main())