updated database path logic

This commit is contained in:
2026-07-17 20:02:11 +02:00
parent d9325fce98
commit 2d48e1dace
4 changed files with 43 additions and 3 deletions
+13 -2
View File
@@ -39,7 +39,7 @@ class UrlPrefixMiddleware:
def load_yaml_config(path):
config_path = Path(path)
config_path = Path(path).expanduser().resolve()
if not config_path.is_file():
raise RuntimeError(
f"Configuration file not found: {config_path}. "
@@ -59,6 +59,14 @@ def load_yaml_config(path):
"URL_PREFIX": normalize_url_prefix(flask_config.get("url_prefix", "/fatima")),
"LOG_FILE": flask_config.get("log_file", "/tmp/fatima.log"),
}
configured_database = flask_config.get("database")
if configured_database is not None:
if not isinstance(configured_database, str) or not configured_database.strip():
raise RuntimeError(f"{config_path}: flask.database must be a non-empty path")
database_path = Path(configured_database).expanduser()
if not database_path.is_absolute():
database_path = config_path.parent / database_path
required["DATABASE"] = str(database_path.resolve())
missing = [
name for name, value in required.items()
if name != "URL_PREFIX" and (not isinstance(value, str) or not value)
@@ -119,7 +127,10 @@ def create_app(test_config=None):
app = Flask(__name__)
config_path = os.environ.get("APP_CONFIG", Path(app.root_path) / "config.yaml")
app.config.from_mapping(load_yaml_config(config_path))
app.config.setdefault("DATABASE", str(Path(app.instance_path) / "calendar.sqlite"))
app.config.setdefault(
"DATABASE",
str(Path(__file__).resolve().parent / "instance" / "calendar.sqlite"),
)
# Environment variables remain useful when deploying without a local file.
for name in ("SECRET_KEY", "APP_USERNAME", "APP_PASSWORD", "DATABASE", "LOG_FILE"):