From: Michael Tremer Date: Mon, 9 May 2022 17:39:55 +0000 (+0000) Subject: unattended: Move warning message later to show more information X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e4ec21c54f39ecb5056bf4a4dbfff2726716b076;p=people%2Fms%2Fbricklayer.git unattended: Move warning message later to show more information 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 --- diff --git a/src/python/__init__.py b/src/python/__init__.py index ac6cf9d..5dc1109 100644 --- a/src/python/__init__.py +++ b/src/python/__init__.py @@ -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, diff --git a/src/python/i18n.py b/src/python/i18n.py index 8594a49..0e36e36 100644 --- a/src/python/i18n.py +++ b/src/python/i18n.py @@ -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], + } diff --git a/src/python/step.py b/src/python/step.py index 53b8f9f..7554d61 100644 --- a/src/python/step.py +++ b/src/python/step.py @@ -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): diff --git a/src/python/tui.py b/src/python/tui.py index 82e2d50..8fd57df 100644 --- a/src/python/tui.py +++ b/src/python/tui.py @@ -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):