]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
ukify: Introduce resolve_at_path()
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 7 Oct 2024 09:29:40 +0000 (11:29 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 9 Oct 2024 18:36:55 +0000 (20:36 +0200)
src/ukify/ukify.py

index a94e6eefd6a0e11c65b1b8b522f02f0ee1d3f437..5f1b2c3e8c84fe935765ad8bc69633076d41e477 100755 (executable)
@@ -1801,6 +1801,13 @@ def create_parser() -> argparse.ArgumentParser:
     return p
 
 
+def resolve_at_path(value: Optional[str]) -> str:
+    if value and value.startswith('@'):
+        return Path(value[1:])
+
+    return value
+
+
 def finalize_options(opts: argparse.Namespace) -> None:
     # Figure out which syntax is being used, one of:
     # ukify verb --arg --arg --arg
@@ -1835,17 +1842,17 @@ def finalize_options(opts: argparse.Namespace) -> None:
     if n_phase_path_groups is not None and n_phase_path_groups != n_pcr_priv:
         raise ValueError('--phases= specifications must match --pcr-private-key=')
 
-    if opts.cmdline and opts.cmdline.startswith('@'):
-        opts.cmdline = Path(opts.cmdline[1:])
-    elif opts.cmdline:
+    opts.cmdline = resolve_at_path(opts.cmdline)
+
+    if isinstance(opts.cmdline, str):
         # Drop whitespace from the command line. If we're reading from a file,
         # we copy the contents verbatim. But configuration specified on the command line
         # or in the config file may contain additional whitespace that has no meaning.
         opts.cmdline = ' '.join(opts.cmdline.split())
 
-    if opts.os_release and opts.os_release.startswith('@'):
-        opts.os_release = Path(opts.os_release[1:])
-    elif not opts.os_release and opts.linux:
+    opts.os_release = resolve_at_path(opts.os_release)
+
+    if not opts.os_release and opts.linux:
         p = Path('/etc/os-release')
         if not p.exists():
             p = Path('/usr/lib/os-release')