]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Clean up load_config() a little
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Sun, 10 Dec 2023 12:06:28 +0000 (13:06 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Sun, 10 Dec 2023 12:06:28 +0000 (13:06 +0100)
mkosi/config.py

index dbdd068808bd815ac45757d6354e47be3654b35a..cbac37842bca5327192f105c9b0f0c6746670573 100644 (file)
@@ -2693,7 +2693,7 @@ def parse_config(argv: Sequence[str] = ()) -> tuple[MkosiArgs, tuple[MkosiConfig
     if not images:
         die("No images defined in mkosi.images/")
 
-    images = [load_config(ns) for ns in images]
+    images = [load_config(args, ns) for ns in images]
     images = resolve_deps(images, include)
 
     return args, tuple(images)
@@ -2817,6 +2817,9 @@ def load_environment(args: argparse.Namespace) -> dict[str, str]:
 
 
 def load_args(args: argparse.Namespace) -> MkosiArgs:
+    if args.cmdline and not args.verb.supports_cmdline():
+        die(f"Arguments after verb are not supported for {args.verb}.")
+
     if args.debug:
         ARG_DEBUG.set(args.debug)
     if args.debug_shell:
@@ -2825,57 +2828,54 @@ def load_args(args: argparse.Namespace) -> MkosiArgs:
     return MkosiArgs.from_namespace(args)
 
 
-def load_config(args: argparse.Namespace) -> MkosiConfig:
-    if args.cmdline and not args.verb.supports_cmdline():
-        die(f"Arguments after verb are not supported for {args.verb}.")
-
-    if args.build_dir:
-        args.build_dir = args.build_dir / f"{args.distribution}~{args.release}~{args.architecture}"
+def load_config(args: MkosiArgs, config: argparse.Namespace) -> MkosiConfig:
+    if config.build_dir:
+        config.build_dir = config.build_dir / f"{config.distribution}~{config.release}~{config.architecture}"
 
-    if args.sign:
-        args.checksum = True
+    if config.sign:
+        config.checksum = True
 
-    if args.output is None:
-        args.output = args.image_id or args.image or "image"
+    if config.output is None:
+        config.output = config.image_id or config.image or "image"
 
-    args.credentials = load_credentials(args)
-    args.kernel_command_line_extra = load_kernel_command_line_extra(args)
-    args.environment = load_environment(args)
+    config.credentials = load_credentials(config)
+    config.kernel_command_line_extra = load_kernel_command_line_extra(config)
+    config.environment = load_environment(config)
 
-    if args.secure_boot and args.verb != Verb.genkey:
-        if args.secure_boot_key is None and args.secure_boot_certificate is None:
+    if config.secure_boot and args.verb != Verb.genkey:
+        if config.secure_boot_key is None and config.secure_boot_certificate is None:
             die("UEFI SecureBoot enabled, but couldn't find the certificate and private key.",
                 hint="Consider generating them with 'mkosi genkey'.")
-        if args.secure_boot_key is None:
+        if config.secure_boot_key is None:
             die("UEFI SecureBoot enabled, certificate was found, but not the private key.",
                 hint="Consider placing it in mkosi.key")
-        if args.secure_boot_certificate is None:
+        if config.secure_boot_certificate is None:
             die("UEFI SecureBoot enabled, private key was found, but not the certificate.",
                 hint="Consider placing it in mkosi.crt")
 
-    if args.repositories and not (
-        args.distribution.is_dnf_distribution() or
-        args.distribution.is_apt_distribution() or
-        args.distribution == Distribution.arch
+    if config.repositories and not (
+        config.distribution.is_dnf_distribution() or
+        config.distribution.is_apt_distribution() or
+        config.distribution == Distribution.arch
     ):
         die("Sorry, the --repositories option is only supported on pacman, dnf and apt based distributions")
 
-    if args.overlay and not args.base_trees:
+    if config.overlay and not config.base_trees:
         die("--overlay can only be used with --base-tree")
 
-    if args.incremental and not args.cache_dir:
+    if config.incremental and not config.cache_dir:
         die("A cache directory must be configured in order to use --incremental")
 
     # For unprivileged builds we need the userxattr OverlayFS mount option, which is only available
     # in Linux v5.11 and later.
     if (
-        (args.build_scripts or args.base_trees) and
+        (config.build_scripts or config.base_trees) and
         GenericVersion(platform.release()) < GenericVersion("5.11") and
         os.geteuid() != 0
     ):
         die("This unprivileged build configuration requires at least Linux v5.11")
 
-    return MkosiConfig.from_namespace(args)
+    return MkosiConfig.from_namespace(config)
 
 
 def yes_no(b: bool) -> str: