fixxes over codex
This commit is contained in:
+28
-4
@@ -3,13 +3,37 @@ import os
|
||||
import json
|
||||
import logging
|
||||
|
||||
try:
|
||||
# Flask ist optional – bei Aufruf außerhalb des App-Contexts fallbacken wir
|
||||
from flask import current_app
|
||||
except Exception: # pragma: no cover - nur wenn Flask nicht verfügbar ist
|
||||
current_app = None
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
def load_configs(config_dir='configs'):
|
||||
def _resolve_config_dir(config_dir=None):
|
||||
"""
|
||||
Ermittelt den zu nutzenden Config-Pfad:
|
||||
1) Expliziter Parameter
|
||||
2) Flask current_app.config['CONFIG_DIR']
|
||||
3) Fallback: lokaler 'configs' Ordner
|
||||
"""
|
||||
if config_dir:
|
||||
return config_dir
|
||||
if current_app:
|
||||
try:
|
||||
return current_app.config.get('CONFIG_DIR', 'configs')
|
||||
except Exception:
|
||||
pass
|
||||
return 'configs'
|
||||
|
||||
|
||||
def load_configs(config_dir=None):
|
||||
"""
|
||||
Lädt alle .json-Konfigurationsdateien aus dem configs-Ordner,
|
||||
außer default_sounds.json (die wird separat geladen).
|
||||
"""
|
||||
config_dir = _resolve_config_dir(config_dir)
|
||||
configs = []
|
||||
if not os.path.exists(config_dir):
|
||||
logger.warning(f"Config-Verzeichnis nicht gefunden: {config_dir}")
|
||||
@@ -38,14 +62,14 @@ def load_configs(config_dir='configs'):
|
||||
return sorted(configs, key=lambda x: x.get('name', ''))
|
||||
|
||||
|
||||
def load_default_sounds(config_dir='configs'):
|
||||
def load_default_sounds(config_dir=None):
|
||||
"""
|
||||
Lädt die globalen Standard-Sounds aus configs/default_sounds.json
|
||||
Wird immer geladen, unabhängig von der aktuellen Lok-Konfiguration
|
||||
"""
|
||||
config_dir = _resolve_config_dir(config_dir)
|
||||
path = os.path.join(config_dir, 'default_sounds.json')
|
||||
data = json.load(f)
|
||||
|
||||
|
||||
if not os.path.exists(path):
|
||||
logger.info("Keine default_sounds.json gefunden → keine globalen Sounds")
|
||||
return []
|
||||
|
||||
Reference in New Issue
Block a user