71 lines
2.1 KiB
Diff
71 lines
2.1 KiB
Diff
|
From 4accc710ab2f92118f4777d13bc585d26e8e939e Mon Sep 17 00:00:00 2001
|
||
|
From: Michael Calmer <mc@suse.de>
|
||
|
Date: Wed, 17 Feb 2016 08:49:15 +0100
|
||
|
Subject: [PATCH 14/22] Check if rpm-python can be imported
|
||
|
|
||
|
---
|
||
|
salt/modules/zypper.py | 36 +++++++++++++++++++++---------------
|
||
|
1 file changed, 21 insertions(+), 15 deletions(-)
|
||
|
|
||
|
diff --git a/salt/modules/zypper.py b/salt/modules/zypper.py
|
||
|
index 7448f8b..d44ad6a 100644
|
||
|
--- a/salt/modules/zypper.py
|
||
|
+++ b/salt/modules/zypper.py
|
||
|
@@ -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
|
||
|
@@ -338,21 +343,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)
|
||
|
|
||
|
|
||
|
--
|
||
|
2.1.4
|
||
|
|