summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Sullivan <nsullivan@kixeye.com>2014-03-18 13:15:32 +1000
committerNathan Sullivan <nsullivan@kixeye.com>2014-03-18 13:15:32 +1000
commit066a10ea68c340773a94d19769ff77c02c39f128 (patch)
tree54412d613b819042683c8c28ce50d2efdf112838
parent2dde12a6bb58d84eff90fb13e120303ac61f8f49 (diff)
add support for explicit version handling with ensure parameter for pip packages
-rw-r--r--manifests/pip.pp38
1 files changed, 32 insertions, 6 deletions
diff --git a/manifests/pip.pp b/manifests/pip.pp
index 7e332fe..cbd2ed8 100644
--- a/manifests/pip.pp
+++ b/manifests/pip.pp
@@ -77,18 +77,29 @@ define python::pip (
default => "--proxy=${proxy}",
}
- $grep_regex = $pkgname ? {
- /==/ => "^${pkgname}\$",
- default => "^${pkgname}==",
+ # If pkgname is not specified, use name (title) instead.
+ $use_pkgname = $pkgname ? {
+ undef => $name,
+ default => $pkgname
+ }
+
+ # Check if searching by explicit version.
+ if $ensure =~ /^((19|20)[0-9][0-9]-(0[1-9]|1[1-2])-([0-2][1-9]|3[0-1])|[0-9]+\.[0-9]+(\.[0-9]+)?)$/ {
+ $grep_regex = "^${use_pkgname}==${ensure}\$"
+ } else {
+ $grep_regex = $use_pkgname ? {
+ /==/ => "^${use_pkgname}\$",
+ default => "^${use_pkgname}==",
+ }
}
$egg_name = $egg ? {
- false => $pkgname,
+ false => $use_pkgname,
default => $egg
}
$source = $url ? {
- false => $pkgname,
+ false => $use_pkgname,
default => "${url}#egg=${egg_name}",
}
@@ -108,7 +119,20 @@ define python::pip (
case $ensure {
+ /^((19|20)[0-9][0-9]-(0[1-9]|1[1-2])-([0-2][1-9]|3[0-1])|[0-9]+\.[0-9]+(\.[0-9]+)?)$/: {
+ # Version formats as per http://guide.python-distribute.org/specification.html#standard-versioning-schemes
+ # Explicit version.
+ exec { "pip_install_${name}":
+ command => "${pip_env} wheel --help > /dev/null 2>&1 && { ${pip_env} wheel --version > /dev/null 2>&1 || wheel_support_flag='--no-use-wheel'; } ; ${pip_env} --log ${cwd}/pip.log install ${install_args} \$wheel_support_flag ${proxy_flag} ${source}==${ensure}",
+ unless => "${pip_env} freeze | grep -i -e ${grep_regex}",
+ user => $owner,
+ environment => $environment,
+ path => ['/usr/local/bin','/usr/bin','/bin', '/usr/sbin'],
+ }
+ }
+
present: {
+ # Whatever version is available.
exec { "pip_install_${name}":
command => "${pip_env} wheel --help > /dev/null 2>&1 && { ${pip_env} wheel --version > /dev/null 2>&1 || wheel_support_flag='--no-use-wheel'; } ; ${pip_env} --log ${cwd}/pip.log install ${install_args} \$wheel_support_flag ${proxy_flag} ${source}",
unless => "${pip_env} freeze | grep -i -e ${grep_regex}",
@@ -119,6 +143,7 @@ define python::pip (
}
latest: {
+ # Latest version.
exec { "pip_install_${name}":
command => "${pip_env} wheel --help > /dev/null 2>&1 && { ${pip_env} wheel --version > /dev/null 2>&1 || wheel_support_flag='--no-use-wheel'; } ; ${pip_env} --log ${cwd}/pip.log install --upgrade \$wheel_support_flag ${proxy_flag} ${source}",
user => $owner,
@@ -128,8 +153,9 @@ define python::pip (
}
default: {
+ # Anti-action, uninstall.
exec { "pip_uninstall_${name}":
- command => "echo y | ${pip_env} uninstall ${uninstall_args} ${proxy_flag} ${pkgname}",
+ command => "echo y | ${pip_env} uninstall ${uninstall_args} ${proxy_flag} ${use_pkgname}",
onlyif => "${pip_env} freeze | grep -i -e ${grep_regex}",
user => $owner,
environment => $environment,