mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 09:23:56 +00:00
Check if rpm-python can be imported
This commit is contained in:
parent
6ad6a90955
commit
389a4b2548
@ -14,10 +14,15 @@ import os
|
||||
|
||||
# Import 3rd-party libs
|
||||
# pylint: disable=import-error,redefined-builtin,no-name-in-module
|
||||
import rpm
|
||||
import salt.ext.six as six
|
||||
from salt.ext.six.moves import configparser
|
||||
from salt.ext.six.moves.urllib.parse import urlparse as _urlparse
|
||||
|
||||
try:
|
||||
import rpm
|
||||
HAS_RPM = True
|
||||
except ImportError:
|
||||
HAS_RPM = False
|
||||
# pylint: enable=import-error,redefined-builtin,no-name-in-module
|
||||
|
||||
from xml.dom import minidom as dom
|
||||
@ -337,21 +342,22 @@ def version_cmp(ver1, ver2):
|
||||
|
||||
salt '*' pkg.version_cmp '0.2-001' '0.2.0.1-002'
|
||||
'''
|
||||
try:
|
||||
cmp_result = rpm.labelCompare(
|
||||
_string_to_evr(ver1),
|
||||
_string_to_evr(ver2)
|
||||
)
|
||||
if cmp_result not in (-1, 0, 1):
|
||||
raise Exception(
|
||||
'cmp result \'{0}\' is invalid'.format(cmp_result)
|
||||
if HAS_RPM:
|
||||
try:
|
||||
cmp_result = rpm.labelCompare(
|
||||
_string_to_evr(ver1),
|
||||
_string_to_evr(ver2)
|
||||
)
|
||||
if cmp_result not in (-1, 0, 1):
|
||||
raise Exception(
|
||||
'cmp result \'{0}\' is invalid'.format(cmp_result)
|
||||
)
|
||||
return cmp_result
|
||||
except Exception as exc:
|
||||
log.warning(
|
||||
'Failed to compare version \'{0}\' to \'{1}\' using '
|
||||
'rpmUtils: {2}'.format(ver1, ver2, exc)
|
||||
)
|
||||
return cmp_result
|
||||
except Exception as exc:
|
||||
log.warning(
|
||||
'Failed to compare version \'{0}\' to \'{1}\' using '
|
||||
'rpmUtils: {2}'.format(ver1, ver2, exc)
|
||||
)
|
||||
return salt.utils.version_cmp(ver1, ver2)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user