STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
config.py
Go to the documentation of this file.
1"""Paths, binary discovery, and run-name conventions for the webviewer backend."""
2
3from __future__ import annotations
4
5import os
6import re
7import shutil
8from pathlib import Path
9
10# Directory holding the Elodin DB run directories.
11ELODIN_DIR = Path(
12 os.environ.get("ELODIN_DB_DIR", str(Path.home() / ".local/share/elodin"))
13).expanduser()
14
15# Where we cache the exported parquet for each run. Immutable past runs → cache
16# never needs invalidation. Lives next to this file, gitignored.
17CACHE_DIR = Path(
18 os.environ.get(
19 "WEBVIEWER_CACHE_DIR", str(Path(__file__).resolve().parent.parent / ".cache")
20 )
21).expanduser()
22
23# Only timestamped runs are considered: daq_YYYYMMDD_HHMMSS, and the simulated
24# variant daq_sim_YYYYMMDD_HHMMSS that session-manager writes for a sim session.
25# Older ad-hoc DBs (daq_live, calibration, hand-named dirs) stay ignored — the
26# `sim_` group is what tells the UI to label a run as synthetic, so widening the
27# pattern does not blur the real/simulated distinction the prefix exists for.
28RUN_RE = re.compile(r"^daq_(?P<sim>sim_)?(?P<date>\d{8})_(?P<time>\d{6})$")
29
30# The one thing this viewer writes: a shared one-line description per run. It lives
31# beside the run dirs, NOT under CACHE_DIR — docker-compose calls the cache volume "safe
32# to wipe", and a line somebody typed is not something to lose to a cache clear. The
33# Elodin mount is already read-write (elodin-db mmaps a DB O_RDWR even just to export
34# it), so nothing extra is needed to deploy this.
35DESCRIPTIONS_PATH = Path(
36 os.environ.get("WEBVIEWER_DESCRIPTIONS_PATH", str(ELODIN_DIR / "run_descriptions.json"))
37).expanduser()
38
39# The video gateway's recordings folder (daq-server/video/recordings), mounted
40# read-only. Unset, or not a directory: the viewer simply has no video. Never written.
41_video = os.environ.get("WEBVIEWER_VIDEO_DIR", "").strip()
42VIDEO_DIR: Path | None = Path(_video).expanduser() if _video else None
43
44# The time zone the gateway machine names its recording folders in (the agent's
45# stamp() uses local time). Only needed for clips with no timing sidecar.
46VIDEO_TZ = os.environ.get("WEBVIEWER_VIDEO_TZ", "America/Los_Angeles")
47
48# Cap the throughput of CSV downloads (bytes/sec) so a big whole-run export can't
49# saturate the host's uplink and starve other services on the box. A long run's
50# tidy CSV can be hundreds of MB; this paces it instead of forbidding it.
51# Default unlimited (0) — local dev is unthrottled; the deployment sets a cap via
52# WEBVIEWER_MAX_DOWNLOAD_BPS (see run.sh --build).
53MAX_DOWNLOAD_BYTES_PER_SEC = int(os.environ.get("WEBVIEWER_MAX_DOWNLOAD_BPS", "0"))
54
55
56def find_elodin_db() -> str:
57 """Locate the elodin-db binary the same way export_elodin_db.sh does."""
58 cargo = Path.home() / ".cargo/bin/elodin-db"
59 if cargo.is_file():
60 return str(cargo)
61 found = shutil.which("elodin-db")
62 if found:
63 return found
64 raise RuntimeError(
65 "elodin-db not found. Install with `cargo install elodin-db` or put it on PATH."
66 )
str find_elodin_db()
Definition config.py:56