first commit

This commit is contained in:
ykcheungab
2026-08-06 15:18:27 +08:00
commit a5a73d76d1
37 changed files with 2697 additions and 0 deletions
+80
View File
@@ -0,0 +1,80 @@
"""Resolve project resource paths for editable and packaged runs."""
from __future__ import annotations
import sys
from pathlib import Path
def is_frozen() -> bool:
return bool(getattr(sys, "frozen", False))
def app_root() -> Path:
"""Return the editable repo root or frozen executable directory."""
if is_frozen():
return Path(sys.executable).resolve().parent
return Path(__file__).resolve().parents[2]
def resource_root() -> Path:
"""Return bundled resource root for editable and PyInstaller runs."""
if is_frozen():
return Path(getattr(sys, "_MEIPASS", app_root())).resolve()
return app_root()
def project_root() -> Path:
"""Return the editable repo root or frozen executable directory."""
return app_root()
def default_options_path() -> Path:
external = app_root() / "config" / "options.json"
if external.exists():
return external
return resource_root() / "config" / "options.json"
def default_steps_path() -> Path:
external = app_root() / "steps" / "default.json"
if external.exists():
return external
return resource_root() / "steps" / "default.json"
def default_locales_dir() -> Path:
external = app_root() / "config" / "locales"
if external.exists():
return external
return resource_root() / "config" / "locales"
def default_recordings_dir() -> Path:
path = app_root() / "recordings"
path.mkdir(parents=True, exist_ok=True)
return path
def default_orisys_sdk_root() -> Path:
"""Sibling ``orisys-sdk`` checkout when sensor-bench lives next to it."""
sibling = app_root().parent / "orisys-sdk"
if sibling.exists():
return sibling
return Path(r"D:\repo\orisys-sdk")
def default_ddjx01_config() -> str:
if is_frozen():
return "ddjx01"
path = default_orisys_sdk_root() / "config" / "ddjx01.json"
if path.exists():
return str(path)
return "ddjx01"
def default_ddjx01_calibration() -> Path:
external = app_root() / "config" / "ddjx01.npy"
if external.exists():
return external
return default_orisys_sdk_root() / "config" / "ddjx01.npy"