new commit

This commit is contained in:
Manuel 2025-04-28 01:46:35 +00:00
parent 5fba595c02
commit 520a213aeb

View File

@ -78,11 +78,8 @@ def install_desktop_environment(arch, desktop_environment_name, desktops_config,
ValueError: If configuration data is missing or incorrect. ValueError: If configuration data is missing or incorrect.
KeyError: If required paths are not found. KeyError: If required paths are not found.
""" """
# Remove the logger = logging.getLogger(__name__) line here, use the module-level logger
logger.info(f"=> Starting installation of desktop environment: {desktop_environment_name} in environment: {target_env} ({arch})...") logger.info(f"=> Starting installation of desktop environment: {desktop_environment_name} in environment: {target_env} ({arch})...")
# Ensure paths dict is available
if paths is None or not isinstance(paths, dict): if paths is None or not isinstance(paths, dict):
logger.error("Paths dictionary is missing or incorrect.") logger.error("Paths dictionary is missing or incorrect.")
raise ValueError("Paths dictionary is required.") raise ValueError("Paths dictionary is required.")
@ -90,7 +87,6 @@ def install_desktop_environment(arch, desktop_environment_name, desktops_config,
if target_env == 'rootfs': if target_env == 'rootfs':
target_path = paths.get('ROOTFS') target_path = paths.get('ROOTFS')
else: else:
# Desktop environments are typically only installed in rootfs in this build process
logger.error(f"Invalid target environment for desktop installation: {target_env}. Installation is only supported in ROOTFS.") logger.error(f"Invalid target environment for desktop installation: {target_env}. Installation is only supported in ROOTFS.")
raise ValueError(f"Invalid target environment for desktop installation: {target_env}") raise ValueError(f"Invalid target environment for desktop installation: {target_env}")
@ -101,122 +97,102 @@ def install_desktop_environment(arch, desktop_environment_name, desktops_config,
desktop_yaml_file = None desktop_yaml_file = None
total_desktop_packages_list = [] total_desktop_packages_list = []
services_to_enable_list = [] # Services are still handled separately services_to_enable_list = []
# Get the specific desktop YAML file path from the main desktops_config
if desktops_config and 'desktops' in desktops_config and desktop_environment_name.lower() in desktops_config['desktops']: if desktops_config and 'desktops' in desktops_config and desktop_environment_name.lower() in desktops_config['desktops']:
desktop_info = desktops_config['desktops'][desktop_environment_name.lower()] desktop_info = desktops_config['desktops'][desktop_environment_name.lower()]
# package_group is not used in this YAML-driven approach
# desktop_packages_group = desktop_info.get('package_group') desktop_yaml_file = desktop_info.get('yaml_file')
desktop_yaml_file = desktop_info.get('yaml_file') # This is the path like 'builder/configs/desktops/xfce.yaml'
else: else:
logger.error(f"Configuration for desktop environment '{desktop_environment_name}' not found in desktops_config.yaml.") logger.error(f"Configuration for desktop environment '{desktop_environment_name}' not found in desktops_config.yaml.")
raise ValueError(f"Configuration for desktop environment '{desktop_environment_name}' not found.") raise ValueError(f"Configuration for desktop environment '{desktop_environment_name}' not found.")
if desktop_yaml_file: if desktop_yaml_file:
logger.info(f"=> Loading desktop configuration from YAML file: {desktop_yaml_file}") logger.info(f"=> Loading desktop configuration from YAML file: {desktop_yaml_full_path}")
# Need to construct the full path if desktop_yaml_file is relative desktop_yaml_full_path = os.path.join(BASE_DIR, desktop_yaml_file)
desktop_yaml_full_path = os.path.join(BASE_DIR, desktop_yaml_file) # Assumes BASE_DIR is project root
try: try:
# Use load_yaml_config helper
desktop_packages_config = load_yaml_config(desktop_yaml_full_path, os.path.basename(desktop_yaml_full_path)) desktop_packages_config = load_yaml_config(desktop_yaml_full_path, os.path.basename(desktop_yaml_full_path))
except Exception as e: except Exception as e:
logger.error(f"Error loading desktop packages YAML '{desktop_yaml_full_path}': {e}") logger.error(f"Error loading desktop packages YAML '{desktop_yaml_full_path}': {e}")
raise # Re-raise the exception raise
if desktop_packages_config: if desktop_packages_config:
logger.debug(f"=> Desktop YAML file loaded successfully from: {desktop_yaml_full_path}") logger.debug(f"=> Desktop YAML file loaded successfully from: {desktop_yaml_full_path}")
# Expected structure: {<architecture>: {desktop_packages: [...], login_manager_packages: [...], ...}}
# Get the configuration specifically for the target architecture desktop_env_details = desktop_packages_config.get('desktop_environment', {})
desktop_config_for_arch = desktop_packages_config.get(arch, {}) # Use 'arch' parameter
if desktop_env_details:
logger.debug(f"=> Found 'desktop_environment' section in YAML.")
desktop_config_for_arch = desktop_env_details.get(arch, {})
if desktop_config_for_arch: if desktop_config_for_arch:
logger.debug(f"=> Configuration found for architecture: {arch}") logger.debug(f"=> Configuration found for architecture: {arch} within 'desktop_environment' section.")
# Get package lists for this architecture
desktop_packages = desktop_config_for_arch.get('desktop_packages', []) desktop_packages = desktop_config_for_arch.get('desktop_packages', [])
login_manager_packages = desktop_config_for_arch.get('login_manager_packages', []) login_manager_packages = desktop_config_for_arch.get('login_manager_packages', [])
default_packages = desktop_config_for_arch.get('default_packages', []) # Assuming this key exists default_packages = desktop_config_for_arch.get('default_packages', [])
# Combine all package lists
if isinstance(desktop_packages, list): if isinstance(desktop_packages, list):
total_desktop_packages_list.extend(desktop_packages) total_desktop_packages_list.extend(desktop_packages)
else: else:
logger.warning(f"'desktop_packages' for {arch} in {desktop_yaml_full_path} is not a list. Ignoring.") logger.warning(f"'desktop_packages' for {arch} in {desktop_yaml_full_path} is not a list (under desktop_environment:{arch}). Ignoring.")
if isinstance(login_manager_packages, list): if isinstance(login_manager_packages, list):
total_desktop_packages_list.extend(login_manager_packages) total_desktop_packages_list.extend(login_manager_packages)
else: else:
logger.warning(f"'login_manager_packages' for {arch} in {desktop_yaml_full_path} is not a list. Ignoring.") logger.warning(f"'login_manager_packages' for {arch} in {desktop_yaml_full_path} is not a list (under desktop_environment:{arch}). Ignoring.")
if isinstance(default_packages, list): if isinstance(default_packages, list):
total_desktop_packages_list.extend(default_packages) total_desktop_packages_list.extend(default_packages)
else: else:
logger.warning(f"'default_packages' for {arch} in {desktop_yaml_full_path} is not a list. Ignoring.") logger.warning(f"'default_packages' for {arch} in {desktop_yaml_full_path} is not a list (under desktop_environment:{arch}). Ignoring.")
# Get the services list for this architecture
services_to_enable_list = desktop_config_for_arch.get('services_enable', []) services_to_enable_list = desktop_config_for_arch.get('services_enable', [])
if not isinstance(services_to_enable_list, list): if not isinstance(services_to_enable_list, list):
logger.warning(f"'services_enable' for {arch} in {desktop_yaml_full_path} is not a list. Ignoring.") logger.warning(f"'services_enable' for {arch} in {desktop_yaml_full_path} is not a list (under desktop_environment:{arch}). Ignoring.")
services_to_enable_list = [] services_to_enable_list = []
else:
logger.warning(f"No configuration found for architecture {arch} within 'desktop_environment' section in {desktop_yaml_full_path}. No desktop packages or services loaded.")
else: else:
logger.warning(f"No configuration found for architecture {arch} in {desktop_yaml_full_path}. No desktop packages or services loaded.") logger.error(f"Could not find 'desktop_environment' section in {desktop_yaml_full_path}.")
else: else:
logger.error(f"=> Failed to load desktop YAML configuration from: {desktop_yaml_full_path}") logger.error(f"=> Failed to load desktop YAML configuration from: {desktop_yaml_full_path}")
# Decide if this should be a fatal error or if a package group fallback is possible
# Currently, if YAML fails or has no arch config, total_desktop_packages_list will be empty
# --- Install Desktop Packages ---
if total_desktop_packages_list: if total_desktop_packages_list:
logger.info(f"=> Desktop package list for {arch} extracted successfully. Building XBPS_INSTALL_CMD command...") logger.info(f"=> Desktop package list for {arch} extracted successfully. Building XBPS_INSTALL_CMD command...")
# Construct the xbps-install command arguments using the helper from bootstrap module
# construct_xbps_install_args expects the package list in the structure {'env_name': {'arch': [package_list]}}
# We are installing into the "rootfs" environment here.
adapted_package_structure = {"rootfs": {arch: total_desktop_packages_list}} adapted_package_structure = {"rootfs": {arch: total_desktop_packages_list}}
# construct_xbps_install_args handles repository filtering, -r, -c args internally
# It needs paths, target_architecture, repositories_data, and the adapted package structure
desktop_packages_args = bootstrap.construct_xbps_install_args( desktop_packages_args = bootstrap.construct_xbps_install_args(
"rootfs", # Environment name (determines target path like paths['ROOTFS']) "rootfs",
paths, # Paths dictionary (needed by construct_xbps_install_args for rootfs path and cache dir) paths,
arch, # Target architecture (use the 'arch' parameter passed to this function) arch,
repositories_data, # All repository data (passed to this function) repositories_data,
adapted_package_structure # Pass desktop packages in the structure expected by construct_xbps_install_args adapted_package_structure
) )
if not desktop_packages_args: if not desktop_packages_args:
logger.warning("Skipping desktop packages installation due to failure in constructing xbps-install arguments.") logger.warning("Skipping desktop packages installation due to failure in constructing xbps-install arguments.")
# The error was likely logged within construct_xbps_install_args
else: else:
# Execute the xbps-install command directly on the host, targeting the rootfs
# Prepend the xbps-install binary path on the host
desktop_install_command = ["/usr/bin/xbps-install"] + desktop_packages_args desktop_install_command = ["/usr/bin/xbps-install"] + desktop_packages_args
logger.info(f"Executing desktop packages installation command (host): {' '.join(desktop_install_command)}") logger.info(f"Executing desktop packages installation command (host): {' '.join(desktop_install_command)}")
try: try:
run_command(desktop_install_command) # Use the existing run_command helper run_command(desktop_install_command)
logger.info(f"=> Installation of desktop packages completed successfully in environment: {target_env}.") logger.info(f"=> Installation of desktop packages completed successfully in environment: {target_env}.")
except Exception as e: # Catching general Exception, consider more specific CalledProcessError except Exception as e:
logger.error(f"Error executing XBPS_INSTALL_CMD for desktop packages in environment: {target_env}: {e}") logger.error(f"Error executing XBPS_INSTALL_CMD for desktop packages in environment: {target_env}: {e}")
raise # Re-raise the exception to stop the build raise
# --- Enable Services ---
# The enable_services_in_chroot function might need to be adapted if it uses chroot execution internally.
# For the host-execution strategy, it should either manipulate files directly or use a helper
# that runs commands in the target context without a full chroot wrapper if possible,
# or use the run_command_in_chroot if that's still deemed necessary for this specific step.
# Assuming enable_services_in_chroot receives the target path and service list and handles execution internally.
if services_to_enable_list: if services_to_enable_list:
logger.info("=> Services to enable found in the desktop YAML configuration.") logger.info("=> Services to enable found in the desktop YAML configuration.")
try: try:
# enable_services_in_chroot needs the target_path (rootfs_path) enable_services_in_chroot(target_path, services_to_enable_list)
enable_services_in_chroot(target_path, services_to_enable_list) # target_path is derived from paths
logger.info(f"=> Services specified in the desktop YAML enabled successfully in environment: {target_env}.") logger.info(f"=> Services specified in the desktop YAML enabled successfully in environment: {target_env}.")
except Exception as e: except Exception as e:
logger.error(f"Error enabling services specified in the desktop YAML in environment: {target_env}: {e}") logger.error(f"Error enabling services specified in the desktop YAML in environment: {target_env}: {e}")