]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Indicate required paths in list path settings
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 7 Apr 2023 12:04:34 +0000 (14:04 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 7 Apr 2023 12:04:34 +0000 (14:04 +0200)
mkosi/__init__.py
mkosi/config.py

index 1cd3db431f9816bd633e857737f5bf15ac7e7478..4bb39e9166de146e482e1ba09ee19fe90d60d8e5 100644 (file)
@@ -59,6 +59,7 @@ from mkosi.config import (
     config_parse_script,
     config_parse_string,
     make_enum_parser,
+    make_path_parser,
     parse_source_target_paths,
 )
 from mkosi.install import (
@@ -1118,7 +1119,7 @@ SETTINGS = (
         dest="repo_dirs",
         name="RepositoryDirectories",
         section="Distribution",
-        parse=config_make_list_parser(delimiter=",", parse=Path),
+        parse=config_make_list_parser(delimiter=",", parse=make_path_parser(required=True)),
         paths=("mkosi.reposdir",),
     ),
     MkosiConfigSetting(
@@ -1253,7 +1254,7 @@ SETTINGS = (
     MkosiConfigSetting(
         dest="initrds",
         section="Output",
-        parse=config_make_list_parser(delimiter=",", parse=Path),
+        parse=config_make_list_parser(delimiter=",", parse=make_path_parser(required=False)),
     ),
     MkosiConfigSetting(
         dest="base_packages",
@@ -1419,7 +1420,7 @@ SETTINGS = (
     MkosiConfigSetting(
         dest="extra_search_paths",
         section="Host",
-        parse=config_make_list_parser(delimiter=",", parse=Path),
+        parse=config_make_list_parser(delimiter=",", parse=make_path_parser(required=True)),
     ),
     MkosiConfigSetting(
         dest="qemu_gui",
index 6e6d142ef0a73faea8c4e3b6b3e848cf5ffc3bba..8a8de5c678f58f1fb57362361c0eaf80c967f589 100644 (file)
@@ -26,6 +26,8 @@ def parse_boolean(s: str) -> bool:
 
 def parse_source_target_paths(value: str) -> tuple[Path, Optional[Path]]:
     src, _, target = value.partition(':')
+    if not Path(src).exists():
+        die(f"{src} does not exist")
     if target and not Path(target).absolute():
         die("Target path must be absolute")
     return Path(src), Path(target) if target else None
@@ -306,6 +308,16 @@ def config_make_list_parser(delimiter: str, parse: Callable[[str], Any] = str) -
     return config_parse_list
 
 
+def make_path_parser(required: bool) -> Callable[[str], Path]:
+    def parse_path(value: str) -> Path:
+        if required and not Path(value).exists():
+            die(f"{value} does not exist")
+
+        return Path(value)
+
+    return parse_path
+
+
 def config_make_path_parser(required: bool) -> ConfigParseCallback:
     def config_parse_path(dest: str, value: Optional[str], namespace: argparse.Namespace) -> Optional[Path]:
         if dest in namespace: