diff --git a/freeipa.spec.in b/freeipa.spec.in index 0cc37aa19..d4e23bce1 100644 --- a/freeipa.spec.in +++ b/freeipa.spec.in @@ -214,6 +214,7 @@ Requires: python-pyasn1 Requires: dbus-python Requires: python-dns >= 1.11.1 Requires: python-kdcproxy >= 0.3 +Requires: rpm-python %description -n python2-ipaserver IPA is an integrated solution to provide centrally managed Identity (users, diff --git a/ipaplatform/redhat/tasks.py b/ipaplatform/redhat/tasks.py index 099eb9e3b..a0b4060cb 100644 --- a/ipaplatform/redhat/tasks.py +++ b/ipaplatform/redhat/tasks.py @@ -30,11 +30,13 @@ import stat import socket import sys import base64 +from functools import total_ordering from subprocess import CalledProcessError from nss.error import NSPRError from pyasn1.error import PyAsn1Error from six.moves import urllib +import rpm from ipapython.ipa_log_manager import root_logger, log_mgr from ipapython import ipautil @@ -47,6 +49,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 +97,21 @@ def selinux_enabled(): return False +@total_ordering +class IPAVersion(object): + + def __init__(self, version): + self.version_tuple = stringToVersion(version) + + def __eq__(self, other): + assert isinstance(other, IPAVersion) + return rpm.labelCompare(self.version_tuple, other.version_tuple) == 0 + + def __lt__(self, other): + assert isinstance(other, IPAVersion) + return rpm.labelCompare(self.version_tuple, other.version_tuple) == -1 + + class RedHatTaskNamespace(BaseTaskNamespace): def restore_context(self, filepath, restorecon=paths.SBIN_RESTORECON): @@ -426,5 +472,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()