From: Michael Tremer Date: Mon, 9 May 2022 16:48:50 +0000 (+0000) Subject: disks: Fix automatic disk selection in unattended mode X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=016d1cdfe0a4fb9a99c3fc6f5ca8d64fe0f2f3f2;p=people%2Fms%2Fbricklayer.git disks: Fix automatic disk selection in unattended mode Signed-off-by: Michael Tremer --- diff --git a/src/python/__init__.py b/src/python/__init__.py index 2dcceb2..8966df1 100644 --- a/src/python/__init__.py +++ b/src/python/__init__.py @@ -82,7 +82,7 @@ class Bricklayer(object): # Hardware self.disks = disk.Disks(self) for path in disks: - self.disks.add_disk(path) + self.disks.add_disk(path, selected=True) # Initialise the text user interface self.tui = tui.Tui(self) @@ -98,6 +98,7 @@ class Bricklayer(object): step.UnattendedWarning, step.Welcome, timezones.SelectTimezone, + disk.UnattendedSelectDisk, disk.SelectDisk, disk.CalculatePartitionLayout, step.RootPassword, diff --git a/src/python/disk.py b/src/python/disk.py index f56fe40..935a856 100644 --- a/src/python/disk.py +++ b/src/python/disk.py @@ -53,7 +53,9 @@ class Disks(object): """ Scans for all disks """ - self.disks.clear() + # Don't scan for disks if already done + if self.disks: + return log.debug("Scanning for disks...") @@ -69,7 +71,7 @@ class Disks(object): # Sort them alphabetically self.disks.sort() - def add_disk(self, path): + def add_disk(self, path, selected=False): """ Adds the disk at path """ @@ -88,6 +90,10 @@ class Disks(object): disk = Disk(self.bricklayer, path) self.disks.append(disk) + # Select this disk + if selected: + disk.selected = True + return disk def _losetup(self, path): @@ -410,6 +416,33 @@ class Partition(object): self.bricklayer.command(command) +class UnattendedSelectDisk(step.UnattendedStep): + """ + Scans for any disks + """ + def run(self): + # Nothing to do if disks have already been selected on the CLI + if self.bricklayer.disks.selected: + return + + # Scan for disks + self.bricklayer.disks.scan() + + # End here if we could not find any disks + if not self.bricklayer.disks.supported: + self.tui.error( + _("No Disks Found"), + _("No supported disks were found") + ) + + raise InstallAbortedError("No disks found") + + # Automatically select the first disk + for disk in self.bricklayer.disks.supported: + disk.selected = True + break + + class SelectDisk(step.InteractiveStep): """ Ask the user which disk(s) to use for the installation process diff --git a/src/python/step.py b/src/python/step.py index 3d2417b..53b8f9f 100644 --- a/src/python/step.py +++ b/src/python/step.py @@ -117,6 +117,16 @@ class InteractiveStep(Step): return not self.bricklayer.unattended +class UnattendedStep(Step): + """ + A convenience handler that only runs this step in unattended mode + """ + @property + def enabled(self): + # Enable only in unattended mode + return self.bricklayer.unattended + + class Welcome(InteractiveStep): """ Shows a very warm welcome message to the user