fix(satellite): laedt .env selbst beim nativen Start
Nativ gestartet (python satellite.py) las das Script nichts aus der .env — nur os.environ. Die Variablen mit Default (SATELLITE_ID, CONTROL_ENABLED …) wirkten "ok", aber RVS_HOST/RVS_TOKEN (ohne Default) blieben leer → Verbindungsfehler. Jetzt laedt _load_dotenv() eine .env neben dem Script (oder im CWD), bevor die Config gelesen wird. Bestehende echte Umgebungsvariablen gewinnen (Docker via env_file bleibt unberuehrt). Kein python-dotenv noetig. README Weg B vereinfacht. Getestet: Parser liest Keys inkl. Quotes + export-Praefix. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -46,6 +46,38 @@ logging.basicConfig(
|
||||
logger = logging.getLogger("satellite")
|
||||
|
||||
|
||||
def _load_dotenv() -> None:
|
||||
"""Laedt eine .env neben dem Script (oder im CWD) in os.environ — fuer den
|
||||
NATIVEN Start (`python satellite.py`). In Docker sind die Variablen via
|
||||
env_file schon gesetzt; bereits gesetzte Werte gewinnen (werden NICHT
|
||||
ueberschrieben). Kein python-dotenv noetig."""
|
||||
here = os.path.dirname(os.path.abspath(__file__))
|
||||
for path in (os.path.join(here, ".env"), os.path.join(os.getcwd(), ".env")):
|
||||
if not os.path.isfile(path):
|
||||
continue
|
||||
try:
|
||||
with open(path, "r", encoding="utf-8") as f:
|
||||
for line in f:
|
||||
line = line.strip()
|
||||
if not line or line.startswith("#") or "=" not in line:
|
||||
continue
|
||||
key, _, val = line.partition("=")
|
||||
key = key.strip()
|
||||
if key.startswith("export "):
|
||||
key = key[len("export "):].strip()
|
||||
val = val.strip()
|
||||
if len(val) >= 2 and val[0] == val[-1] and val[0] in ("'", '"'):
|
||||
val = val[1:-1]
|
||||
if key and key not in os.environ:
|
||||
os.environ[key] = val
|
||||
except Exception as exc:
|
||||
logging.getLogger("satellite").warning(".env laden fehlgeschlagen (%s): %s", path, exc)
|
||||
break # erste gefundene .env gewinnt
|
||||
|
||||
|
||||
_load_dotenv()
|
||||
|
||||
|
||||
# ─── Konfiguration ──────────────────────────────────────────────────
|
||||
|
||||
def _env_bool(name: str, default: bool) -> bool:
|
||||
|
||||
Reference in New Issue
Block a user