mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 01:18:58 +00:00
Merge pull request #6339 from terminalmage/quickfix
pip: deprecate runas param
This commit is contained in:
commit
dc5a07fdb9
@ -112,6 +112,7 @@ def install(pkgs=None,
|
|||||||
no_download=False,
|
no_download=False,
|
||||||
global_options=None,
|
global_options=None,
|
||||||
install_options=None,
|
install_options=None,
|
||||||
|
user=None,
|
||||||
runas=None,
|
runas=None,
|
||||||
no_chown=False,
|
no_chown=False,
|
||||||
cwd=None,
|
cwd=None,
|
||||||
@ -198,10 +199,13 @@ def install(pkgs=None,
|
|||||||
global_options
|
global_options
|
||||||
Extra global options to be supplied to the setup.py call before the
|
Extra global options to be supplied to the setup.py call before the
|
||||||
install command.
|
install command.
|
||||||
runas
|
user
|
||||||
User to run pip as
|
The user under which to run pip
|
||||||
|
.. note::
|
||||||
|
The ``runas`` argument is deprecated as of 0.16.1. ``user`` should be
|
||||||
|
used instead.
|
||||||
no_chown
|
no_chown
|
||||||
When runas is given, do not attempt to copy and chown
|
When user is given, do not attempt to copy and chown
|
||||||
a requirements file
|
a requirements file
|
||||||
cwd
|
cwd
|
||||||
Current working directory to run pip from
|
Current working directory to run pip from
|
||||||
@ -236,6 +240,15 @@ def install(pkgs=None,
|
|||||||
if env and not bin_env:
|
if env and not bin_env:
|
||||||
bin_env = env
|
bin_env = env
|
||||||
|
|
||||||
|
# Support deprecated 'runas' arg
|
||||||
|
if not user and runas is not None:
|
||||||
|
user = str(runas)
|
||||||
|
salt.utils.warn_until(
|
||||||
|
(0, 18),
|
||||||
|
'The \'runas\' argument to pip.install is deprecated, and will be '
|
||||||
|
'removed in 0.18.0. Please use \'user\' instead.'
|
||||||
|
)
|
||||||
|
|
||||||
cmd = [_get_pip_bin(bin_env), 'install']
|
cmd = [_get_pip_bin(bin_env), 'install']
|
||||||
|
|
||||||
if activate and bin_env:
|
if activate and bin_env:
|
||||||
@ -264,16 +277,16 @@ def install(pkgs=None,
|
|||||||
}
|
}
|
||||||
requirement = cached_requirements
|
requirement = cached_requirements
|
||||||
|
|
||||||
if runas and not no_chown:
|
if user and not no_chown:
|
||||||
# Need to make a temporary copy since the runas user will, most
|
# Need to make a temporary copy since the user will, most
|
||||||
# likely, not have the right permissions to read the file
|
# likely, not have the right permissions to read the file
|
||||||
treq = salt.utils.mkstemp()
|
treq = salt.utils.mkstemp()
|
||||||
shutil.copyfile(requirement, treq)
|
shutil.copyfile(requirement, treq)
|
||||||
logger.debug(
|
logger.debug(
|
||||||
'Changing ownership of requirements file {0!r} to '
|
'Changing ownership of requirements file {0!r} to '
|
||||||
'user {1!r}'.format(treq, runas)
|
'user {1!r}'.format(treq, user)
|
||||||
)
|
)
|
||||||
__salt__['file.chown'](treq, runas, None)
|
__salt__['file.chown'](treq, user, None)
|
||||||
cleanup_requirements.append(treq)
|
cleanup_requirements.append(treq)
|
||||||
cmd.append('--requirement={0!r}'.format(treq or requirement))
|
cmd.append('--requirement={0!r}'.format(treq or requirement))
|
||||||
|
|
||||||
@ -432,7 +445,7 @@ def install(pkgs=None,
|
|||||||
cmd.append('--editable={0}'.format(entry))
|
cmd.append('--editable={0}'.format(entry))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
cmd_kwargs = dict(runas=runas, cwd=cwd)
|
cmd_kwargs = dict(runas=user, cwd=cwd)
|
||||||
if bin_env and os.path.isdir(bin_env):
|
if bin_env and os.path.isdir(bin_env):
|
||||||
cmd_kwargs['env'] = {'VIRTUAL_ENV': bin_env}
|
cmd_kwargs['env'] = {'VIRTUAL_ENV': bin_env}
|
||||||
return __salt__['cmd.run_all'](' '.join(cmd), **cmd_kwargs)
|
return __salt__['cmd.run_all'](' '.join(cmd), **cmd_kwargs)
|
||||||
@ -450,6 +463,7 @@ def uninstall(pkgs=None,
|
|||||||
log=None,
|
log=None,
|
||||||
proxy=None,
|
proxy=None,
|
||||||
timeout=None,
|
timeout=None,
|
||||||
|
user=None,
|
||||||
runas=None,
|
runas=None,
|
||||||
no_chown=False,
|
no_chown=False,
|
||||||
cwd=None,
|
cwd=None,
|
||||||
@ -481,10 +495,13 @@ def uninstall(pkgs=None,
|
|||||||
password.
|
password.
|
||||||
timeout
|
timeout
|
||||||
Set the socket timeout (default 15 seconds)
|
Set the socket timeout (default 15 seconds)
|
||||||
runas
|
user
|
||||||
User to run pip as
|
The user under which to run pip
|
||||||
|
.. note::
|
||||||
|
The ``runas`` argument is deprecated as of 0.16.1. ``user`` should be
|
||||||
|
used instead.
|
||||||
no_chown
|
no_chown
|
||||||
When runas is given, do not attempt to copy and chown
|
When user is given, do not attempt to copy and chown
|
||||||
a requirements file
|
a requirements file
|
||||||
cwd
|
cwd
|
||||||
Current working directory to run pip from
|
Current working directory to run pip from
|
||||||
@ -502,6 +519,15 @@ def uninstall(pkgs=None,
|
|||||||
'''
|
'''
|
||||||
cmd = [_get_pip_bin(bin_env), 'uninstall', '-y']
|
cmd = [_get_pip_bin(bin_env), 'uninstall', '-y']
|
||||||
|
|
||||||
|
# Support deprecated 'runas' arg
|
||||||
|
if not user and runas is not None:
|
||||||
|
user = str(runas)
|
||||||
|
salt.utils.warn_until(
|
||||||
|
(0, 18),
|
||||||
|
'The \'runas\' argument to pip.install is deprecated, and will be '
|
||||||
|
'removed in 0.18.0. Please use \'user\' instead.'
|
||||||
|
)
|
||||||
|
|
||||||
cleanup_requirements = []
|
cleanup_requirements = []
|
||||||
if requirements is not None:
|
if requirements is not None:
|
||||||
if isinstance(requirements, string_types):
|
if isinstance(requirements, string_types):
|
||||||
@ -524,16 +550,16 @@ def uninstall(pkgs=None,
|
|||||||
}
|
}
|
||||||
requirement = cached_requirements
|
requirement = cached_requirements
|
||||||
|
|
||||||
if runas and not no_chown:
|
if user and not no_chown:
|
||||||
# Need to make a temporary copy since the runas user will, most
|
# Need to make a temporary copy since the user will, most
|
||||||
# likely, not have the right permissions to read the file
|
# likely, not have the right permissions to read the file
|
||||||
treq = salt.utils.mkstemp()
|
treq = salt.utils.mkstemp()
|
||||||
shutil.copyfile(requirement, treq)
|
shutil.copyfile(requirement, treq)
|
||||||
logger.debug(
|
logger.debug(
|
||||||
'Changing ownership of requirements file {0!r} to '
|
'Changing ownership of requirements file {0!r} to '
|
||||||
'user {1!r}'.format(treq, runas)
|
'user {1!r}'.format(treq, user)
|
||||||
)
|
)
|
||||||
__salt__['file.chown'](treq, runas, None)
|
__salt__['file.chown'](treq, user, None)
|
||||||
cleanup_requirements.append(treq)
|
cleanup_requirements.append(treq)
|
||||||
cmd.append('--requirement={0!r}'.format(treq or requirement))
|
cmd.append('--requirement={0!r}'.format(treq or requirement))
|
||||||
|
|
||||||
@ -563,7 +589,7 @@ def uninstall(pkgs=None,
|
|||||||
pkgs = [p.strip() for p in pkgs.split(',')]
|
pkgs = [p.strip() for p in pkgs.split(',')]
|
||||||
cmd.extend(pkgs)
|
cmd.extend(pkgs)
|
||||||
|
|
||||||
cmd_kwargs = dict(runas=runas, cwd=cwd)
|
cmd_kwargs = dict(runas=user, cwd=cwd)
|
||||||
if bin_env and os.path.isdir(bin_env):
|
if bin_env and os.path.isdir(bin_env):
|
||||||
cmd_kwargs['env'] = {'VIRTUAL_ENV': bin_env}
|
cmd_kwargs['env'] = {'VIRTUAL_ENV': bin_env}
|
||||||
|
|
||||||
@ -578,6 +604,7 @@ def uninstall(pkgs=None,
|
|||||||
|
|
||||||
|
|
||||||
def freeze(bin_env=None,
|
def freeze(bin_env=None,
|
||||||
|
user=None,
|
||||||
runas=None,
|
runas=None,
|
||||||
cwd=None):
|
cwd=None):
|
||||||
'''
|
'''
|
||||||
@ -590,8 +617,11 @@ def freeze(bin_env=None,
|
|||||||
pip-2.6, etc..) just specify the pip bin you want.
|
pip-2.6, etc..) just specify the pip bin you want.
|
||||||
If uninstalling from a virtualenv, just use the path to the virtualenv
|
If uninstalling from a virtualenv, just use the path to the virtualenv
|
||||||
(/home/code/path/to/virtualenv/)
|
(/home/code/path/to/virtualenv/)
|
||||||
runas
|
user
|
||||||
User to run pip as
|
The user under which to run pip
|
||||||
|
.. note::
|
||||||
|
The ``runas`` argument is deprecated as of 0.16.1. ``user`` should be
|
||||||
|
used instead.
|
||||||
cwd
|
cwd
|
||||||
Current working directory to run pip from
|
Current working directory to run pip from
|
||||||
|
|
||||||
@ -599,9 +629,17 @@ def freeze(bin_env=None,
|
|||||||
|
|
||||||
salt '*' pip.freeze /home/code/path/to/virtualenv/
|
salt '*' pip.freeze /home/code/path/to/virtualenv/
|
||||||
'''
|
'''
|
||||||
|
# Support deprecated 'runas' arg
|
||||||
|
if not user and runas is not None:
|
||||||
|
user = str(runas)
|
||||||
|
salt.utils.warn_until(
|
||||||
|
(0, 18),
|
||||||
|
'The \'runas\' argument to pip.install is deprecated, and will be '
|
||||||
|
'removed in 0.18.0. Please use \'user\' instead.'
|
||||||
|
)
|
||||||
|
|
||||||
cmd = [_get_pip_bin(bin_env), 'freeze']
|
cmd = [_get_pip_bin(bin_env), 'freeze']
|
||||||
cmd_kwargs = dict(runas=runas, cwd=cwd)
|
cmd_kwargs = dict(runas=user, cwd=cwd)
|
||||||
if bin_env and os.path.isdir(bin_env):
|
if bin_env and os.path.isdir(bin_env):
|
||||||
cmd_kwargs['env'] = {'VIRTUAL_ENV': bin_env}
|
cmd_kwargs['env'] = {'VIRTUAL_ENV': bin_env}
|
||||||
result = __salt__['cmd.run_all'](' '.join(cmd), **cmd_kwargs)
|
result = __salt__['cmd.run_all'](' '.join(cmd), **cmd_kwargs)
|
||||||
@ -614,6 +652,7 @@ def freeze(bin_env=None,
|
|||||||
|
|
||||||
def list_(prefix=None,
|
def list_(prefix=None,
|
||||||
bin_env=None,
|
bin_env=None,
|
||||||
|
user=None,
|
||||||
runas=None,
|
runas=None,
|
||||||
cwd=None):
|
cwd=None):
|
||||||
'''
|
'''
|
||||||
@ -628,7 +667,16 @@ def list_(prefix=None,
|
|||||||
|
|
||||||
cmd = [_get_pip_bin(bin_env), 'freeze']
|
cmd = [_get_pip_bin(bin_env), 'freeze']
|
||||||
|
|
||||||
cmd_kwargs = dict(runas=runas, cwd=cwd)
|
# Support deprecated 'runas' arg
|
||||||
|
if not user and runas is not None:
|
||||||
|
user = str(runas)
|
||||||
|
salt.utils.warn_until(
|
||||||
|
(0, 18),
|
||||||
|
'The \'runas\' argument to pip.install is deprecated, and will be '
|
||||||
|
'removed in 0.18.0. Please use \'user\' instead.'
|
||||||
|
)
|
||||||
|
|
||||||
|
cmd_kwargs = dict(runas=user, cwd=cwd)
|
||||||
if bin_env and os.path.isdir(bin_env):
|
if bin_env and os.path.isdir(bin_env):
|
||||||
cmd_kwargs['env'] = {'VIRTUAL_ENV': bin_env}
|
cmd_kwargs['env'] = {'VIRTUAL_ENV': bin_env}
|
||||||
result = __salt__['cmd.run_all'](' '.join(cmd), **cmd_kwargs)
|
result = __salt__['cmd.run_all'](' '.join(cmd), **cmd_kwargs)
|
||||||
|
@ -69,6 +69,8 @@ def installed(name,
|
|||||||
|
|
||||||
name
|
name
|
||||||
The name of the python package to install
|
The name of the python package to install
|
||||||
|
user
|
||||||
|
The user under which to run pip
|
||||||
pip_bin : None
|
pip_bin : None
|
||||||
Deprecated, use bin_env
|
Deprecated, use bin_env
|
||||||
env : None
|
env : None
|
||||||
@ -94,7 +96,7 @@ def installed(name,
|
|||||||
|
|
||||||
ret = {'name': name, 'result': None, 'comment': '', 'changes': {}}
|
ret = {'name': name, 'result': None, 'comment': '', 'changes': {}}
|
||||||
try:
|
try:
|
||||||
pip_list = __salt__['pip.list'](prefix, bin_env, runas=user, cwd=cwd)
|
pip_list = __salt__['pip.list'](prefix, bin_env, user=user, cwd=cwd)
|
||||||
except (CommandNotFoundError, CommandExecutionError) as err:
|
except (CommandNotFoundError, CommandExecutionError) as err:
|
||||||
ret['result'] = False
|
ret['result'] = False
|
||||||
ret['comment'] = 'Error installing \'{0}\': {1}'.format(name, err)
|
ret['comment'] = 'Error installing \'{0}\': {1}'.format(name, err)
|
||||||
@ -154,7 +156,7 @@ def installed(name,
|
|||||||
no_install=no_install,
|
no_install=no_install,
|
||||||
no_download=no_download,
|
no_download=no_download,
|
||||||
install_options=install_options,
|
install_options=install_options,
|
||||||
runas=user,
|
user=user,
|
||||||
no_chown=no_chown,
|
no_chown=no_chown,
|
||||||
cwd=cwd,
|
cwd=cwd,
|
||||||
pre_releases=pre_releases,
|
pre_releases=pre_releases,
|
||||||
@ -164,7 +166,7 @@ def installed(name,
|
|||||||
if pip_install_call and (pip_install_call['retcode'] == 0):
|
if pip_install_call and (pip_install_call['retcode'] == 0):
|
||||||
ret['result'] = True
|
ret['result'] = True
|
||||||
|
|
||||||
pkg_list = __salt__['pip.list'](prefix, bin_env, runas=user, cwd=cwd)
|
pkg_list = __salt__['pip.list'](prefix, bin_env, user=user, cwd=cwd)
|
||||||
if not pkg_list:
|
if not pkg_list:
|
||||||
ret['comment'] = (
|
ret['comment'] = (
|
||||||
'There was no error installing package \'{0}\' although '
|
'There was no error installing package \'{0}\' although '
|
||||||
@ -204,14 +206,15 @@ def removed(name,
|
|||||||
|
|
||||||
name
|
name
|
||||||
The name of the package to uninstall
|
The name of the package to uninstall
|
||||||
|
user
|
||||||
|
The user under which to run pip
|
||||||
bin_env : None
|
bin_env : None
|
||||||
the pip executable or virtualenenv to use
|
the pip executable or virtualenenv to use
|
||||||
'''
|
'''
|
||||||
|
|
||||||
ret = {'name': name, 'result': None, 'comment': '', 'changes': {}}
|
ret = {'name': name, 'result': None, 'comment': '', 'changes': {}}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
pip_list = __salt__['pip.list'](bin_env=bin_env, runas=user, cwd=cwd)
|
pip_list = __salt__['pip.list'](bin_env=bin_env, user=user, cwd=cwd)
|
||||||
except (CommandExecutionError, CommandNotFoundError) as err:
|
except (CommandExecutionError, CommandNotFoundError) as err:
|
||||||
ret['result'] = False
|
ret['result'] = False
|
||||||
ret['comment'] = 'Error uninstalling \'{0}\': {1}'.format(name, err)
|
ret['comment'] = 'Error uninstalling \'{0}\': {1}'.format(name, err)
|
||||||
@ -233,7 +236,7 @@ def removed(name,
|
|||||||
log=log,
|
log=log,
|
||||||
proxy=proxy,
|
proxy=proxy,
|
||||||
timeout=timeout,
|
timeout=timeout,
|
||||||
runas=user,
|
user=user,
|
||||||
cwd=cwd,
|
cwd=cwd,
|
||||||
__env__='base'):
|
__env__='base'):
|
||||||
ret['result'] = True
|
ret['result'] = True
|
||||||
|
Loading…
Reference in New Issue
Block a user