Skip to content

Commit d1f2392

Browse files
committed
INFRA-669: Add Windows support for ensure => absent
1 parent c063ea5 commit d1f2392

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

manifests/pip.pp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@
195195

196196
# Explicit version out of VCS when PIP supported URL is provided
197197
if $source =~ /^'(git\+|hg\+|bzr\+|svn\+)(http|https|ssh|svn|sftp|ftp|lp|git)(:\/\/).+'$/ {
198+
if $::operatingsystem == 'windows' { fail('Windows support not yet implemented') }
198199
if $_ensure != present and $_ensure != latest {
199200
$command = "${pip_install} ${install_args} ${pip_common_args}@${_ensure}#egg=${egg_name}"
200201
$unless_command = "${pip_env} list | grep -i -e '${grep_regex}'"
@@ -277,9 +278,21 @@
277278

278279
default: {
279280
# Anti-action, uninstall.
280-
if $::operatingsystem == 'windows' { fail('Not implemented yet') }
281-
$command = "echo y | ${pip_env} uninstall ${uninstall_args} ${proxy_flag} ${name}"
282-
$unless_command = "! ${pip_env} list | grep -i -e '${grep_regex}'"
281+
if $::operatingsystem != 'windows' {
282+
$command = "echo y | ${pip_env} uninstall ${uninstall_args} ${proxy_flag} ${name}"
283+
$unless_command = "! ${pip_env} list | grep -i -e '${grep_regex}'"
284+
} else {
285+
$command = "${pip_env} uninstall -y ${uninstall_args} ${proxy_flag} ${name}"
286+
$unless_command = join(["${python_env}/${python_executable} -c \"",
287+
"import subprocess;",
288+
"import sys;",
289+
"import re;",
290+
"package_name='${pkgname_with_dashes}';",
291+
"pip = lambda x: subprocess.Popen('${pip_env}'.split() + x, stdout=subprocess.PIPE, stderr=subprocess.STDOUT).communicate()[0];",
292+
"res = re.compile('^'+package_name+'==(.+)$', re.MULTILINE).search(pip(['freeze', '--all']));",
293+
"installed_version = res and res.group(1).strip() or None;",
294+
"sys.exit(installed_version is not None);\"",])
295+
}
283296
}
284297
}
285298
}

0 commit comments

Comments
 (0)