File transfer
This commit is contained in:
		
							parent
							
								
									e24b69597b
								
							
						
					
					
						commit
						c31c452f7e
					
				
					 3 changed files with 24 additions and 11 deletions
				
			
		
							
								
								
									
										
											BIN
										
									
								
								DefaultFallbackWallpaper.jpg
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								DefaultFallbackWallpaper.jpg
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 508 KiB  | 
| 
						 | 
				
			
			@ -5,7 +5,7 @@ enable_wallpaper_sets = true
 | 
			
		|||
used_sets = ["anime", "nature"]
 | 
			
		||||
wallpapers_per_set = 5
 | 
			
		||||
notify = false
 | 
			
		||||
fallback_wallpaper = "/path/to/paper"
 | 
			
		||||
fallback_wallpaper = "/etc/wallman/DefaultFallbackWallpaper.jpg"
 | 
			
		||||
loglevel = "INFO"
 | 
			
		||||
systray = true
 | 
			
		||||
behavior = "fill"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -13,7 +13,7 @@ from wallman.wallman_classes import ConfigError, ConfigGeneral, ConfigFile
 | 
			
		|||
global logger
 | 
			
		||||
logger = logging.getLogger("wallman")
 | 
			
		||||
 | 
			
		||||
class _ConfigLib:
 | 
			
		||||
class _Config:
 | 
			
		||||
    # Initializes the most important config values. TODO: Add handling for the empty config edge case and the FileNotFound case
 | 
			
		||||
    def __init__(self) -> None:
 | 
			
		||||
        self.config_file: ConfigFile = self._initialize_config() # Full config
 | 
			
		||||
| 
						 | 
				
			
			@ -45,7 +45,7 @@ class _ConfigLib:
 | 
			
		|||
        if self.config_systray:
 | 
			
		||||
            self._verify_systray_deps()
 | 
			
		||||
 | 
			
		||||
    # Read config. TODO: Add error handling for the config not found case.
 | 
			
		||||
    # Read config
 | 
			
		||||
    def _initialize_config(self) -> ConfigFile:
 | 
			
		||||
        chdir(str(getenv("HOME")) + "/.config/wallman/")
 | 
			
		||||
        try:
 | 
			
		||||
| 
						 | 
				
			
			@ -76,14 +76,12 @@ class _ConfigLib:
 | 
			
		|||
            system("touch wallman.log")
 | 
			
		||||
        logging.basicConfig(filename="wallman.log", encoding="utf-8", level=numeric_level)
 | 
			
		||||
 | 
			
		||||
    # TODO: Make this all just work inside the try/except block, there is no need for get()
 | 
			
		||||
    # TODO: Adjust these variable names
 | 
			
		||||
    def _set_behavior(self) -> str:
 | 
			
		||||
        try:
 | 
			
		||||
            self.config_general.get("behavior")
 | 
			
		||||
            behavior = self.config_general["behavior"]
 | 
			
		||||
        except KeyError:
 | 
			
		||||
            logger.error("There is no wallpaper behavior specified in general, defaulting to fill...")
 | 
			
		||||
            print("ERROR: There is no wallpaper behavior specified in general, defaulting to fill...")
 | 
			
		||||
            logger.warning("There is no wallpaper behavior specified in general, defaulting to fill...")
 | 
			
		||||
            print("WARNING: There is no wallpaper behavior specified in general, defaulting to fill...")
 | 
			
		||||
 | 
			
		||||
        human_behaviors: List[str] = ["plain", "tile", "center", "fill", "max", "scale"]
 | 
			
		||||
        machine_behaviors: List[str] = ["--bg", "--bg-tile", "--bg-center", "--bg-fill", "--bg-max", "--bg-scale"]
 | 
			
		||||
| 
						 | 
				
			
			@ -110,7 +108,6 @@ class _ConfigLib:
 | 
			
		|||
        logger.info(f"The wallpaper behavior '{behavior}' has been set.")
 | 
			
		||||
        return behavior
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    def _set_fallback_wallpaper(self) -> None:
 | 
			
		||||
        if self.config_general["fallback_wallpaper"]:
 | 
			
		||||
            system(f"feh {self.config_behavior} --no-fehbg {self.config_general['fallback_wallpaper']}")
 | 
			
		||||
| 
						 | 
				
			
			@ -119,6 +116,23 @@ class _ConfigLib:
 | 
			
		|||
            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...")
 | 
			
		||||
 | 
			
		||||
    def _initialize_general(self) -> bool:
 | 
			
		||||
        # Create Config General Dict
 | 
			
		||||
        try:
 | 
			
		||||
            self.config_general: ConfigGeneral = self.config_file["general"]
 | 
			
		||||
        except KeyError:
 | 
			
		||||
            print("CRITICAL: No general dictionary found in Config file.")
 | 
			
		||||
            return False
 | 
			
		||||
        # Set up logger.
 | 
			
		||||
        self.config_log_level = self.config_general.get("log_level", "INFO").upper()
 | 
			
		||||
        self._set_log_level()
 | 
			
		||||
        logger.debug(f"Log level has been set to {self.config_log_level}")
 | 
			
		||||
        logger.debug("Logger initialized successfully")
 | 
			
		||||
        # Set up fallback wallpaper
 | 
			
		||||
 | 
			
		||||
        return True
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class ConfigValidity(_ConfigLib):
 | 
			
		||||
    # TODO: Add handling for the empty config case.
 | 
			
		||||
    def __init__(self):
 | 
			
		||||
| 
						 | 
				
			
			@ -201,7 +215,6 @@ class ConfigValidity(_ConfigLib):
 | 
			
		|||
        return False
 | 
			
		||||
 | 
			
		||||
    def validate_config(self) -> bool:
 | 
			
		||||
        # NOTE: Consider changing this to exit(-1)
 | 
			
		||||
        # HACK: Consider using different exit codes for different errors to help users debug.
 | 
			
		||||
        if not self._check_fallback_wallpaper():
 | 
			
		||||
            pass
 | 
			
		||||
| 
						 | 
				
			
			@ -218,7 +231,7 @@ class ConfigValidity(_ConfigLib):
 | 
			
		|||
 | 
			
		||||
# TODO: Improve modularity. See notes inside the class for more details.
 | 
			
		||||
# TODO: Ensure functionality and if needed add handling for the 1 wallpaper per set case.
 | 
			
		||||
class WallpaperLogic(_ConfigLib):
 | 
			
		||||
class WallpaperLogic(_Config):
 | 
			
		||||
    def __init__(self) -> None:
 | 
			
		||||
        super().__init__()
 | 
			
		||||
        self.wallpaper_list: List[str] = None # pyright: ignore
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue