]> git.ipfire.org Git - people/ms/bricklayer.git/commitdiff
unattended: Move warning message later to show more information
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 9 May 2022 17:39:55 +0000 (17:39 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 9 May 2022 17:42:19 +0000 (17:42 +0000)
It does not make too much sense to start the unattended installation
with a countdown that cannot be stopped.

Instead, we collect some information now and will then show a dialogue
that shows the disks and has a cancellation button.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/python/__init__.py
src/python/i18n.py
src/python/step.py
src/python/tui.py

index ac6cf9deffce42b55b48aa846d2418b440edc1eb..5dc1109e40f46299ecab019ed74057ac7d812184 100644 (file)
@@ -95,7 +95,6 @@ class Bricklayer(object):
 
        # An ordered list of all available steps
        steps = (
-               step.UnattendedWarning,
                step.Welcome,
                timezones.SelectTimezone,
                disk.Scan,
@@ -105,6 +104,7 @@ class Bricklayer(object):
                step.RootPassword,
 
                # Go!
+               step.UnattendedWarning,
                disk.CreatePartitionLayout,
                disk.CreateFilesystems,
                disk.MountFilesystems,
index 8594a4916504414a4a7a16fcec96a624ee730bc8..0e36e367c190ac0cadd8aac832581a7bd92a79f1 100644 (file)
@@ -36,3 +36,16 @@ def _(singular, plural=None, n=None):
                return gettext.dngettext("bricklayer", singular, plural, n)
 
        return gettext.dgettext("bricklayer", singular)
+
+def list(objects):
+       length = len(objects)
+
+       if length == 0:
+               return ""
+       elif length == 1:
+               return objects[0]
+       else:
+               return _("%(commas)s, and %(last)s") % {
+                       "commas" : ",".join(objects[:-1]),
+                       "last"   : objects[-1],
+               }
index 53b8f9f4f59e6ee6b8e77af7106fbe488d2cd280..7554d61fae28bd350efb0a9307574ad443369a9a 100644 (file)
@@ -26,6 +26,7 @@ import pakfire.errors
 import snack
 
 from . import i18n
+from .errors import *
 from .i18n import _
 
 # Setup logging
@@ -175,26 +176,24 @@ class Congratulations(InteractiveStep):
                )
 
 
-class UnattendedWarning(Step):
-       @property
-       def enabled(self):
-               # Only enabled in unattended mode
-               return self.bricklayer.unattended
-
+class UnattendedWarning(UnattendedStep):
        def run(self):
-               seconds = 10
-
-               p = self.tui.progress(
-                       _("Unattended Installation"),
-                       _("Unattended installation is starting in %s seconds") % seconds,
-                       max_value=seconds * 10,
-               )
-
-               with p as w:
-                       for i in range(seconds * 10):
-                               time.sleep(0.1)
-
-                               w.progress(i + 1)
+               timeout = 10
+               disks = self.bricklayer.disks.selected
+
+               message = _(
+                       "The unattended installation will start in %(timeout)s seconds using %(disks)s",
+                       "The unattended installation will start in %(timeout)s seconds using %(disks)s",
+                       len(disks),
+               ) % {
+                       "timeout" : timeout,
+                       "disks"   : i18n.list(disks),
+               }
+
+               # Show message to the user and allow them to cancel
+               if self.tui.message(_("Unattended Installation"), message,
+                       buttons=[_("Cancel Unattended Installation")], timeout=timeout):
+                               raise InstallAbortedError
 
 
 class RootPassword(InteractiveStep):
index 82e2d50505410c5c1e3df2b8da41e8c5d6e22dfd..8fd57df42b80ab282e57eaf043a6d061d27a663c 100644 (file)
@@ -146,7 +146,8 @@ class Tui(object):
 
                self.screen.pushHelpLine(helpline)
 
-       def message(self, title, text, buttons=None, height=None, width=40, help=None):
+       def message(self, title, text, buttons=None, height=None, width=40,
+                       help=None, timeout=None):
                """
                        Shows a message to the user
                """
@@ -157,7 +158,7 @@ class Tui(object):
                        buttons = (_("OK"), _("Cancel"))
 
                window = ButtonsWindow(self, title=title, text=text,
-                       buttons=buttons, height=height, width=width, help=help)
+                       buttons=buttons, height=height, width=width, help=help, timeout=timeout)
 
                return window.run()
 
@@ -228,8 +229,10 @@ class Window(object):
 
 
 class ButtonsWindow(Window):
-       def __init__(self, tui, title, text, buttons=None, height=None, width=None, help=None):
+       def __init__(self, tui, title, text, buttons=None, height=None, width=None,
+                       help=None, timeout=None):
                Window.__init__(self, tui, title, text, height=height, width=width, help=help)
+               self.timeout = timeout
 
                # Configure some default buttons
                if buttons is None:
@@ -255,6 +258,10 @@ class ButtonsWindow(Window):
                # Create the button bar
                grid.add(self.buttons, 0, 1, growx=True)
 
+               # Set timeout
+               if self.timeout:
+                       grid.setTimer(self.timeout * 1000)
+
                return grid
 
        def run(self):