From: Joerg Behrmann Date: Tue, 25 Apr 2023 12:20:40 +0000 (+0200) Subject: config: add missing version comparision for non-equality X-Git-Tag: v15~198^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=29db743bcbd5e7b7ec89f4e11cbe7cae7bb468ac;p=thirdparty%2Fmkosi.git config: add missing version comparision for non-equality --- diff --git a/mkosi.md b/mkosi.md index 84fb1d9a2..14978356c 100644 --- 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 diff --git a/mkosi/config.py b/mkosi/config.py index eb086f2eb..75fdacc74 100644 --- a/mkosi/config.py +++ b/mkosi/config.py @@ -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 diff --git a/tests/test_parse_load_args.py b/tests/test_parse_load_args.py index 7908cfeaf..c0bdf9a32 100644 --- a/tests/test_parse_load_args.py +++ b/tests/test_parse_load_args.py @@ -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,