Read config from file
This commit is contained in:
parent
e3816dfdb7
commit
a3c949c7d5
5 changed files with 110 additions and 13 deletions
|
|
@ -1,7 +1,12 @@
|
|||
import logging
|
||||
from dataclasses import dataclass
|
||||
|
||||
import yaml
|
||||
|
||||
DEFAULT_CONFIG_PATH = "photoalbum.conf.yml"
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@dataclass
|
||||
class Config:
|
||||
|
|
@ -11,4 +16,17 @@ class Config:
|
|||
# Size of the image when looking at the standalone image page
|
||||
view_size: tuple[int, int] = (1920, 1080)
|
||||
|
||||
# TODO: to/from file classmethods
|
||||
@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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue