From: Daan De Meyer Date: Sat, 6 May 2023 10:07:59 +0000 (+0200) Subject: Allow skipping presets with a [Match] section X-Git-Tag: v15~177^2~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=96b0b17aaa85e54976d4398345dc508bdb10d0f7;p=thirdparty%2Fmkosi.git Allow skipping presets with a [Match] section If a preset's main config file has a [Match] section and it doesn't match, do not add the preset to the list of presets. --- diff --git a/mkosi/config.py b/mkosi/config.py index 514385687..5fa4cb8af 100644 --- a/mkosi/config.py +++ b/mkosi/config.py @@ -1167,7 +1167,7 @@ class MkosiConfigParser: self.settings_lookup = {s.name: s for s in self.SETTINGS} self.match_lookup = {m.name: m for m in self.MATCHES} - def parse_config(self, path: Path, namespace: argparse.Namespace) -> None: + def parse_config(self, path: Path, namespace: argparse.Namespace) -> bool: extras = path.is_dir() if path.is_dir(): @@ -1205,11 +1205,11 @@ class MkosiConfigParser: setattr(namespace, s.dest, default) if not match(s.dest, v, namespace): - return + return False elif (m := self.match_lookup.get(k)): if not m.match(v): - return + return False parser.remove_section("Match") @@ -1234,6 +1234,8 @@ class MkosiConfigParser: if Path(f).exists(): setattr(namespace, s.dest, s.parse(s.dest, f, namespace)) + return True + def create_argument_parser(self) -> argparse.ArgumentParser: action = config_make_action(self.SETTINGS) @@ -1918,7 +1920,8 @@ class MkosiConfigParser: cp = copy.deepcopy(namespace) with chdir(p if p.is_dir() else Path.cwd()): - self.parse_config(p if p.is_file() else Path("."), cp) + if not self.parse_config(p if p.is_file() else Path("."), cp): + continue setattr(cp, "preset", name)