Spaces:
Sleeping
Sleeping
File size: 994 Bytes
ba58433 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | """
Bundled avatar image registry.
Provides helpers for resolving and listing the avatar images shipped in
``app/assets/avatars/``.
"""
import logging
from functools import lru_cache
from pathlib import Path
logger = logging.getLogger(__name__)
_AVATARS_DIR = Path(__file__).resolve().parent.parent / "assets" / "avatars"
def get_bundled_avatar_path(name: str) -> Path | None:
"""Return the filesystem path for a bundled avatar, or *None* if the
file does not exist."""
if not _AVATARS_DIR.is_dir():
return None
candidate = _AVATARS_DIR / name
if candidate.is_file():
return candidate
return None
@lru_cache(maxsize=1)
def list_bundled_avatars() -> tuple[str, ...]:
"""Return the filenames of all bundled avatar images."""
if not _AVATARS_DIR.is_dir():
return ()
avatars = tuple(sorted(f.name for f in _AVATARS_DIR.iterdir() if f.is_file()))
logger.info("Found %d bundled avatar images.", len(avatars))
return avatars
|