On 10.12.2015 09:13, Lukas Slebodnik wrote:
On (09/12/15 19:22), Martin Basti wrote:
https://fedorahosted.org/freeipa/ticket/5535

Patch attached.
>From 8ef93485d61e8732166fb0c5b6c4559209740f3e Mon Sep 17 00:00:00 2001
From: Martin Basti <mba...@redhat.com>
Date: Wed, 9 Dec 2015 18:53:35 +0100
Subject: [PATCH] Fix version comparison

Use RPM library to compare vendor versions of IPA for redhat platform

https://fedorahosted.org/freeipa/ticket/5535
---
freeipa.spec.in             |  2 ++
ipaplatform/redhat/tasks.py | 19 +++++++++++++++++++
2 files changed, 21 insertions(+)

diff --git a/freeipa.spec.in b/freeipa.spec.in
index 
9f82b3695fb10c4db65cc31278364b3b34e26098..09feba7b8324f5e645da3e8010de86b6c3ee5ab9
 100644
--- a/freeipa.spec.in
+++ b/freeipa.spec.in
@@ -166,6 +166,8 @@ Requires: %{etc_systemd_dir}
Requires: gzip
Requires: python-gssapi >= 1.1.0
Requires: custodia
+Requires: rpm-python
+Requires: rpmdevtools
Could you explain why do you need the 2nd package?
It does not contains any python modules
and I cannot see usage of any binary in this patch

LS
Thanks for this catch, it is actually located in yum package, I rather copy stringToVersion function from there to IPA, to avoid dependency hell

Updated patch attached.
From 2cce3c5d0aa7de88e7a0a69af8a0e8e803bd8305 Mon Sep 17 00:00:00 2001
From: Martin Basti <mba...@redhat.com>
Date: Wed, 9 Dec 2015 18:53:35 +0100
Subject: [PATCH] Fix version comparison

Use RPM library to compare vendor versions of IPA for redhat platform

https://fedorahosted.org/freeipa/ticket/5535
---
 freeipa.spec.in             |  1 +
 ipaplatform/redhat/tasks.py | 47 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+)

diff --git a/freeipa.spec.in b/freeipa.spec.in
index 9f82b3695fb10c4db65cc31278364b3b34e26098..7a5565c497b0dd20ed73af3112a37ac25d2abe6e 100644
--- a/freeipa.spec.in
+++ b/freeipa.spec.in
@@ -166,6 +166,7 @@ Requires: %{etc_systemd_dir}
 Requires: gzip
 Requires: python-gssapi >= 1.1.0
 Requires: custodia
+Requires: rpm-python
 
 Provides: %{alt_name}-server = %{version}
 Conflicts: %{alt_name}-server
diff --git a/ipaplatform/redhat/tasks.py b/ipaplatform/redhat/tasks.py
index 94d2cb4e906965a20bcfdd55f38854005091c26f..9c975f9627ebd7207c1390aab264338972dbaff6 100644
--- a/ipaplatform/redhat/tasks.py
+++ b/ipaplatform/redhat/tasks.py
@@ -30,6 +30,7 @@ import stat
 import socket
 import sys
 import base64
+import rpm
 
 from subprocess import CalledProcessError
 from nss.error import NSPRError
@@ -47,6 +48,35 @@ from ipaplatform.redhat.authconfig import RedHatAuthConfig
 from ipaplatform.base.tasks import BaseTaskNamespace
 
 
+# copied from rpmUtils/miscutils.py
+def stringToVersion(verstring):
+    if verstring in [None, '']:
+        return (None, None, None)
+    i = verstring.find(':')
+    if i != -1:
+        try:
+            epoch = str(long(verstring[:i]))
+        except ValueError:
+            # look, garbage in the epoch field, how fun, kill it
+            epoch = '0' # this is our fallback, deal
+    else:
+        epoch = '0'
+    j = verstring.find('-')
+    if j != -1:
+        if verstring[i + 1:j] == '':
+            version = None
+        else:
+            version = verstring[i + 1:j]
+        release = verstring[j + 1:]
+    else:
+        if verstring[i + 1:] == '':
+            version = None
+        else:
+            version = verstring[i + 1:]
+        release = None
+    return (epoch, version, release)
+
+
 log = log_mgr.get_logger(__name__)
 
 
@@ -66,6 +96,16 @@ def selinux_enabled():
         return False
 
 
+class IPAVersion(object):
+
+    def __init__(self, version):
+        self.version_tuple = stringToVersion(version)
+
+    def __cmp__(self, other):
+        assert isinstance(other, IPAVersion)
+        return rpm.labelCompare(self.version_tuple, other.version_tuple)
+
+
 class RedHatTaskNamespace(BaseTaskNamespace):
 
     def restore_context(self, filepath, restorecon=paths.SBIN_RESTORECON):
@@ -423,5 +463,12 @@ class RedHatTaskNamespace(BaseTaskNamespace):
         super(RedHatTaskNamespace, self).create_system_user(name, group,
             homedir, shell, uid, gid, comment, create_homedir)
 
+    def parse_ipa_version(self, version):
+        """
+        :param version: textual version
+        :return: object implementing proper __cmp__ method for version compare
+        """
+        return IPAVersion(version)
+
 
 tasks = RedHatTaskNamespace()
-- 
2.5.0

-- 
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code

Reply via email to