diff --git a/builder/core/install_desktop.py b/builder/core/install_desktop.py index a96c208a..425f7926 100644 --- a/builder/core/install_desktop.py +++ b/builder/core/install_desktop.py @@ -78,11 +78,8 @@ def install_desktop_environment(arch, desktop_environment_name, desktops_config, ValueError: If configuration data is missing or incorrect. 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})...") - # Ensure paths dict is available if paths is None or not isinstance(paths, dict): logger.error("Paths dictionary is missing or incorrect.") raise ValueError("Paths dictionary is required.") @@ -90,7 +87,6 @@ def install_desktop_environment(arch, desktop_environment_name, desktops_config, if target_env == 'rootfs': target_path = paths.get('ROOTFS') 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.") 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 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']: 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') # This is the path like 'builder/configs/desktops/xfce.yaml' + + desktop_yaml_file = desktop_info.get('yaml_file') else: 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.") if desktop_yaml_file: - logger.info(f"=> Loading desktop configuration from YAML file: {desktop_yaml_file}") - # Need to construct the full path if desktop_yaml_file is relative - desktop_yaml_full_path = os.path.join(BASE_DIR, desktop_yaml_file) # Assumes BASE_DIR is project root + logger.info(f"=> Loading desktop configuration from YAML file: {desktop_yaml_full_path}") + desktop_yaml_full_path = os.path.join(BASE_DIR, desktop_yaml_file) try: - # Use load_yaml_config helper desktop_packages_config = load_yaml_config(desktop_yaml_full_path, os.path.basename(desktop_yaml_full_path)) except Exception as e: logger.error(f"Error loading desktop packages YAML '{desktop_yaml_full_path}': {e}") - raise # Re-raise the exception + raise if desktop_packages_config: logger.debug(f"=> Desktop YAML file loaded successfully from: {desktop_yaml_full_path}") - # Expected structure: {: {desktop_packages: [...], login_manager_packages: [...], ...}} - # Get the configuration specifically for the target architecture - desktop_config_for_arch = desktop_packages_config.get(arch, {}) # Use 'arch' parameter - if desktop_config_for_arch: - logger.debug(f"=> Configuration found for architecture: {arch}") - # Get package lists for this architecture - desktop_packages = desktop_config_for_arch.get('desktop_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 + desktop_env_details = desktop_packages_config.get('desktop_environment', {}) + + 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: + logger.debug(f"=> Configuration found for architecture: {arch} within 'desktop_environment' section.") + desktop_packages = desktop_config_for_arch.get('desktop_packages', []) + login_manager_packages = desktop_config_for_arch.get('login_manager_packages', []) + default_packages = desktop_config_for_arch.get('default_packages', []) + + if isinstance(desktop_packages, list): + total_desktop_packages_list.extend(desktop_packages) + else: + 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): + total_desktop_packages_list.extend(login_manager_packages) + else: + 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): + total_desktop_packages_list.extend(default_packages) + else: + logger.warning(f"'default_packages' for {arch} in {desktop_yaml_full_path} is not a list (under desktop_environment:{arch}). Ignoring.") + + services_to_enable_list = desktop_config_for_arch.get('services_enable', []) + if not isinstance(services_to_enable_list, list): + 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 = [] - # Combine all package lists - if isinstance(desktop_packages, list): - total_desktop_packages_list.extend(desktop_packages) else: - logger.warning(f"'desktop_packages' for {arch} in {desktop_yaml_full_path} is not a list. Ignoring.") - - if isinstance(login_manager_packages, list): - total_desktop_packages_list.extend(login_manager_packages) - else: - logger.warning(f"'login_manager_packages' for {arch} in {desktop_yaml_full_path} is not a list. Ignoring.") - - if isinstance(default_packages, list): - total_desktop_packages_list.extend(default_packages) - else: - logger.warning(f"'default_packages' for {arch} in {desktop_yaml_full_path} is not a list. Ignoring.") - - - # Get the services list for this architecture - services_to_enable_list = desktop_config_for_arch.get('services_enable', []) - 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.") - services_to_enable_list = [] - + 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: - 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: 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: 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}} - # 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( - "rootfs", # Environment name (determines target path like paths['ROOTFS']) - paths, # Paths dictionary (needed by construct_xbps_install_args for rootfs path and cache dir) - arch, # Target architecture (use the 'arch' parameter passed to this function) - repositories_data, # All repository data (passed to this function) - adapted_package_structure # Pass desktop packages in the structure expected by construct_xbps_install_args + "rootfs", + paths, + arch, + repositories_data, + adapted_package_structure ) if not desktop_packages_args: 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: - # 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 logger.info(f"Executing desktop packages installation command (host): {' '.join(desktop_install_command)}") 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}.") - 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}") - 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: logger.info("=> Services to enable found in the desktop YAML configuration.") try: - # enable_services_in_chroot needs the target_path (rootfs_path) - enable_services_in_chroot(target_path, services_to_enable_list) # target_path is derived from paths + enable_services_in_chroot(target_path, services_to_enable_list) logger.info(f"=> Services specified in the desktop YAML enabled successfully in environment: {target_env}.") except Exception as e: logger.error(f"Error enabling services specified in the desktop YAML in environment: {target_env}: {e}")