]> git.ipfire.org Git - people/ms/bricklayer.git/commitdiff
bricklayer: Allow to customize the unattended timeout on CLI
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 15 Mar 2025 12:16:07 +0000 (12:16 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 15 Mar 2025 12:16:07 +0000 (12:16 +0000)
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 <michael.tremer@ipfire.org>
src/bricklayer
src/python/__init__.py
src/python/step.py

index 8b75a9a2a8aabf1cface5b4e8bf4c4429dc47fe7..51c68e9317da6b9880743cc76923994c907020e7 100644 (file)
@@ -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",
index 98b8d2a7644629347d676aefd2a9353117612193..c536da8825f173401e2106ae138f62b7f8a2c62b 100644 (file)
@@ -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:
index bfc2aab102d8ca4f9de2ec683d8cb0a89cb194da..d3403c90afdfae0148c55b51368f1f1cfa31d78b 100644 (file)
@@ -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