mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Add a cmp compatibility function utility
The ``cmp`` function has been removed in Python 3. This PR adds the functionality as a salt utility, so the function can be used across all Python versions. Fixes #42697
This commit is contained in:
parent
7bf2cdb363
commit
5605104285
2 changed files with 14 additions and 1 deletions
|
@ -22,6 +22,7 @@ from salt.ext.six.moves.urllib.request import urlopen as _urlopen # pylint: dis
|
|||
# Import salt libs
|
||||
import salt.key
|
||||
import salt.utils
|
||||
import salt.utils.compat
|
||||
import salt.utils.minions
|
||||
import salt.client
|
||||
import salt.client.ssh
|
||||
|
@ -669,7 +670,7 @@ def versions():
|
|||
ver_diff = -2
|
||||
else:
|
||||
minion_version = salt.version.SaltStackVersion.parse(minions[minion])
|
||||
ver_diff = cmp(minion_version, master_version)
|
||||
ver_diff = salt.utils.compat.cmp(minion_version, master_version)
|
||||
|
||||
if ver_diff not in version_status:
|
||||
version_status[ver_diff] = {}
|
||||
|
|
|
@ -46,3 +46,15 @@ def deepcopy_bound(name):
|
|||
finally:
|
||||
copy._deepcopy_dispatch = pre_dispatch
|
||||
return ret
|
||||
|
||||
|
||||
def cmp(x, y):
|
||||
'''
|
||||
Compatibility helper function to replace the ``cmp`` function from Python 2. The
|
||||
``cmp`` function is no longer available in Python 3.
|
||||
|
||||
cmp(x, y) -> integer
|
||||
|
||||
Return negative if x<y, zero if x==y, positive if x>y.
|
||||
'''
|
||||
return (x > y) - (x < y)
|
||||
|
|
Loading…
Add table
Reference in a new issue