50 lines
1.4 KiB
Python
50 lines
1.4 KiB
Python
from pathlib import Path
|
|
import os
|
|
import tomllib
|
|
from typing import Optional
|
|
|
|
_RESOLVED: dict[str, Path] = {}
|
|
|
|
def get_config_path() -> Path:
|
|
return Path(os.environ.get("SLOP_CONFIG", "config.toml"))
|
|
|
|
def _resolve_path(env_var: str, config_key: str, default: str) -> Path:
|
|
if env_var in os.environ:
|
|
return Path(os.environ[env_var])
|
|
try:
|
|
with open(get_config_path(), "rb") as f:
|
|
cfg = tomllib.load(f)
|
|
if "paths" in cfg and config_key in cfg["paths"]:
|
|
return Path(cfg["paths"][config_key])
|
|
except FileNotFoundError:
|
|
pass
|
|
return Path(default)
|
|
|
|
def get_conductor_dir() -> Path:
|
|
if "conductor_dir" not in _RESOLVED:
|
|
_RESOLVED["conductor_dir"] = _resolve_path("SLOP_CONDUCTOR_DIR", "conductor_dir", "conductor")
|
|
return _RESOLVED["conductor_dir"]
|
|
|
|
def get_logs_dir() -> Path:
|
|
if "logs_dir" not in _RESOLVED:
|
|
_RESOLVED["logs_dir"] = _resolve_path("SLOP_LOGS_DIR", "logs_dir", "logs/sessions")
|
|
return _RESOLVED["logs_dir"]
|
|
|
|
def get_scripts_dir() -> Path:
|
|
if "scripts_dir" not in _RESOLVED:
|
|
_RESOLVED["scripts_dir"] = _resolve_path("SLOP_SCRIPTS_DIR", "scripts_dir", "scripts/generated")
|
|
return _RESOLVED["scripts_dir"]
|
|
|
|
def get_tracks_dir() -> Path:
|
|
return get_conductor_dir() / "tracks"
|
|
|
|
def get_track_state_dir(track_id: str) -> Path:
|
|
return get_tracks_dir() / track_id
|
|
|
|
def get_archive_dir() -> Path:
|
|
return get_conductor_dir() / "archive"
|
|
|
|
def reset_resolved() -> None:
|
|
"""For testing only - clear cached resolutions."""
|
|
_RESOLVED.clear()
|