Skip to content

Commit

Permalink
Add TUI for installing non-standard kernels
Browse files Browse the repository at this point in the history
Add a new screen to Software selection spoke that appears after addon
selection.
This screen allows for selecting non-standard kernels.

Resolves: rhbz#2164819
  • Loading branch information
OndrejZobal authored and rvykydal committed Jan 22, 2024
1 parent 714cc3d commit 3bae673
Showing 1 changed file with 97 additions and 4 deletions.
101 changes: 97 additions & 4 deletions pyanaconda/ui/tui/spokes/software_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@
is_software_selection_complete, SoftwareSelectionCache, get_group_data, get_environment_data
from pyanaconda.ui.tui.spokes import NormalTUISpoke
from pyanaconda.core.threads import thread_manager
from pyanaconda.ui.lib.software import FEATURE_64K, KernelFeatures, \
get_kernel_from_properties, get_available_kernel_features, get_kernel_titles_and_descriptions
from pyanaconda.core.i18n import N_, _
from pyanaconda.core.constants import THREAD_PAYLOAD, THREAD_CHECK_SOFTWARE, \
THREAD_SOFTWARE_WATCHER, PAYLOAD_TYPE_DNF
from pyanaconda.core.configuration.anaconda import conf

from simpleline.render.containers import ListColumnContainer
from simpleline.render.prompt import Prompt
Expand Down Expand Up @@ -69,6 +72,8 @@ def __init__(self, data, storage, payload):

# Get the packages configuration.
self._selection_cache = SoftwareSelectionCache(self.payload.proxy)
self._kernel_selection = None
self._available_kernels = None

# Are we taking values (package list) from a kickstart file?
self._kickstarted = flags.automatedInstall and self.payload.proxy.PackagesKickstarted
Expand All @@ -92,6 +97,9 @@ def _initialize(self):
"""Initialize the spoke in a separate thread."""
thread_manager.wait(THREAD_PAYLOAD)

self._available_kernels = get_available_kernel_features(self.payload.proxy)
self._kernel_selection = dict.fromkeys(self._available_kernels, False)

# Initialize and check the software selection.
self._initialize_selection()

Expand Down Expand Up @@ -252,7 +260,8 @@ def input(self, args, key):
self.data,
self.storage,
self.payload,
self._selection_cache
self._selection_cache,
self._kernel_selection
)
ScreenHandler.push_screen_modal(spoke)
self.apply()
Expand All @@ -269,6 +278,19 @@ def apply(self):
selection = self._selection_cache.get_selection_data()
log.debug("Setting new software selection: %s", selection)

# Processing chosen kernel
if conf.ui.show_kernel_options:
self._available_kernels = get_available_kernel_features(self.payload.proxy)
feature_64k = self._available_kernels[FEATURE_64K] and \
self._kernel_selection[FEATURE_64K]
features = KernelFeatures(feature_64k)
kernel = get_kernel_from_properties(features)
if kernel:
log.debug("Selected kernel package: %s", kernel)
selection.packages.append(kernel)
selection.excluded_packages.append("kernel")

log.debug("Setting new software selection: %s", self._selection)
self.payload.set_packages_selection(selection)

def execute(self):
Expand Down Expand Up @@ -297,11 +319,12 @@ class AdditionalSoftwareSpoke(NormalTUISpoke):
"""The spoke for choosing the additional software."""
category = SoftwareCategory

def __init__(self, data, storage, payload, selection_cache):
def __init__(self, data, storage, payload, selection_cache, kernel_selection):
super().__init__(data, storage, payload)
self.title = N_("Software selection")
self._container = None
self._selection_cache = selection_cache
self._kernel_selection = kernel_selection

def refresh(self, args=None):
"""Refresh the screen."""
Expand Down Expand Up @@ -342,11 +365,81 @@ def _select_group(self, group):
else:
self._selection_cache.deselect_group(group)

def _show_kernel_features_screen(self, kernels):
"""Returns True if at least one non-standard kernel is available.
"""
if not conf.ui.show_kernel_options:
return False
for val in kernels.values():
if val:
return True
return False

def input(self, args, key):
if self._container.process_user_input(key):
return InputState.PROCESSED_AND_REDRAW
else:
return super().input(args, key)
if key.lower() == Prompt.CONTINUE:
available_kernels = get_available_kernel_features(self.payload.proxy)
if self._show_kernel_features_screen(available_kernels):
spoke = KernelSelectionSpoke(self.data, self.storage, self.payload,
self._selection_cache, self._kernel_selection,
available_kernels)
ScreenHandler.push_screen_modal(spoke)
self.execute()
self.close()
return InputState.PROCESSED

return super().input(args, key)

def apply(self):
pass


class KernelSelectionSpoke(NormalTUISpoke):
"""A subspoke for selecting kernel features.
"""
def __init__(self, data, storage, payload, selection_cache,
_kernel_selection, available_kernels):
super().__init__(data, storage, payload)
self.title = N_("Kernel Options")
self._container = None
self._selection_cache = selection_cache
self._kernel_selection = _kernel_selection
self._available_kernels = available_kernels

def refresh(self, args=None):
NormalTUISpoke.refresh(self)

# Retrieving translated UI strings
labels = get_kernel_titles_and_descriptions()

# Updating kernel availability
self._available_kernels = get_available_kernel_features(self.payload.proxy)
self._container = ListColumnContainer(2, columns_width=38, spacing=2)

# Rendering kernel checkboxes
for (name, val) in self._kernel_selection.items():
if not self._available_kernels[name]:
continue
(title, text) = labels[name]
widget = CheckboxWidget(title="%s" % title, text="%s" % text, completed=val)
self._container.add(widget, callback=self._set_kernel_callback, data=name)

self.window.add_with_separator(TextWidget(_("Kernel options")))
self.window.add_with_separator(self._container)

def _set_kernel_callback(self, data):
self._kernel_selection[data] = not self._kernel_selection[data]

def input(self, args, key):
if self._container.process_user_input(key):
return InputState.PROCESSED_AND_REDRAW

if key.lower() == Prompt.CONTINUE:
self.close()
return InputState.PROCESSED

return super().input(args, key)

def apply(self):
pass

0 comments on commit 3bae673

Please sign in to comment.