diff options
author | Sergey Stankevich <sergey.stankevich@gmail.com> | 2012-09-09 18:36:30 -0400 |
---|---|---|
committer | Sergey Stankevich <sergey.stankevich@gmail.com> | 2012-09-09 18:36:30 -0400 |
commit | ed137893babebabdfdb5adf44d1a52272093ce8b (patch) | |
tree | f611108dc849fe8f4372aac981d7e242d59b957b /manifests/pip.pp |
Initial import
Diffstat (limited to 'manifests/pip.pp')
-rw-r--r-- | manifests/pip.pp | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/manifests/pip.pp b/manifests/pip.pp new file mode 100644 index 0000000..9762c10 --- /dev/null +++ b/manifests/pip.pp @@ -0,0 +1,64 @@ +# == Define: python::pip +# +# Installs and manages packages from pip. +# +# === Parameters +# +# [*ensure*] +# present|absent. Default: present +# +# [*virtualenv*] +# virtualenv to run pip in. +# +# [*proxy*] +# Proxy server to use for outbound connections. Default: none +# +# === Examples +# +# python::pip { 'flask': +# virtualenv => '/var/www/project1', +# proxy => 'http://proxy.domain.com:3128', +# } +# +# === Authors +# +# Sergey Stankevich +# +define python::pip ( + $virtualenv, + $ensure = present, + $proxy = false +) { + + # Parameter validation + if ! $virtualenv { + fail('python::pip: virtualenv parameter must not be empty') + } + + $proxy_flag = $proxy ? { + false => '', + default => "--proxy=${proxy}", + } + + $grep_regex = $name ? { + /==/ => "^${name}\$", + default => "^${name}==", + } + + case $ensure { + present: { + exec { "pip_install_${name}": + command => "${virtualenv}/bin/pip install ${proxy_flag} ${name}", + unless => "${virtualenv}/bin/pip freeze | grep -i -e ${grep_regex}", + } + } + + default: { + exec { "pip_uninstall_${name}": + command => "echo y | ${virtualenv}/bin/pip uninstall ${proxy_flag} ${name}", + onlyif => "${virtualenv}/bin/pip freeze | grep -i -e ${grep_regex}", + } + } + } + +} |