mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #25755 from twangboy/fix_25717
Fixed problem with dunder functions not being passed
This commit is contained in:
commit
f367acb253
1 changed files with 37 additions and 37 deletions
|
@ -35,56 +35,56 @@ def __virtual__():
|
|||
for simulating UAC forces a GUI prompt, and is not compatible with
|
||||
salt-minion running as SYSTEM.
|
||||
'''
|
||||
if __grains__['os_family'] != 'Windows':
|
||||
if not salt.utils.is_windows():
|
||||
return False
|
||||
elif __grains__['osrelease'] in ('XP', '2003Server'):
|
||||
return False
|
||||
return 'chocolatey'
|
||||
|
||||
|
||||
def _clear_context():
|
||||
def _clear_context(context):
|
||||
'''
|
||||
Clear variables stored in __context__. Run this function when a new version
|
||||
of chocolatey is installed.
|
||||
'''
|
||||
for var in (x for x in __context__ if x.startswith('chocolatey.')):
|
||||
__context__.pop(var)
|
||||
context.pop(var)
|
||||
|
||||
|
||||
def _yes():
|
||||
def _yes(context):
|
||||
'''
|
||||
Returns ['--yes'] if on v0.9.9.0 or later, otherwise returns an empty list
|
||||
'''
|
||||
if 'chocolatey._yes' in __context__:
|
||||
return __context__['chocolatey._yes']
|
||||
return context['chocolatey._yes']
|
||||
if _LooseVersion(chocolatey_version()) >= _LooseVersion('0.9.9'):
|
||||
answer = ['--yes']
|
||||
else:
|
||||
answer = []
|
||||
__context__['chocolatey._yes'] = answer
|
||||
context['chocolatey._yes'] = answer
|
||||
return answer
|
||||
|
||||
|
||||
def _find_chocolatey():
|
||||
def _find_chocolatey(context, salt):
|
||||
'''
|
||||
Returns the full path to chocolatey.bat on the host.
|
||||
'''
|
||||
if 'chocolatey._path' in __context__:
|
||||
return __context__['chocolatey._path']
|
||||
if 'chocolatey._path' in context:
|
||||
return context['chocolatey._path']
|
||||
choc_defaults = ['C:\\Chocolatey\\bin\\chocolatey.bat',
|
||||
'C:\\ProgramData\\Chocolatey\\bin\\chocolatey.exe', ]
|
||||
|
||||
choc_path = __salt__['cmd.which']('chocolatey.exe')
|
||||
choc_path = salt['cmd.which']('chocolatey.exe')
|
||||
if not choc_path:
|
||||
for choc_dir in choc_defaults:
|
||||
if __salt__['cmd.has_exec'](choc_dir):
|
||||
if salt['cmd.has_exec'](choc_dir):
|
||||
choc_path = choc_dir
|
||||
if not choc_path:
|
||||
err = ('Chocolatey not installed. Use chocolatey.bootstrap to '
|
||||
'install the Chocolatey package manager.')
|
||||
log.error(err)
|
||||
raise CommandExecutionError(err)
|
||||
__context__['chocolatey._path'] = choc_path
|
||||
context['chocolatey._path'] = choc_path
|
||||
return choc_path
|
||||
|
||||
|
||||
|
@ -102,7 +102,7 @@ def chocolatey_version():
|
|||
'''
|
||||
if 'chocolatey._version' in __context__:
|
||||
return __context__['chocolatey._version']
|
||||
cmd = [_find_chocolatey(), 'help']
|
||||
cmd = [_find_chocolatey(__context__, __salt__), 'help']
|
||||
out = __salt__['cmd.run'](cmd, python_shell=False)
|
||||
for line in out.splitlines():
|
||||
line = line.lower()
|
||||
|
@ -144,7 +144,7 @@ def bootstrap(force=False):
|
|||
'''
|
||||
# Check if Chocolatey is already present in the path
|
||||
try:
|
||||
choc_path = _find_chocolatey()
|
||||
choc_path = _find_chocolatey(__context__, __salt__)
|
||||
except CommandExecutionError:
|
||||
choc_path = None
|
||||
if choc_path and not force:
|
||||
|
@ -242,7 +242,7 @@ def list_(narrow, all_versions=False, pre_versions=False, source=None):
|
|||
salt '*' chocolatey.list <narrow>
|
||||
salt '*' chocolatey.list <narrow> all_versions=True
|
||||
'''
|
||||
choc_path = _find_chocolatey()
|
||||
choc_path = _find_chocolatey(__context__, __salt__)
|
||||
cmd = [choc_path, 'list', narrow]
|
||||
if salt.utils.is_true(all_versions):
|
||||
cmd.append('-AllVersions')
|
||||
|
@ -282,7 +282,7 @@ def list_webpi():
|
|||
|
||||
salt '*' chocolatey.list_webpi
|
||||
'''
|
||||
choc_path = _find_chocolatey()
|
||||
choc_path = _find_chocolatey(__context__, __salt__)
|
||||
cmd = [choc_path, 'list', '-Source', 'webpi']
|
||||
result = __salt__['cmd.run_all'](cmd, python_shell=False)
|
||||
|
||||
|
@ -305,7 +305,7 @@ def list_windowsfeatures():
|
|||
|
||||
salt '*' chocolatey.list_windowsfeatures
|
||||
'''
|
||||
choc_path = _find_chocolatey()
|
||||
choc_path = _find_chocolatey(__context__, __salt__)
|
||||
cmd = [choc_path, 'list', '-Source', 'windowsfeatures']
|
||||
result = __salt__['cmd.run_all'](cmd, python_shell=False)
|
||||
|
||||
|
@ -341,7 +341,7 @@ def install(name, version=None, source=None, force=False):
|
|||
salt '*' chocolatey.install <package name>
|
||||
salt '*' chocolatey.install <package name> version=<package version>
|
||||
'''
|
||||
choc_path = _find_chocolatey()
|
||||
choc_path = _find_chocolatey(__context__, __salt__)
|
||||
# chocolatey helpfully only supports a single package argument
|
||||
cmd = [choc_path, 'install', name]
|
||||
if version:
|
||||
|
@ -350,7 +350,7 @@ def install(name, version=None, source=None, force=False):
|
|||
cmd.extend(['-Source', source])
|
||||
if salt.utils.is_true(force):
|
||||
cmd.append('-Force')
|
||||
cmd.extend(_yes())
|
||||
cmd.extend(_yes(__context__))
|
||||
result = __salt__['cmd.run_all'](cmd, python_shell=False)
|
||||
|
||||
if result['retcode'] != 0:
|
||||
|
@ -358,7 +358,7 @@ def install(name, version=None, source=None, force=False):
|
|||
log.error(err)
|
||||
raise CommandExecutionError(err)
|
||||
elif name == 'chocolatey':
|
||||
_clear_context()
|
||||
_clear_context(__context__)
|
||||
|
||||
return result['stdout']
|
||||
|
||||
|
@ -376,9 +376,9 @@ def install_cygwin(name):
|
|||
|
||||
salt '*' chocolatey.install_cygwin <package name>
|
||||
'''
|
||||
choc_path = _find_chocolatey()
|
||||
choc_path = _find_chocolatey(__context__, __salt__)
|
||||
cmd = [choc_path, 'cygwin', name]
|
||||
cmd.extend(_yes())
|
||||
cmd.extend(_yes(__context__))
|
||||
result = __salt__['cmd.run_all'](cmd, python_shell=False)
|
||||
|
||||
if result['retcode'] != 0:
|
||||
|
@ -407,11 +407,11 @@ def install_gem(name, version=None):
|
|||
salt '*' chocolatey.install_gem <package name>
|
||||
salt '*' chocolatey.install_gem <package name> version=<package version>
|
||||
'''
|
||||
choc_path = _find_chocolatey()
|
||||
choc_path = _find_chocolatey(__context__, __salt__)
|
||||
cmd = [choc_path, 'gem', name]
|
||||
if version:
|
||||
cmd.extend(['-Version', version])
|
||||
cmd.extend(_yes())
|
||||
cmd.extend(_yes(__context__))
|
||||
result = __salt__['cmd.run_all'](cmd, python_shell=False)
|
||||
|
||||
if result['retcode'] != 0:
|
||||
|
@ -450,7 +450,7 @@ def install_missing(name, version=None, source=None):
|
|||
salt '*' chocolatey.install_missing <package name>
|
||||
salt '*' chocolatey.install_missing <package name> version=<package version>
|
||||
'''
|
||||
choc_path = _find_chocolatey()
|
||||
choc_path = _find_chocolatey(__context__, __salt__)
|
||||
if _LooseVersion(chocolatey_version()) >= _LooseVersion('0.9.8.24'):
|
||||
log.warning('installmissing is deprecated, using install')
|
||||
return install(name, version=version)
|
||||
|
@ -462,7 +462,7 @@ def install_missing(name, version=None, source=None):
|
|||
if source:
|
||||
cmd.extend(['-Source', source])
|
||||
# Shouldn't need this as this code should never run on v0.9.9 and newer
|
||||
cmd.extend(_yes())
|
||||
cmd.extend(_yes(__context__))
|
||||
result = __salt__['cmd.run_all'](cmd, python_shell=False)
|
||||
|
||||
if result['retcode'] != 0:
|
||||
|
@ -491,11 +491,11 @@ def install_python(name, version=None):
|
|||
salt '*' chocolatey.install_python <package name>
|
||||
salt '*' chocolatey.install_python <package name> version=<package version>
|
||||
'''
|
||||
choc_path = _find_chocolatey()
|
||||
choc_path = _find_chocolatey(__context__, __salt__)
|
||||
cmd = [choc_path, 'python', name]
|
||||
if version:
|
||||
cmd.extend(['-Version', version])
|
||||
cmd.extend(_yes())
|
||||
cmd.extend(_yes(__context__))
|
||||
result = __salt__['cmd.run_all'](cmd, python_shell=False)
|
||||
|
||||
if result['retcode'] != 0:
|
||||
|
@ -520,9 +520,9 @@ def install_windowsfeatures(name):
|
|||
|
||||
salt '*' chocolatey.install_windowsfeatures <package name>
|
||||
'''
|
||||
choc_path = _find_chocolatey()
|
||||
choc_path = _find_chocolatey(__context__, __salt__)
|
||||
cmd = [choc_path, 'windowsfeatures', name]
|
||||
cmd.extend(_yes())
|
||||
cmd.extend(_yes(__context__))
|
||||
result = __salt__['cmd.run_all'](cmd, python_shell=False)
|
||||
|
||||
if result['retcode'] != 0:
|
||||
|
@ -546,9 +546,9 @@ def install_webpi(name):
|
|||
|
||||
salt '*' chocolatey.install_webpi <package name>
|
||||
'''
|
||||
choc_path = _find_chocolatey()
|
||||
choc_path = _find_chocolatey(__context__, __salt__)
|
||||
cmd = [choc_path, 'webpi', name]
|
||||
cmd.extend(_yes())
|
||||
cmd.extend(_yes(__context__))
|
||||
result = __salt__['cmd.run_all'](cmd, python_shell=False)
|
||||
|
||||
if result['retcode'] != 0:
|
||||
|
@ -577,12 +577,12 @@ def uninstall(name, version=None):
|
|||
salt '*' chocolatey.uninstall <package name>
|
||||
salt '*' chocolatey.uninstall <package name> version=<package version>
|
||||
'''
|
||||
choc_path = _find_chocolatey()
|
||||
choc_path = _find_chocolatey(__context__, __salt__)
|
||||
# chocolatey helpfully only supports a single package argument
|
||||
cmd = [choc_path, 'uninstall', name]
|
||||
if version:
|
||||
cmd.extend(['-Version', version])
|
||||
cmd.extend(_yes())
|
||||
cmd.extend(_yes(__context__))
|
||||
result = __salt__['cmd.run_all'](cmd, python_shell=False)
|
||||
|
||||
if result['retcode'] != 0:
|
||||
|
@ -616,13 +616,13 @@ def update(name, source=None, pre_versions=False):
|
|||
salt "*" chocolatey.update <package name> pre_versions=True
|
||||
'''
|
||||
# chocolatey helpfully only supports a single package argument
|
||||
choc_path = _find_chocolatey()
|
||||
choc_path = _find_chocolatey(__context__, __salt__)
|
||||
cmd = [choc_path, 'update', name]
|
||||
if source:
|
||||
cmd.extend(['-Source', source])
|
||||
if salt.utils.is_true(pre_versions):
|
||||
cmd.append('-PreRelease')
|
||||
cmd.extend(_yes())
|
||||
cmd.extend(_yes(__context__))
|
||||
result = __salt__['cmd.run_all'](cmd, python_shell=False)
|
||||
|
||||
if result['retcode'] != 0:
|
||||
|
@ -659,7 +659,7 @@ def version(name, check_remote=False, source=None, pre_versions=False):
|
|||
salt "*" chocolatey.version <package name>
|
||||
salt "*" chocolatey.version <package name> check_remote=True
|
||||
'''
|
||||
choc_path = _find_chocolatey()
|
||||
choc_path = _find_chocolatey(__context__, __salt__)
|
||||
if not choc_path:
|
||||
err = 'Chocolatey not installed. Use chocolatey.bootstrap to install the Chocolatey package manager.'
|
||||
log.error(err)
|
||||
|
|
Loading…
Add table
Reference in a new issue