blob: 9762c103d4f0285d46870388fd87b03a3701b8ab (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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}",
}
}
}
}
|