From: Daan De Meyer Date: Fri, 7 Apr 2023 12:04:34 +0000 (+0200) Subject: Indicate required paths in list path settings X-Git-Tag: v15~265^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=153967812326ee4e30503dd59df1a31e99864763;p=thirdparty%2Fmkosi.git Indicate required paths in list path settings --- diff --git a/mkosi/__init__.py b/mkosi/__init__.py index 1cd3db431..4bb39e916 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -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", diff --git a/mkosi/config.py b/mkosi/config.py index 6e6d142ef..8a8de5c67 100644 --- a/mkosi/config.py +++ b/mkosi/config.py @@ -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: