Init photobooth - borne photo evenementielle RPi4
Backend FastAPI complet : camera gphoto2, filtres/overlays Pillow, chroma key OpenCV, multi-shot/collage, GIF, impression CUPS, email SMTP, QR code. Frontend web vanilla (HTML/CSS/JS) pour Chromium kiosk. Menu admin cache (appui long coin ecran). Toutes les fonctionnalites activables/desactivables. Scripts install + systemd pour RPi4. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
52
backend/config.py
Normal file
52
backend/config.py
Normal file
@@ -0,0 +1,52 @@
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
|
||||
RACINE = Path(__file__).resolve().parent.parent
|
||||
CHEMIN_CONFIG = RACINE / "data" / "config.json"
|
||||
CHEMIN_CONFIG_DEFAUT = RACINE / "data" / "config.defaut.json"
|
||||
DOSSIER_PHOTOS = RACINE / "data" / "photos"
|
||||
DOSSIER_EXPORTS = RACINE / "data" / "exports"
|
||||
DOSSIER_OVERLAYS = RACINE / "frontend" / "assets" / "overlays"
|
||||
DOSSIER_FONDS = RACINE / "frontend" / "assets" / "backgrounds"
|
||||
|
||||
|
||||
def charger_config() -> dict:
|
||||
"""Charge la configuration depuis config.json."""
|
||||
if not CHEMIN_CONFIG.exists():
|
||||
if CHEMIN_CONFIG_DEFAUT.exists():
|
||||
shutil.copy(CHEMIN_CONFIG_DEFAUT, CHEMIN_CONFIG)
|
||||
else:
|
||||
return {}
|
||||
with open(CHEMIN_CONFIG, "r", encoding="utf-8") as f:
|
||||
return json.load(f)
|
||||
|
||||
|
||||
def sauvegarder_config(config: dict):
|
||||
"""Sauvegarde la configuration dans config.json."""
|
||||
CHEMIN_CONFIG.parent.mkdir(parents=True, exist_ok=True)
|
||||
with open(CHEMIN_CONFIG, "w", encoding="utf-8") as f:
|
||||
json.dump(config, f, ensure_ascii=False, indent=2)
|
||||
|
||||
|
||||
def mettre_a_jour_config(modifications: dict) -> dict:
|
||||
"""Met a jour la configuration avec les modifications fournies (merge profond)."""
|
||||
config = charger_config()
|
||||
_merge_profond(config, modifications)
|
||||
sauvegarder_config(config)
|
||||
return config
|
||||
|
||||
|
||||
def _merge_profond(base: dict, modifications: dict):
|
||||
"""Fusionne recursivement les modifications dans la base."""
|
||||
for cle, valeur in modifications.items():
|
||||
if cle in base and isinstance(base[cle], dict) and isinstance(valeur, dict):
|
||||
_merge_profond(base[cle], valeur)
|
||||
else:
|
||||
base[cle] = valeur
|
||||
|
||||
|
||||
# Initialisation des dossiers au chargement du module
|
||||
for dossier in [DOSSIER_PHOTOS, DOSSIER_EXPORTS, DOSSIER_OVERLAYS, DOSSIER_FONDS]:
|
||||
dossier.mkdir(parents=True, exist_ok=True)
|
||||
Reference in New Issue
Block a user