Add settings from environment and .env
This commit is contained in:
1 parent
a782770e57
commit
38a6d9e1d7
1 file changed
+32
@@ -0,0 +1,32 @@
|
|||||||
|
"""Settings, from environment variables or a .env file in the repo root (real environment variables win)."""
|
||||||
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
|
ROOT = Path(__file__).resolve().parent.parent
|
||||||
|
|
||||||
|
|
||||||
|
def load_env(path):
|
||||||
|
if not path.exists():
|
||||||
|
return
|
||||||
|
for line in path.read_text(encoding="utf-8").splitlines():
|
||||||
|
line = line.strip()
|
||||||
|
if line and not line.startswith("#") and "=" in line:
|
||||||
|
key, value = line.split("=", 1)
|
||||||
|
os.environ.setdefault(key.strip(), value.strip().strip("'\""))
|
||||||
|
|
||||||
|
|
||||||
|
load_env(ROOT / ".env") # before anything reads os.environ, including parentcalendar.extraction
|
||||||
|
|
||||||
|
PUBLIC_URL = os.environ.get("PUBLIC_URL", "").rstrip("/")
|
||||||
|
DATA_DIR = Path(os.environ.get("DATA_DIR", ROOT / "data"))
|
||||||
|
IMAGES_DIR = DATA_DIR / "images"
|
||||||
|
DB_PATH = DATA_DIR / "parentcalendar.db"
|
||||||
|
STATIC_DIR = ROOT / "static"
|
||||||
|
HOST = os.environ.get("HOST", "127.0.0.1")
|
||||||
|
PORT = int(os.environ.get("PORT", "8000"))
|
||||||
|
IMAGE_RETENTION_DAYS = int(os.environ.get("IMAGE_RETENTION_DAYS", "90"))
|
||||||
|
MAX_UPLOAD_BYTES = 25 * 1024 * 1024 # per file
|
||||||
|
CANCELLED_DAYS = 30 # deleted events stay in exports as STATUS:CANCELLED this long
|
||||||
|
# Stored in each new event's UID; changing PUBLIC_URL later never changes existing UIDs.
|
||||||
|
UID_DOMAIN = urlparse(PUBLIC_URL).hostname or "parentcalendar.local"
|
||||||
Reference in new issue
Block a user