mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Detect legacy versions of chocolatey correctly
- This commit makes sure to detect both newer and legacy versions of chocolatey before giving up
This commit is contained in:
parent
e7571e6d61
commit
157e0f446d
1 changed files with 23 additions and 13 deletions
|
@ -102,20 +102,30 @@ def chocolatey_version():
|
|||
'''
|
||||
if 'chocolatey._version' in __context__:
|
||||
return __context__['chocolatey._version']
|
||||
cmd = [_find_chocolatey(__context__, __salt__)]
|
||||
out = __salt__['cmd.run'](cmd, python_shell=False)
|
||||
for line in out.splitlines():
|
||||
line = line.lower()
|
||||
if line.startswith('chocolatey v'):
|
||||
__context__['chocolatey._version'] = line[12:]
|
||||
return __context__['chocolatey._version']
|
||||
elif line.startswith('version: '):
|
||||
try:
|
||||
__context__['chocolatey._version'] = \
|
||||
line.split(None, 1)[-1].strip("'")
|
||||
|
||||
def find_version(legacy=False):
|
||||
cmd = [_find_chocolatey(__context__, __salt__)]
|
||||
if legacy:
|
||||
cmd.append('help')
|
||||
out = __salt__['cmd.run'](cmd, python_shell=False)
|
||||
for line in out.splitlines():
|
||||
line = line.lower()
|
||||
if line.startswith('chocolatey v'):
|
||||
__context__['chocolatey._version'] = line[12:]
|
||||
return __context__['chocolatey._version']
|
||||
except Exception:
|
||||
pass
|
||||
elif line.startswith('version: '):
|
||||
try:
|
||||
__context__['chocolatey._version'] = \
|
||||
line.split(None, 1)[-1].strip("'")
|
||||
return __context__['chocolatey._version']
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# First try to find if we have a newer version of choco
|
||||
# which doesn't contain the help command,
|
||||
# else try for a legacy version
|
||||
find_version(legacy=False)
|
||||
find_version(legacy=True)
|
||||
raise CommandExecutionError('Unable to determine Chocolatey version')
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue