"""Where the browser keeps what a cell did not name a path for.""" from __future__ import annotations import os import time from pathlib import Path # A screenshot nobody kept is not worth the disk after this long. SCREENSHOT_TTL_SECONDS = 7 * 24 * 60 * 60 def home() -> Path: return Path(os.environ.get("ALBEDO_HOME") or "~/.albedo").expanduser() def screenshots() -> Path: """Default screenshots go to the cache, never into the working tree.""" return home() / "cache" / "browser-screenshots" def prune(directory: Path, *, now: float | None = None) -> None: """Removes the PNGs in `directory` last written before the time-to-live.""" cutoff = (time.time() if now is None else now) - SCREENSHOT_TTL_SECONDS try: entries = list(directory.glob("*.png")) except OSError: return for entry in entries: try: if entry.stat().st_mtime < cutoff: entry.unlink() except OSError: pass