From 25d2fbce9f1dceda4205923d222822be4f4b2b67 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sat, 15 Mar 2025 12:16:07 +0000 Subject: [PATCH] bricklayer: Allow to customize the unattended timeout on CLI This is probably only useful when testing because I don't want to wait so long until the process starts... Signed-off-by: Michael Tremer --- src/bricklayer | 16 ++++++++++++++++ src/python/__init__.py | 4 +++- src/python/step.py | 5 ++--- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/bricklayer b/src/bricklayer index 8b75a9a..51c68e9 100644 --- a/src/bricklayer +++ b/src/bricklayer @@ -31,6 +31,20 @@ from bricklayer.i18n import _ # Setup logging log = logging.getLogger("bricklayer") +def positive_int(value): + """ + A helper function to accept only positive integers on the command line + """ + # Convert to integer + value = int(value) + + # Raise an error if the value is negative + if value < 0: + raise argparse.ArgumentTypeError(_("Must be a positive integer or zero")) + + # Return the value + return value + class Cli(object): """ This class is called from the command line interface and parses any @@ -50,6 +64,8 @@ class Cli(object): help=_("Enable debugging mode")) parser.add_argument("--unattended", action="store_true", help=_("Enable unattended mode")) + parser.add_argument("--unattended-timeout", nargs="?", type=positive_int, + help=_("Seconds to wait before launching the unattended installation")) parser.add_argument("--disk", nargs="*", dest="disks", default=[], help=_("A disk image file or device which will be used")) parser.add_argument("--serial", action="store_true", diff --git a/src/python/__init__.py b/src/python/__init__.py index 98b8d2a..c536da8 100644 --- a/src/python/__init__.py +++ b/src/python/__init__.py @@ -48,11 +48,13 @@ class Bricklayer(object): Bricklayer's base class """ def __init__(self, arch, pakfire_config=None, first_install=False, debug=False, - unattended=False, disks=[], serial=False, ignore_kernel_cmdline=False): + unattended=False, unattended_timeout=10, disks=[], serial=False, + ignore_kernel_cmdline=False): self.arch = arch self.first_install = first_install self.debug = debug self.unattended = unattended + self.unattended_timeout = unattended_timeout # Enable debug logging if debug: diff --git a/src/python/step.py b/src/python/step.py index bfc2aab..d3403c9 100644 --- a/src/python/step.py +++ b/src/python/step.py @@ -184,19 +184,18 @@ class Congratulations(Step): class UnattendedWarning(UnattendedStep): def run(self): - timeout = 10 disks = self.bricklayer.disks.selected message = _( "The unattended installation will start in %(timeout)s seconds using %(disks)s", ) % { - "timeout" : timeout, + "timeout" : self.bricklayer.unattended_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): + buttons=[_("Cancel Unattended Installation")], timeout=self.bricklayer.unattended_timeout): raise InstallAbortedError -- 2.47.3