mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Use apt_pkg.version_compare if available
This fixes #24397 Signed-off-by: Mathieu Le Marec - Pasquet <kiorky@cryptelium.net>
This commit is contained in:
parent
953725a563
commit
e15cb936b5
1 changed files with 15 additions and 0 deletions
|
@ -49,6 +49,12 @@ try:
|
|||
except ImportError:
|
||||
HAS_APT = False
|
||||
|
||||
try:
|
||||
import apt_pkg
|
||||
HAS_APTPKG = True
|
||||
except ImportError:
|
||||
HAS_APTPKG = False
|
||||
|
||||
try:
|
||||
import softwareproperties.ppa
|
||||
HAS_SOFTWAREPROPERTIES = True
|
||||
|
@ -1117,6 +1123,15 @@ def version_cmp(pkg1, pkg2):
|
|||
|
||||
salt '*' pkg.version_cmp '0.2.4-0ubuntu1' '0.2.4.1-0ubuntu1'
|
||||
'''
|
||||
# if we have apt_pkg, this will be quickier this way
|
||||
# and also do not rely on shell.
|
||||
if HAS_APTPKG:
|
||||
try:
|
||||
return apt_pkg.version_compare(pkg1, pkg2)
|
||||
except (TypeError, ValueError):
|
||||
# try to use shell version in case of errors via
|
||||
# the python binding
|
||||
pass
|
||||
try:
|
||||
for oper, ret in (('lt', -1), ('eq', 0), ('gt', 1)):
|
||||
cmd = 'dpkg --compare-versions {0} {1} ' \
|
||||
|
|
Loading…
Add table
Reference in a new issue