From: Joerg Behrmann Date: Mon, 24 Apr 2023 18:19:59 +0000 (+0200) Subject: config: Improve GenericVersion performance X-Git-Tag: v15~200^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c0267200d7bf2fce4bf9f6c797a156bba32f24c2;p=thirdparty%2Fmkosi.git config: Improve GenericVersion performance --- diff --git a/mkosi/config.py b/mkosi/config.py index 107665288..6edf1a576 100644 --- a/mkosi/config.py +++ b/mkosi/config.py @@ -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)