From ebfc3c9845e2a51a69ea3f196c8632d43b1a0f23 Mon Sep 17 00:00:00 2001 From: MarekWo Date: Sun, 1 Mar 2026 06:57:08 +0100 Subject: [PATCH] feat(v2): Add v2 config settings (DB, TCP, backup) New environment variables for Phase 0: - MC_DB_PATH: SQLite database location - MC_TCP_HOST/MC_TCP_PORT: TCP transport (meshcore-proxy) - MC_BACKUP_ENABLED/HOUR/RETENTION_DAYS: automated backup - MC_AUTO_RECONNECT, MC_LOG_LEVEL: connection management Co-Authored-By: Claude Opus 4.6 --- app/config.py | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/app/config.py b/app/config.py index c088374..e9fd439 100644 --- a/app/config.py +++ b/app/config.py @@ -18,14 +18,30 @@ class Config: MC_DEVICE_NAME = os.getenv('MC_DEVICE_NAME', 'MeshCore') MC_CONFIG_DIR = os.getenv('MC_CONFIG_DIR', '/root/.config/meshcore') - # MeshCore Bridge configuration + # MeshCore Bridge configuration (v1 — will be removed in Phase 1) MC_BRIDGE_URL = os.getenv('MC_BRIDGE_URL', 'http://meshcore-bridge:5001/cli') - # Archive configuration + # Archive configuration (v1 — archives move to SQLite in v2) MC_ARCHIVE_DIR = os.getenv('MC_ARCHIVE_DIR', '/root/.archive/meshcore') MC_ARCHIVE_ENABLED = os.getenv('MC_ARCHIVE_ENABLED', 'true').lower() == 'true' MC_ARCHIVE_RETENTION_DAYS = int(os.getenv('MC_ARCHIVE_RETENTION_DAYS', '7')) + # v2: Database + MC_DB_PATH = os.getenv('MC_DB_PATH', '') # empty = auto: {MC_CONFIG_DIR}/mc-webui.db + + # v2: TCP connection (alternative to serial, e.g. meshcore-proxy) + MC_TCP_HOST = os.getenv('MC_TCP_HOST', '') # empty = use serial + MC_TCP_PORT = int(os.getenv('MC_TCP_PORT', '5000')) + + # v2: Backup + MC_BACKUP_ENABLED = os.getenv('MC_BACKUP_ENABLED', 'true').lower() == 'true' + MC_BACKUP_HOUR = int(os.getenv('MC_BACKUP_HOUR', '2')) + MC_BACKUP_RETENTION_DAYS = int(os.getenv('MC_BACKUP_RETENTION_DAYS', '7')) + + # v2: Connection + MC_AUTO_RECONNECT = os.getenv('MC_AUTO_RECONNECT', 'true').lower() == 'true' + MC_LOG_LEVEL = os.getenv('MC_LOG_LEVEL', 'INFO') + # Flask server configuration FLASK_HOST = os.getenv('FLASK_HOST', '0.0.0.0') FLASK_PORT = int(os.getenv('FLASK_PORT', '5000')) @@ -42,10 +58,23 @@ class Config: """Get the full path to archive directory""" return Path(self.MC_ARCHIVE_DIR) + @property + def db_path(self) -> Path: + """Get SQLite database path""" + if self.MC_DB_PATH: + return Path(self.MC_DB_PATH) + return Path(self.MC_CONFIG_DIR) / 'mc-webui.db' + + @property + def use_tcp(self) -> bool: + """True if TCP transport should be used instead of serial""" + return bool(self.MC_TCP_HOST) + def __repr__(self): + transport = f"tcp={self.MC_TCP_HOST}:{self.MC_TCP_PORT}" if self.use_tcp else f"serial={self.MC_SERIAL_PORT}" return ( f"Config(device={self.MC_DEVICE_NAME}, " - f"port={self.MC_SERIAL_PORT}, " + f"{transport}, " f"config_dir={self.MC_CONFIG_DIR})" )