#!/usr/bin/env python3 """Filesystem layout helpers shared by the web configurator and updater. On the target device the layout is: /opt/buttontask/ versions// (ButtonTask + webconfig/) current -> versions/ config/ icons/ (shared, never replaced) run/ (heartbeat, update-status.json) scripts/ (privileged helpers, see scripts/) """ import os from pathlib import Path def install_root(): """Resolve the ButtonTask install root (the directory holding versions/, current, config/, run/).""" env = os.environ.get("BUTTONTASK_ROOT") if env: return Path(env) return Path("/opt/buttontask") def run_dir(): p = install_root() / "run" try: p.mkdir(parents=True, exist_ok=True) except OSError: pass return p def versions_dir(): return install_root() / "versions" def current_link(): return install_root() / "current" def scripts_dir(): """Directory with the privileged helper scripts. Prefer the installed copy under /scripts, fall back to the copy that ships next to this package (dev/source tree).""" installed = install_root() / "scripts" if installed.is_dir(): return installed return Path(__file__).resolve().parent / "scripts" QT_HEARTBEAT = "qt.alive" UPDATE_STATUS = "update-status.json" BUTTON_LOG = "button-log.jsonl"