Compare commits

...

3 commits

Author SHA1 Message Date
Emma Nora Theuer
9ba75569c9 Added fallback_wallpaper to general. 2024-06-03 19:30:21 +02:00
Emma Nora Theuer
fcd3b82894 Added a fallback wallpaper that gets set if a config error is detected, adjusted default loglevel 2024-06-03 19:29:41 +02:00
Emma Nora Theuer
009ab7cc4c Updated documentation for new feature. 2024-06-03 19:27:30 +02:00
3 changed files with 53 additions and 10 deletions

View file

@ -41,7 +41,7 @@ This is a short guide on how to correctly configure wallman. Look in the sample
** TOML Dictionaries ** TOML Dictionaries
First of all, the config file is structured via different TOML dictionaries. There are two TOML dictionaries: general and changing_times that must be present in every config. Aside from that, further dictionaries are needed depending on how wallman is configured. You need to create a dictionary with the name of each wallpaper set defined in the used_sets list (more on that later). You should probably just configure wallman by editing the sample config as it is by far the easiest way to do it. First of all, the config file is structured via different TOML dictionaries. There are two TOML dictionaries: general and changing_times that must be present in every config. Aside from that, further dictionaries are needed depending on how wallman is configured. You need to create a dictionary with the name of each wallpaper set defined in the used_sets list (more on that later). You should probably just configure wallman by editing the sample config as it is by far the easiest way to do it.
*** general *** general
In general, you need to always define 3 variables and you can optionally add one more: In general, you need to always define 3 variables and you can optionally add two more:
+ enable_wallpaper_sets: bool + enable_wallpaper_sets: bool
A simple switch that states if you want to use different sets of wallpapers or not. A simple switch that states if you want to use different sets of wallpapers or not.
+ used_sets: list + used_sets: list
@ -50,6 +50,8 @@ In general, you need to always define 3 variables and you can optionally add one
The amount of wallpapers that you use in each set. It should be an integer. The amount of wallpapers that you use in each set. It should be an integer.
+ Optional: notify: bool + Optional: notify: bool
This defaults to "false". Enable to set send a desktop notification when the wallpaper is changed. The program will still work correctly, even if this option is not defined at all. This defaults to "false". Enable to set send a desktop notification when the wallpaper is changed. The program will still work correctly, even if this option is not defined at all.
+ Optional: fallback_wallpaper: bool
Wallpaper to be set if an error is found in the config. Defaults to None. If none is set and the config is written incorrectly, a ConfigError is raised and the program is exited. If an error in the config occurs but the fallback wallpaper has been defined, it will be set and wallman will exit with Code 1.
*** changing_times *** changing_times
The changing_times dictionary is used to specify the times of the day when your wallpaper is switched. The names of the keys do not matter here, the values must always be strings in the "XX:YY:ZZ" 24 hour time system. use 00:00:00 for midnight. Note that XX should be in the range of 00-23 and YY and ZZ should be in the range of 00-59. The changing_times dictionary is used to specify the times of the day when your wallpaper is switched. The names of the keys do not matter here, the values must always be strings in the "XX:YY:ZZ" 24 hour time system. use 00:00:00 for midnight. Note that XX should be in the range of 00-23 and YY and ZZ should be in the range of 00-59.

View file

@ -5,6 +5,7 @@ enable_wallpaper_sets = true
used_sets = ["anime", "nature"] used_sets = ["anime", "nature"]
wallpapers_per_set = 5 wallpapers_per_set = 5
notify = False notify = False
fallback_wallpaper = "/path/to/paper"
# Enter the hours at which you want the wallpaper to change. # Enter the hours at which you want the wallpaper to change.
# If the script is called between one of this times, it will go back to the previous time. # If the script is called between one of this times, it will go back to the previous time.

View file

@ -1,4 +1,5 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
from sys import exit
from os import chdir, getenv, system from os import chdir, getenv, system
import logging import logging
import tomllib import tomllib
@ -9,7 +10,7 @@ from apscheduler.triggers.cron import CronTrigger
# setup logging # setup logging
chdir(str(getenv("HOME")) + "/.local/share/wallman/") chdir(str(getenv("HOME")) + "/.local/share/wallman/")
logger = logging.getLogger(__name__) 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 # read config
# a = list(data["changing_times"].values()) # a = list(data["changing_times"].values())
@ -43,22 +44,48 @@ class _ConfigLib:
self.config_notify = False self.config_notify = False
logger.warning("'notify' is not set in dictionary general in the config file, defaulting to '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): class ConfigValidity(_ConfigLib):
def __init__(self): def __init__(self):
super().__init__() 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: def _check_wallpapers_per_set_and_changing_times(self) -> None:
# Check if the amount of wallpapers_per_set and given changing times match # Check if the amount of wallpapers_per_set and given changing times match
if self.config_total_changing_times == self.config_wallpapers_per_set: 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") logger.debug("The amount of changing times and wallpapers per set is set correctly")
else: else:
logger.error("The amount of changing times and the amount of wallpapers per set does not match.") try:
raise ConfigError("Please provide an amount of changing_times equal to wallpapers_per_set.") 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: def _check_general_validity(self) -> None:
if len(self.config_general) < 3: if len(self.config_general) < 3:
logger.error("An insufficient amount of parameters for general has been provided, exiting...") try:
raise ConfigError("general should have at least 3 elements") 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: def _check_wallpaper_dicts(self)-> None:
# This block checks if a dictionary for each wallpaper set exists # 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: if wallpaper_set in self.config_file:
logger.debug(f"The dictionary {wallpaper_set} has been found in config.") logger.debug(f"The dictionary {wallpaper_set} has been found in config.")
else: else:
logger.error(f"No dictionary {wallpaper_set} has been found in the config.") try:
raise ConfigError(f"The dictionary {wallpaper_set} has not been found in the config") 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: def _check_wallpaper_amount(self) -> None:
# This block checks if if each wallpaper set dictionary provides enough wallpapers to satisfy wallpapers_per_set # 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: if len(self.config_file[wallpaper_set]) == self.config_wallpapers_per_set:
logger.debug(f"Dictionary {wallpaper_set} has sufficient values.") logger.debug(f"Dictionary {wallpaper_set} has sufficient values.")
else: else:
logger.error(f"Dictionary {wallpaper_set} does not have sufficient entries") try:
raise ConfigError(f"Dictionary {wallpaper_set} does not have the correct amount of entries") 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: def validate_config(self) -> None:
self._check_fallback_wallpaper()
self._check_wallpapers_per_set_and_changing_times() self._check_wallpapers_per_set_and_changing_times()
self._check_general_validity() self._check_general_validity()
self._check_wallpaper_dicts() self._check_wallpaper_dicts()