photojawn/photoalbum/config.py
2024-08-03 08:35:17 -07:00

32 lines
825 B
Python

import logging
from dataclasses import dataclass
import yaml
DEFAULT_CONFIG_PATH = "photoalbum.conf.yml"
logger = logging.getLogger(__name__)
@dataclass
class Config:
# Size of thumbnails when looking at a folder page
thumbnail_size: tuple[int, int] = (128, 128)
# Size of the image when looking at the standalone image page
view_size: tuple[int, int] = (1920, 1080)
@classmethod
def from_yaml(cls, contents: bytes) -> "Config":
conf = cls()
data = yaml.safe_load(contents)
if data is None:
return conf
for key, val in data.items():
match key:
case "thumnail_size":
conf.thumbnail_size = tuple(val)
case "view_size":
conf.view_size = tuple(val)
return conf