mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2024-12-23 15:40:01 -06:00
Fix version comparison
Use RPM library to compare vendor versions of IPA for redhat platform https://fedorahosted.org/freeipa/ticket/5535 Reviewed-By: Tomas Babej <tbabej@redhat.com>
This commit is contained in:
parent
e622da3e1a
commit
91913c5ba7
@ -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,
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user