pre uart exchange
This commit is contained in:
48
tool/core/config.py
Normal file
48
tool/core/config.py
Normal file
@@ -0,0 +1,48 @@
|
||||
# tool/core/config.py
|
||||
import os
|
||||
import yaml
|
||||
from pathlib import Path
|
||||
|
||||
class Config:
|
||||
def __init__(self):
|
||||
self._config = None
|
||||
self.config_name = "config.yaml"
|
||||
self.custom_path = None # Speicher für den Parameter-Pfad
|
||||
self.debug = False
|
||||
|
||||
def _load(self):
|
||||
if self._config is not None:
|
||||
return
|
||||
|
||||
from core.utils import console
|
||||
|
||||
search_paths = []
|
||||
if self.custom_path:
|
||||
search_paths.append(Path(self.custom_path))
|
||||
|
||||
search_paths.append(Path(os.getcwd()) / self.config_name)
|
||||
search_paths.append(Path(__file__).parent.parent / self.config_name)
|
||||
|
||||
config_path = None
|
||||
for p in search_paths:
|
||||
if p.exists():
|
||||
config_path = p
|
||||
break
|
||||
|
||||
if not config_path:
|
||||
raise FileNotFoundError(f"Konfiguration konnte an keinem Ort gefunden werden.")
|
||||
|
||||
if not config_path.exists():
|
||||
raise FileNotFoundError(f"Konfiguration nicht gefunden: {self.config_name}")
|
||||
else:
|
||||
if self.debug: console.print(f"[bold green]✓[/bold green] Konfiguration geladen: [info]{config_path}[/info]")
|
||||
|
||||
with open(config_path, 'r') as f:
|
||||
self._config = yaml.safe_load(f)
|
||||
|
||||
@property
|
||||
def serial_settings(self):
|
||||
self._load()
|
||||
return self._config.get('serial', {})
|
||||
|
||||
cfg = Config()
|
||||
Reference in New Issue
Block a user