From dee72c349242b98b7111c99284890ce7e5aac877 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Mon, 10 May 2021 19:47:14 +0000 Subject: [PATCH] steps: Move TUI into Step class Signed-off-by: Michael Tremer --- src/python/__init__.py | 4 ++-- src/python/bootloaders.py | 6 +++--- src/python/disk.py | 26 +++++++++++++------------- src/python/packages.py | 4 ++-- src/python/step.py | 31 ++++++++++++++++--------------- src/python/timezones.py | 4 ++-- 6 files changed, 38 insertions(+), 37 deletions(-) diff --git a/src/python/__init__.py b/src/python/__init__.py index d6c1846..e1b1c48 100644 --- a/src/python/__init__.py +++ b/src/python/__init__.py @@ -180,14 +180,14 @@ class Bricklayer(object): Runs a single step """ # Initialize the step - step = stepcls(self) + step = stepcls(self, tui=self.tui) # Skip this step if it isn't enabled if not step.enabled: return # Run it - return step.run(self.tui) + return step.run() def _read_os_release(self): """ diff --git a/src/python/bootloaders.py b/src/python/bootloaders.py index d8bbbfe..e16a684 100644 --- a/src/python/bootloaders.py +++ b/src/python/bootloaders.py @@ -130,18 +130,18 @@ class InstallBootloader(step.Step): """ Installs the bootloader """ - def run(self, tui): + def run(self): # Find all packages that need to be installed packages = [] for bootloader in self.bricklayer.bootloaders: packages += bootloader.packages # Install them - self.install_packages(tui, packages) + self.install_packages(packages) # Install all bootloaders for bootloader in self.bricklayer.bootloaders: - with tui.progress( + with self.tui.progress( _("Installing Bootloader"), _("Installing bootloader \"%s\"...") % _(bootloader.name), ): diff --git a/src/python/disk.py b/src/python/disk.py index c4196f3..5827c0f 100644 --- a/src/python/disk.py +++ b/src/python/disk.py @@ -416,13 +416,13 @@ class SelectDisk(step.InteractiveStep): # Scan for disks self.disks.scan() - def run(self, tui): + def run(self): # Create a dictionary with all disks disks = { disk : "%s" % disk for disk in self.disks.supported } # Show an error if no suitable disks were found if not disks: - tui.error( + self.tui.error( _("No Disks Found"), _("No supported disks were found") ) @@ -434,7 +434,7 @@ class SelectDisk(step.InteractiveStep): while True: # Select disks - selection = tui.select( + selection = self.tui.select( _("Disk Selection"), _("Please select all disks for installation"), disks, default=selection, multi=True, width=60, @@ -442,7 +442,7 @@ class SelectDisk(step.InteractiveStep): # Is at least one disk selected? if not selection: - tui.error( + self.tui.error( _("No Disk Selected"), _("Please select a disk to continue the installation"), buttons=[_("Back")], @@ -460,7 +460,7 @@ class CalculatePartitionLayout(step.Step): """ Calculates the partition layout """ - def run(self, tui): + def run(self): # This probably will be fast enough that we do not need to show anything # Perform the job @@ -471,10 +471,10 @@ class CreatePartitionLayout(step.Step): """ Creates the desired partition layout on disk """ - def run(self, tui): + def run(self): log.debug("Creating partitions") - with tui.progress( + with self.tui.progress( _("Creating Partition Layout"), _("Creating partition layout..."), ): @@ -486,10 +486,10 @@ class CreateFilesystems(step.Step): """ Formats all newly created partitions """ - def run(self, tui): + def run(self): for disk in self.bricklayer.disks.selected: for partition in disk.partitions: - with tui.progress( + with self.tui.progress( _("Creating Filesystems"), _("Formatting partition \"%s\"...") % (partition.name or partition.path) ): @@ -500,8 +500,8 @@ class MountFilesystems(step.Step): """ Mount all filesystems """ - def run(self, tui): - with tui.progress( + def run(self): + with self.tui.progress( _("Mounting Filesystems"), _("Mounting filesystems..."), ): @@ -512,8 +512,8 @@ class UmountFilesystems(step.Step): """ Umount all filesystems """ - def run(self, tui): - with tui.progress( + def run(self): + with self.tui.progress( _("Umounting Filesystems"), _("Umounting filesystems..."), ): diff --git a/src/python/packages.py b/src/python/packages.py index b0f6beb..46a4331 100644 --- a/src/python/packages.py +++ b/src/python/packages.py @@ -21,8 +21,8 @@ from . import step class InstallPackages(step.Step): - def run(self, tui): + def run(self): # Get list of all packages to be installed packages = self.bricklayer.settings.get("packages", []) - self.install_packages(tui, packages) + self.install_packages(packages) diff --git a/src/python/step.py b/src/python/step.py index 91d0a43..c00c94a 100644 --- a/src/python/step.py +++ b/src/python/step.py @@ -39,8 +39,9 @@ class Step(object): # This enables or disables this step enabled = True - def __init__(self, bricklayer): + def __init__(self, bricklayer, tui): self.bricklayer = bricklayer + self.tui = tui log.debug("Initializing step %s" % self.__class__.__name__) @@ -53,19 +54,19 @@ class Step(object): """ pass - def run(self, tui): + def run(self): """ Run this step - to be overlayed """ pass - def install_packages(self, tui, packages): + def install_packages(self, packages): # Nothing to do if there are no packages if not packages: return # Set up Pakfire - with tui.progress( + with self.tui.progress( _("Setting Up Pakfire"), _("Pakfire is being set up..."), ): @@ -73,7 +74,7 @@ class Step(object): with p as p: # Resolve package dependencies - with tui.progress( + with self.tui.progress( _("Resolving Dependencies"), _("Resolving package dependencies..."), ): @@ -95,7 +96,7 @@ class Step(object): text.append("\n".join(lines)) - tui.error( + self.tui.error( _("Dependency Problem"), _( "A problem has occured during resolving package dependencies:\n\n%s", @@ -109,7 +110,7 @@ class Step(object): log.info("%s" % transaction.dump()) # Run the transaction - with tui.progress( + with self.tui.progress( _("Installing Packages"), _("Installing packages..."), ): @@ -130,12 +131,12 @@ class Welcome(InteractiveStep): """ Shows a very warm welcome message to the user """ - def run(self, tui): + def run(self): name = self.bricklayer.os.get("NAME") current_language = self.bricklayer.settings.get("language") # Let the user select - lang = tui.select( + lang = self.tui.select( _("Willkommen, Bienvenue, Welcome!"), _("Select the language you wish to use for the installation"), i18n.supported_languages, default=current_language, @@ -155,8 +156,8 @@ class Congratulations(InteractiveStep): """ Shows a message that the installation is complete """ - def run(self, tui): - tui.message( + def run(self): + self.tui.message( _("Congratulations"), _( "The installation has been completed successfully." @@ -175,10 +176,10 @@ class UnattendedWarning(Step): # Only enabled in unattended mode return self.bricklayer.unattended - def run(self, tui): + def run(self): seconds = 10 - p = tui.progress( + p = self.tui.progress( _("Unattended Installation"), _("Unattended installation is starting in %s seconds") % seconds, max_value=seconds * 10, @@ -192,8 +193,8 @@ class UnattendedWarning(Step): class RootPassword(InteractiveStep): - def run(self, tui): - password = tui.passwd( + def run(self): + password = self.tui.passwd( _("Root Password"), _("Please enter the password for the 'root' user"), ) diff --git a/src/python/timezones.py b/src/python/timezones.py index 661440d..adb15bf 100644 --- a/src/python/timezones.py +++ b/src/python/timezones.py @@ -28,7 +28,7 @@ from .i18n import _ log = logging.getLogger("bricklayer.timezones") class SelectTimezone(step.InteractiveStep): - def run(self, tui): + def run(self): # Get a list of all available timezones timezones = { tz : tz for tz in sorted(pytz.all_timezones) @@ -37,7 +37,7 @@ class SelectTimezone(step.InteractiveStep): # Which timezone is currently selected? timezone = self.bricklayer.settings.get("timezone", "UTC") - timezone = tui.select( + timezone = self.tui.select( _("Timezone"), _("Please select the timezone:"), timezones, default=timezone, -- 2.47.2