Allow organization of wallpaper directory

This commit is contained in:
Michael Bradley 2025-06-14 18:31:42 -04:00
parent 4d44d82d4c
commit fd62f649d0
Signed by: MichaelBradley
SSH key fingerprint: SHA256:BKO2eI2LPsCbQS3n3i5SdwZTAIV3F1lHezR07qP+Ob0

View file

@ -1,5 +1,6 @@
"""Script to update the wallpaper"""
from abc import ABC, abstractmethod
from collections.abc import Iterator
from json import dumps, loads
from math import ceil, floor, isnan, nan
from os import environ
@ -70,11 +71,18 @@ class Wallpaper(Background):
if len(stringified) != cls._cache.write_text(stringified):
raise Exception("Did not fully write blue light cache to file")
@classmethod
def _files(cls) -> Iterator[Path]:
for (root, _, files) in cls._wallpapers.walk():
if root.name != "ignore":
for file in files:
yield root / file
@classmethod
def available(cls) -> "OrderedSet[Background]":
cache = cls._read_cache()
modified = False
wallpapers = {str(path): Wallpaper(path) for path in cls._wallpapers.iterdir()}
wallpapers = {str(path): Wallpaper(path) for path in cls._files()}
for wallpaper in wallpapers.values():
cached = cache.get(str(wallpaper._path))
if cached is None or isnan(cached):