import os import json import mysql.connector from util.logger import logger CONFIG_PATH = "config/db_config.json" def is_configured(): return os.path.exists(CONFIG_PATH) def load_config(): try: with open(CONFIG_PATH, "r") as file: return json.load(file) except Exception as e: logger.error(f"[DB-Config] Fehler beim Laden: {e}") return None def save_config(config): try: os.makedirs("config", exist_ok=True) with open(CONFIG_PATH, "w") as file: json.dump(config, file, indent=2) logger.info("[DB-Config] Konfiguration gespeichert.") except Exception as e: logger.error(f"[DB-Config] Fehler beim Speichern: {e}") def test_connection(config) -> bool: try: conn = mysql.connector.connect(**config) conn.close() return True except Exception as e: logger.warning(f"[DB-Check] Verbindung fehlgeschlagen: {e}") return False