|
|
|
@ -1,4 +1,5 @@
|
|
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
from sys import exit
|
|
|
|
|
from os import chdir, getenv, system
|
|
|
|
|
import logging
|
|
|
|
|
import tomllib
|
|
|
|
@ -9,7 +10,7 @@ from apscheduler.triggers.cron import CronTrigger
|
|
|
|
|
# setup logging
|
|
|
|
|
chdir(str(getenv("HOME")) + "/.local/share/wallman/")
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
logging.basicConfig(filename="wallman.log", encoding="utf-8", level=logging.DEBUG)
|
|
|
|
|
logging.basicConfig(filename="wallman.log", encoding="utf-8", level=logging.WARNING)
|
|
|
|
|
|
|
|
|
|
# read config
|
|
|
|
|
# a = list(data["changing_times"].values())
|
|
|
|
@ -43,22 +44,48 @@ class _ConfigLib:
|
|
|
|
|
self.config_notify = False
|
|
|
|
|
logger.warning("'notify' is not set in dictionary general in the config file, defaulting to 'false'.")
|
|
|
|
|
|
|
|
|
|
def _set_fallback_wallpaper(self):
|
|
|
|
|
if self.config_general["fallback_wallpaper"]:
|
|
|
|
|
system(f"feh --bg-fill --no-fehbg {self.config_general['fallback_wallpaper']}")
|
|
|
|
|
logger.info("The fallback Wallpaper has been set.")
|
|
|
|
|
else:
|
|
|
|
|
logger.critical("An Error occured and no fallback wallpaper was provided, exiting...")
|
|
|
|
|
raise ConfigError("An error occured and no fallback wallpaper has been set, exiting...")
|
|
|
|
|
|
|
|
|
|
class ConfigValidity(_ConfigLib):
|
|
|
|
|
def __init__(self):
|
|
|
|
|
super().__init__()
|
|
|
|
|
|
|
|
|
|
def _check_fallback_wallpaper(self):
|
|
|
|
|
if self.config_general["fallback_wallpaper"]:
|
|
|
|
|
logger.debug("A fallback wallpaper has been defined.")
|
|
|
|
|
else:
|
|
|
|
|
logger.warning("No fallback wallpaper has been provided. If the config is written incorrectly, the program will not be able to be executed.")
|
|
|
|
|
|
|
|
|
|
def _check_wallpapers_per_set_and_changing_times(self) -> None:
|
|
|
|
|
# Check if the amount of wallpapers_per_set and given changing times match
|
|
|
|
|
if self.config_total_changing_times == self.config_wallpapers_per_set:
|
|
|
|
|
logger.debug("The amount of changing times and wallpapers per set is set correctly")
|
|
|
|
|
else:
|
|
|
|
|
logger.error("The amount of changing times and the amount of wallpapers per set does not match.")
|
|
|
|
|
raise ConfigError("Please provide an amount of changing_times equal to wallpapers_per_set.")
|
|
|
|
|
try:
|
|
|
|
|
self._set_fallback_wallpaper()
|
|
|
|
|
logger.error("The amount of changing_times and the amount of wallpapers_per_set does not much, the fallback wallpaper has been set.")
|
|
|
|
|
print("ERROR: The amount of changing_times and the amount of wallpapers_per_set does not much, the fallback wallpaper has been set.")
|
|
|
|
|
exit(1)
|
|
|
|
|
except ConfigError:
|
|
|
|
|
logger.critical("The amount of changing times and the amount of wallpapers per set does not match, exiting...")
|
|
|
|
|
raise ConfigError("Please provide an amount of changing_times equal to wallpapers_per_set, exiting...")
|
|
|
|
|
|
|
|
|
|
def _check_general_validity(self) -> None:
|
|
|
|
|
if len(self.config_general) < 3:
|
|
|
|
|
logger.error("An insufficient amount of parameters for general has been provided, exiting...")
|
|
|
|
|
raise ConfigError("general should have at least 3 elements")
|
|
|
|
|
try:
|
|
|
|
|
self._set_fallback_wallpaper()
|
|
|
|
|
logger.error("An insufficient amount of elements has been provided for general, the fallback wallpaper has been set.")
|
|
|
|
|
print("ERROR: An insufficient amount of wallpapers has been provided for general, the fallback wallpaper has been set.")
|
|
|
|
|
exit(1)
|
|
|
|
|
except ConfigError:
|
|
|
|
|
logger.critical("An insufficient amount of elements for general has been provided, exiting...")
|
|
|
|
|
raise ConfigError("general should have at least 3 elements, exiting...")
|
|
|
|
|
|
|
|
|
|
def _check_wallpaper_dicts(self)-> None:
|
|
|
|
|
# This block checks if a dictionary for each wallpaper set exists
|
|
|
|
@ -66,8 +93,14 @@ class ConfigValidity(_ConfigLib):
|
|
|
|
|
if wallpaper_set in self.config_file:
|
|
|
|
|
logger.debug(f"The dictionary {wallpaper_set} has been found in config.")
|
|
|
|
|
else:
|
|
|
|
|
logger.error(f"No dictionary {wallpaper_set} has been found in the config.")
|
|
|
|
|
raise ConfigError(f"The dictionary {wallpaper_set} has not been found in the config")
|
|
|
|
|
try:
|
|
|
|
|
self._set_fallback_wallpaper()
|
|
|
|
|
logger.error(f"The dictionary {wallpaper_set} has not been found in the config, the fallback wallpaper has been set.")
|
|
|
|
|
print(f"ERROR: The dictionary {wallpaper_set} has not been found in the config, the fallback wallpaper has been set.")
|
|
|
|
|
exit(1)
|
|
|
|
|
except ConfigError:
|
|
|
|
|
logger.critical(f"No dictionary {wallpaper_set} has been found in the config exiting...")
|
|
|
|
|
raise ConfigError(f"The dictionary {wallpaper_set} has not been found in the config, exiting...")
|
|
|
|
|
|
|
|
|
|
def _check_wallpaper_amount(self) -> None:
|
|
|
|
|
# This block checks if if each wallpaper set dictionary provides enough wallpapers to satisfy wallpapers_per_set
|
|
|
|
@ -75,10 +108,17 @@ class ConfigValidity(_ConfigLib):
|
|
|
|
|
if len(self.config_file[wallpaper_set]) == self.config_wallpapers_per_set:
|
|
|
|
|
logger.debug(f"Dictionary {wallpaper_set} has sufficient values.")
|
|
|
|
|
else:
|
|
|
|
|
logger.error(f"Dictionary {wallpaper_set} does not have sufficient entries")
|
|
|
|
|
raise ConfigError(f"Dictionary {wallpaper_set} does not have the correct amount of entries")
|
|
|
|
|
try:
|
|
|
|
|
self._set_fallback_wallpaper()
|
|
|
|
|
logger.error(f"The Dictionary {wallpaper_set} does not have sufficient entries, the fallback wallpaper has been set.")
|
|
|
|
|
print(f"ERROR: The Dictionaty {wallpaper_set} does not have sufficient entries, the fallback wallpaper has been set.")
|
|
|
|
|
exit(1)
|
|
|
|
|
except ConfigError:
|
|
|
|
|
logger.critical(f"Dictionary {wallpaper_set} does not have sufficient entries, exciting...")
|
|
|
|
|
raise ConfigError(f"Dictionary {wallpaper_set} does not have the correct amount of entries, exciting...")
|
|
|
|
|
|
|
|
|
|
def validate_config(self) -> None:
|
|
|
|
|
self._check_fallback_wallpaper()
|
|
|
|
|
self._check_wallpapers_per_set_and_changing_times()
|
|
|
|
|
self._check_general_validity()
|
|
|
|
|
self._check_wallpaper_dicts()
|
|
|
|
|