]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
config: add missing version comparision for non-equality
authorJoerg Behrmann <behrmann@physik.fu-berlin.de>
Tue, 25 Apr 2023 12:20:40 +0000 (14:20 +0200)
committerJoerg Behrmann <behrmann@physik.fu-berlin.de>
Tue, 25 Apr 2023 12:20:40 +0000 (14:20 +0200)
mkosi.md
mkosi/config.py
tests/test_parse_load_args.py

index 84fb1d9a27ef30a22ca747cb452c3a31d817e90c..14978356c112759fd3c821a325e4900b3202cb64 100644 (file)
--- a/mkosi.md
+++ b/mkosi.md
@@ -245,7 +245,7 @@ a boolean argument: either "1", "yes", or "true" to enable, or "0",
 `ImageVersion=`
 
 : Matches against the configured image version. Image versions can be prepended
-  by the operators `==`, `>=`, `<=`, `<`, `>` for rich version comparisons
+  by the operators `==`, `!=`, `>=`, `<=`, `<`, `>` for rich version comparisons
   according to the UAPI group version format specification. If no operator is
   prepended, the equality operator is assumed by default If this condition is
   used and no image Version has be explicitly configured yet, this condition
index eb086f2eb173fcb8a2264fbd5c81784d9cf56c59..75fdacc7405ccb6ed33ebe1f843821ad2c510bda 100644 (file)
@@ -287,6 +287,7 @@ def config_make_image_version_list_matcher(delimiter: str) -> ConfigMatchCallbac
         for v in version_specs:
             for sigil, opfunc in {
                 "==": operator.eq,
+                "!=": operator.ne,
                 "<=": operator.le,
                 ">=": operator.ge,
                 ">": operator.gt,
@@ -1518,6 +1519,12 @@ class GenericVersion:
         cmd = ["systemd-analyze", "compare-versions", self._version, "eq", other._version]
         return run(cmd, check=False).returncode == 0
 
+    def __ne__(self, other: object) -> bool:
+        if not isinstance(other, GenericVersion):
+            return False
+        cmd = ["systemd-analyze", "compare-versions", self._version, "ne", other._version]
+        return run(cmd, check=False).returncode == 0
+
     def __lt__(self, other: object) -> bool:
         if not isinstance(other, GenericVersion):
             return False
index 7908cfeaf1b54b5863e9ad981d2383be5581566b..c0bdf9a32c825989b5a8359174e550c792464497 100644 (file)
@@ -288,6 +288,7 @@ def test_match_imageid(image1: str, image2: str) -> None:
 def test_match_imageversion(op: str, version: str) -> None:
     opfunc = {
         "==": operator.eq,
+        "!=": operator.ne,
         "<": operator.lt,
         "<=": operator.le,
         ">": operator.gt,