adding uninstall method

This commit is contained in:
Nick Lang 2012-03-16 00:28:24 -06:00
parent 56d325904e
commit d68e381371

View File

@ -16,9 +16,9 @@ def _get_pip_bin(bin_env):
if os.path.exists(os.path.join(bin_env, 'bin', 'pip')):
pip_bin = os.path.join(bin_env, 'bin', 'pip')
else:
pip_bin = bin_env
pip_bin = bin_env
return pip_bin
def install(packages=None,
requirements=None,
@ -50,7 +50,7 @@ def install(packages=None,
Install packages individually or from a pip requirements file. Install
packages globally or to a virtualenv.
packages
packages
comma separated list of packages to install
requirements
path to requirements
@ -114,7 +114,7 @@ def install(packages=None,
option options to pass multiple options to setup.py
install. If you are using an option with a directory
path, be sure to use absolute path.
CLI Example::
@ -125,25 +125,23 @@ def install(packages=None,
salt '*' pip.install <package name> bin_env=/path/to/virtualenv
salt '*' pip.install <package name> bin_env=/path/to/pip_bin
Comlicated CLI example::
salt '*' pip.install markdown,django editable=git+https://github.com/worldcompany/djangoembed.git#egg=djangoembed upgrade=True no_deps=True
'''
pip_bin = _get_pip_bin(bin_env)
cmd = '{pip_bin} install'.format(pip_bin=pip_bin)
print cmd
cmd = '{0} install'.format(_get_pip_bin(bin_env))
if packages:
pkg = packages.replace(",", " ")
cmd = '{cmd} {pkg}'.format(
cmd = '{cmd} {pkg} '.format(
cmd=cmd, pkg=pkg)
print cmd
if requirements:
cmd = '{cmd} --requirements{requirements}'.format(
cmd = '{cmd} --requirements{requirements} '.format(
cmd=cmd, requirements=requirements)
if log:
try:
@ -151,11 +149,11 @@ def install(packages=None,
os.path.exists(log)
except IOError:
raise IOError("'%s' is not writeable" % log)
cmd = '{cmd} --{log}'.format(
cmd = '{cmd} --{log} '.format(
cmd=cmd, log=log)
if proxy:
cmd = '{cmd} --proxy={proxy}'.format(
cmd = '{cmd} --proxy={proxy} '.format(
cmd=cmd, proxy=proxy)
if timeout:
@ -163,13 +161,13 @@ def install(packages=None,
int(timeout)
except ValueError:
raise ValueError("'%s' is not a valid integer base 10.")
cmd = '{cmd} --timeout={timeout}'.format(
cmd = '{cmd} --timeout={timeout} '.format(
cmd=cmd, timeout=timeout)
if editable:
if editable.find('egg') == -1:
raise Exception('You must specify an egg for this editable')
cmd = '{cmd} --editable={editable}'.format(
cmd = '{cmd} --editable={editable} '.format(
cmd=cmd, editable=editable)
if find_links:
@ -181,68 +179,145 @@ def install(packages=None,
if index_url:
if not index_url.startswith("http://"):
raise Exception("'%s' must be a valid url" % index_url)
cmd = '{cmd} --index_url={index_url}'.format(
cmd = '{cmd} --index_url={index_url} '.format(
cmd=cmd, index_url=index_url)
if extra_index_url:
if not extra_index_url.startswith("http://"):
raise Exception("'%s' must be a valid url" % extra_index_url)
cmd = '{cmd} --extra_index_url={extra_index_url}'.format(
cmd = '{cmd} --extra_index_url={extra_index_url} '.format(
cmd=cmd, extra_index_url=extra_index_url)
if no_index:
cmd = '{cmd} --no-index'.format(cmd=cmd)
cmd = '{cmd} --no-index '.format(cmd=cmd)
if mirrors:
if not mirrors.startswith("http://"):
raise Exception("'%s' must be a valid url" % mirrors)
cmd = '{cmd} --use-mirrors --mirrors={mirrors}'.format(
cmd = '{cmd} --use-mirrors --mirrors={mirrors} '.format(
cmd=cmd, mirrors=mirrors)
if build:
cmd = '{cmd} --build={build}'.format(
cmd = '{cmd} --build={build} '.format(
cmd=cmd, build=build)
if target:
cmd = '{cmd} --target={target}'.format(
cmd = '{cmd} --target={target} '.format(
cmd=cmd, target=target)
if download:
cmd = '{cmd} --download={download}'.format(
cmd = '{cmd} --download={download} '.format(
cmd=cmd, download=download)
if download_cache:
cmd = '{cmd} --download_cache={download_cache}'.format(
cmd = '{cmd} --download_cache={download_cache} '.format(
cmd=cmd, download_cache=download_cache)
if source:
cmd = '{cmd} --source={source}'.format(
cmd = '{cmd} --source={source} '.format(
cmd=cmd, source=source)
if upgrade:
cmd = '{cmd} --upgrade'.format(cmd=cmd)
cmd = '{cmd} --upgrade '.format(cmd=cmd)
if force_reinstall:
cmd = '{cmd} --force-reinstall'.format(cmd=cmd)
cmd = '{cmd} --force-reinstall '.format(cmd=cmd)
if ignore_installed:
cmd = '{cmd} --ignore-installed'.format(cmd=cmd)
cmd = '{cmd} --ignore-installed '.format(cmd=cmd)
if no_deps:
cmd = '{cmd} --no-deps'.format(cmd=cmd)
cmd = '{cmd} --no-deps '.format(cmd=cmd)
if no_install:
cmd = '{cmd} --no-install'.format(cmd=cmd)
cmd = '{cmd} --no-install '.format(cmd=cmd)
if no_download:
cmd = '{cmd} --no-download'.format(cmd=cmd)
cmd = '{cmd} --no-download '.format(cmd=cmd)
if install_options:
cmd = '{cmd} --install-options={install_options}'.format(
cmd = '{cmd} --install-options={install_options} '.format(
cmd=cmd, install_options=install_options)
return __salt__['cmd.run'](cmd)
def uninstall(packages=None,
requirements=None,
bin_env=None,
log=None,
proxy=None,
timeout=None):
'''
Uninstall packages with pip
Uninstall packages individually or from a pip requirements file. Uninstall
packages globally or from a virtualenv.
packages
comma separated list of packages to install
requirements
path to requirements
bin_env
path to pip bin or path to virtualenv. If doing an uninstall from
the system python and want to use a specific pip bin (pip-2.7,
pip-2.6, etc..) just specify the pip bin you want.
If uninstalling from a virtualenv, just use the path to the virtualenv
(/home/code/path/to/virtualenv/)
log
Log file where a complete (maximum verbosity) record will be kept
proxy
Specify a proxy in the form
user:passwd@proxy.server:port. Note that the
user:password@ is optional and required only if you
are behind an authenticated proxy. If you provide
user@proxy.server:port then you will be prompted for a
password.
timeout
Set the socket timeout (default 15 seconds)
CLI Example::
salt '*' pip.uninstall <package name>,<package2 name>
salt '*' pip.uninstall requirements=/path/to/requirements.txt
salt '*' pip.uninstall <package name> bin_env=/path/to/virtualenv
salt '*' pip.uninstall <package name> bin_env=/path/to/pip_bin
'''
cmd = '{0} uninstall -y '.format(_get_pip_bin(bin_env))
if requirements:
cmd = '{cmd} --requirements{requirements} '.format(
cmd=cmd, requirements=requirements)
if log:
try:
# TODO make this check if writeable
os.path.exists(log)
except IOError:
raise IOError("'%s' is not writeable" % log)
cmd = '{cmd} --{log} '.format(
cmd=cmd, log=log)
if proxy:
cmd = '{cmd} --proxy={proxy} '.format(
cmd=cmd, proxy=proxy)
if timeout:
try:
int(timeout)
except ValueError:
raise ValueError("'%s' is not a valid integer base 10.")
cmd = '{cmd} --timeout={timeout} '.format(
cmd=cmd, timeout=timeout)
return __salt__['cmd.run'](cmd).split('\n')
def freeze(bin_env=None):
'''
Return a list of installed packages either globally or in the specified
@ -257,8 +332,7 @@ def freeze(bin_env=None):
to the pip that is installed in the virtualenv. This option can also be
set in the minion config file as ``pip.pip_bin``.
'''
pip_bin = _get_pip_bin(bin_env)
cmd = '{0} freeze'.format(pip_bin)
cmd = '{0} freeze'.format(_get_pip_bin(bin_env))
return __salt__['cmd.run'](cmd).split('\n')