- Added logging to the VM wallpaper retrieval function to capture errors and warnings related to content retrieval and file creation. - Implemented checks for None, empty, and invalid content types to ensure robustness in wallpaper handling. - Enhanced the SSIM structure check function with size validation and improved error handling for image processing. - Added logging for image size discrepancies and exceptions during SSIM computation to aid in debugging. These changes improve error handling and logging, ensuring better maintainability and reliability of the evaluators.
51 lines
1.5 KiB
Python
51 lines
1.5 KiB
Python
import os
|
|
import logging
|
|
from typing import Union
|
|
|
|
logger = logging.getLogger("desktopenv.getters.info")
|
|
|
|
|
|
def get_vm_screen_size(env, config: dict) -> dict:
|
|
return env.controller.get_vm_screen_size()
|
|
|
|
|
|
def get_vm_window_size(env, config: dict) -> dict:
|
|
return env.controller.get_vm_window_size(app_class_name=config["app_class_name"])
|
|
|
|
|
|
def get_vm_wallpaper(env, config: dict) -> Union[str, bytes]:
|
|
_path = os.path.join(env.cache_dir, config["dest"])
|
|
|
|
content = env.controller.get_vm_wallpaper()
|
|
|
|
# Check if content is None or empty
|
|
if content is None:
|
|
logger.error("Failed to get VM wallpaper: controller returned None")
|
|
# Create an empty file to prevent downstream errors
|
|
with open(_path, "wb") as f:
|
|
f.write(b"")
|
|
return _path
|
|
|
|
if not isinstance(content, bytes):
|
|
logger.error(f"Invalid wallpaper content type: {type(content)}, expected bytes")
|
|
# Create an empty file to prevent downstream errors
|
|
with open(_path, "wb") as f:
|
|
f.write(b"")
|
|
return _path
|
|
|
|
if len(content) == 0:
|
|
logger.warning("VM wallpaper content is empty")
|
|
# Create an empty file to prevent downstream errors
|
|
with open(_path, "wb") as f:
|
|
f.write(b"")
|
|
return _path
|
|
|
|
with open(_path, "wb") as f:
|
|
f.write(content)
|
|
|
|
return _path
|
|
|
|
|
|
def get_list_directory(env, config: dict) -> dict:
|
|
return env.controller.get_vm_directory_tree(config["path"])
|