]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Allow skipping presets with a [Match] section
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Sat, 6 May 2023 10:07:59 +0000 (12:07 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Sun, 7 May 2023 17:17:18 +0000 (19:17 +0200)
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.

mkosi/config.py

index 5143856878b6f265d5ce8576156a03cd897cfc48..5fa4cb8af3d4d6109145d4b327f19fd25915cbb5 100644 (file)
@@ -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)