]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
config: Improve GenericVersion performance
authorJoerg Behrmann <behrmann@physik.fu-berlin.de>
Mon, 24 Apr 2023 18:19:59 +0000 (20:19 +0200)
committerJoerg Behrmann <behrmann@physik.fu-berlin.de>
Mon, 24 Apr 2023 20:41:57 +0000 (22:41 +0200)
mkosi/config.py

index 107665288c58b43164d3dc9a77589c3427b7b90c..6edf1a576179640ad642a8d4e5610c255712e4f2 100644 (file)
@@ -1463,8 +1463,6 @@ class MkosiConfigParser:
         return namespace
 
 
-
-@functools.total_ordering
 class GenericVersion:
     def __init__(self, version: str):
         self._version = version
@@ -1481,6 +1479,23 @@ class GenericVersion:
         cmd = ["systemd-analyze", "compare-versions", self._version, "lt", other._version]
         return run(cmd, check=False).returncode == 0
 
+    def __le__(self, other: object) -> bool:
+        if not isinstance(other, GenericVersion):
+            return False
+        cmd = ["systemd-analyze", "compare-versions", self._version, "le", other._version]
+        return run(cmd, check=False).returncode == 0
+
+    def __gt__(self, other: object) -> bool:
+        if not isinstance(other, GenericVersion):
+            return False
+        cmd = ["systemd-analyze", "compare-versions", self._version, "gt", other._version]
+        return run(cmd, check=False).returncode == 0
+
+    def __ge__(self, other: object) -> bool:
+        if not isinstance(other, GenericVersion):
+            return False
+        cmd = ["systemd-analyze", "compare-versions", self._version, "ge", other._version]
+        return run(cmd, check=False).returncode == 0
 
 
 @dataclasses.dataclass(frozen=True)