Spaces:
Sleeping
Sleeping
| """Utility helpers: logging setup, path handling, JSON read/write.""" | |
| from pathlib import Path | |
| import json | |
| import logging | |
| ROOT = Path(__file__).resolve().parents[1] | |
| LOGS_DIR = ROOT / "logs" | |
| LOGS_DIR.mkdir(exist_ok=True) | |
| logging.basicConfig( | |
| filename=LOGS_DIR / "drs.log", | |
| level=logging.INFO, | |
| format="%(asctime)s [%(levelname)s] %(message)s", | |
| ) | |
| logger = logging.getLogger("drs") | |
| def ensure_dir(path: Path): | |
| """Create directory if absent.""" | |
| path.mkdir(parents=True, exist_ok=True) | |
| def read_json(fp: Path): | |
| with open(fp, "r", encoding="utf-8") as f: | |
| return json.load(f) | |
| def write_json(obj, fp: Path): | |
| ensure_dir(fp.parent) | |
| with open(fp, "w", encoding="utf-8") as f: | |
| json.dump(obj, f, indent=2) |