feat(data): use generate_default_toml() in load_config fallback
This commit is contained in:
1 file changed
+26
-10
+26
-10
@@ -49,19 +49,35 @@ def load_config():
|
|||||||
service = start_config_service()
|
service = start_config_service()
|
||||||
return service.get_all()
|
return service.get_all()
|
||||||
except ImportError:
|
except ImportError:
|
||||||
# Fallback to direct file loading
|
pass
|
||||||
config = {}
|
|
||||||
|
|
||||||
if os.path.exists(CONFIG_FILE):
|
try:
|
||||||
try:
|
from utils.constants import generate_default_toml
|
||||||
import tomlkit
|
except ImportError:
|
||||||
|
generate_default_toml = None
|
||||||
|
|
||||||
with open(CONFIG_FILE) as f:
|
config = {}
|
||||||
config = dict(tomlkit.load(f))
|
|
||||||
except Exception as e:
|
|
||||||
logger.error(f"Error loading config: {e}")
|
|
||||||
|
|
||||||
return config
|
if os.path.exists(CONFIG_FILE):
|
||||||
|
try:
|
||||||
|
import tomlkit
|
||||||
|
|
||||||
|
with open(CONFIG_FILE) as f:
|
||||||
|
config = dict(tomlkit.load(f))
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Error loading config: {e}")
|
||||||
|
elif generate_default_toml:
|
||||||
|
try:
|
||||||
|
raw = generate_default_toml()
|
||||||
|
with open(CONFIG_FILE, "w") as f:
|
||||||
|
f.write(raw)
|
||||||
|
import tomlkit
|
||||||
|
|
||||||
|
config = dict(tomlkit.loads(raw))
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Error generating default config: {e}")
|
||||||
|
|
||||||
|
return config
|
||||||
|
|
||||||
|
|
||||||
NOTIFICATION_TIMEOUT_STR = "5s"
|
NOTIFICATION_TIMEOUT_STR = "5s"
|
||||||
|
|||||||
Reference in new issue
Block a user