From fd94e7cba4dfd6502eb5c66bb4cbc42ab3dc839a Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Sun, 14 Jul 2013 18:41:52 +0100 Subject: [PATCH] Fix multiple requirements for both install and uninstall. * Fixed typo when copying requirements file to the temporary file for `pip.install`. * Handling of the requirements file(s) was totally different on `pip.uninstall` when it the intended result is supposed to be the same(regarding the requirements file of course, not install/uninstall). Fixed it, and to fix it `no_chown` was also added in `pip.uninstall`, if it's needed to install, it should also be needed to uninstall. --- salt/modules/pip.py | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/salt/modules/pip.py b/salt/modules/pip.py index 7b1afef5c8..00878f5fd6 100644 --- a/salt/modules/pip.py +++ b/salt/modules/pip.py @@ -265,7 +265,7 @@ def install(pkgs=None, # Need to make a temporary copy since the runas user will, most # likely, not have the right permissions to read the file treq = salt.utils.mkstemp() - shutil.copyfile(requirements, treq) + shutil.copyfile(requirement, treq) logger.debug( 'Changing ownership of requirements file {0!r} to ' 'user {1!r}'.format(treq, runas) @@ -445,6 +445,7 @@ def uninstall(pkgs=None, proxy=None, timeout=None, runas=None, + no_chown=False, cwd=None, __env__='base'): ''' @@ -476,6 +477,9 @@ def uninstall(pkgs=None, Set the socket timeout (default 15 seconds) runas User to run pip as + no_chown + When runas is given, do not attempt to copy and chown + a requirements file cwd Current working directory to run pip from @@ -505,11 +509,32 @@ def uninstall(pkgs=None, for requirement in requirements: treq = None if requirement.startswith('salt://'): - req = __salt__['cp.cache_file'](requirement, __env__) + cached_requirements = _get_cached_requirements( + requirement, __env__ + ) + if not cached_requirements: + return { + 'result': False, + 'comment': ( + 'pip requirements file {0!r} not found'.format( + requirement + ) + ) + } + requirement = cached_requirements + + if runas and not no_chown: + # Need to make a temporary copy since the runas user will, most + # likely, not have the right permissions to read the file treq = salt.utils.mkstemp() - shutil.copyfile(req, treq) + shutil.copyfile(requirement, treq) + logger.debug( + 'Changing ownership of requirements file {0!r} to ' + 'user {1!r}'.format(treq, runas) + ) + __salt__['file.chown'](treq, runas, None) cleanup_requirements.append(treq) - cmd.append('--requirements={0!r}'.format(treq or requirement)) + cmd.append('--requirement={0!r}'.format(treq or requirement)) if log: try: