summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/facter/pip_version.rb27
-rw-r--r--lib/facter/python_version.rb40
-rw-r--r--lib/facter/virtualenv_version.rb27
3 files changed, 94 insertions, 0 deletions
diff --git a/lib/facter/pip_version.rb b/lib/facter/pip_version.rb
new file mode 100644
index 0000000..ce32f98
--- /dev/null
+++ b/lib/facter/pip_version.rb
@@ -0,0 +1,27 @@
+# Make pip version available as a fact
+# Works with pip loaded and without, pip installed using pip and package installed
+require 'puppet'
+pkg = Puppet::Type.type(:package).new(:name => "python-pip")
+Facter.add("pip_version") do
+ has_weight 100
+ setcode do
+ begin
+ /^pip (\d+\.\d+\.?\d*).*$/.match(Facter::Util::Resolution.exec('pip --version 2>/dev/null'))[1]
+ rescue
+ false
+ end
+ end
+end
+
+Facter.add("pip_version") do
+ has_weight 50
+ setcode do
+ begin
+ unless [:absent,'purged'].include?(pkg.retrieve[pkg.property(:ensure)])
+ /^.*(\d+\.\d+\.\d+).*$/.match(pkg.retrieve[pkg.property(:ensure)])[1]
+ end
+ rescue
+ false
+ end
+ end
+end
diff --git a/lib/facter/python_version.rb b/lib/facter/python_version.rb
new file mode 100644
index 0000000..bb9ec98
--- /dev/null
+++ b/lib/facter/python_version.rb
@@ -0,0 +1,40 @@
+# Make python versions available as facts
+# In lists default python and system python versions
+require 'puppet'
+pkg = Puppet::Type.type(:package).new(:name => "python")
+
+Facter.add("system_python_version") do
+ setcode do
+ begin
+ unless [:absent,'purged'].include?(pkg.retrieve[pkg.property(:ensure)])
+ /^(\d+\.\d+\.\d+).*$/.match(pkg.retrieve[pkg.property(:ensure)])[1]
+ end
+ rescue
+ false
+ end
+ end
+end
+
+Facter.add("python_version") do
+ has_weight 100
+ setcode do
+ begin
+ /^.*(\d+\.\d+\.\d+)$/.match(Facter::Util::Resolution.exec('python -V 2>&1'))[1]
+ rescue
+ false
+ end
+ end
+end
+
+Facter.add("python_version") do
+ has_weight 50
+ setcode do
+ begin
+ unless [:absent,'purged'].include?(pkg.retrieve[pkg.property(:ensure)])
+ /^.*(\d+\.\d+\.\d+).*$/.match(pkg.retrieve[pkg.property(:ensure)])[1]
+ end
+ rescue
+ false
+ end
+ end
+end
diff --git a/lib/facter/virtualenv_version.rb b/lib/facter/virtualenv_version.rb
new file mode 100644
index 0000000..04736ed
--- /dev/null
+++ b/lib/facter/virtualenv_version.rb
@@ -0,0 +1,27 @@
+# Make virtualenv version available as a fact
+# Works with virualenv loaded and without, pip installed and package installed
+require 'puppet'
+pkg = Puppet::Type.type(:package).new(:name => "virtualenv")
+Facter.add("virtualenv_version") do
+ has_weight 100
+ setcode do
+ begin
+ Facter::Util::Resolution.exec('virtualenv --version')
+ rescue
+ false
+ end
+ end
+end
+
+Facter.add("virtualenv_version") do
+ has_weight 50
+ setcode do
+ begin
+ unless [:absent,'purged'].include?(pkg.retrieve[pkg.property(:ensure)])
+ /^.*(\d+\.\d+\.\d+).*$/.match(pkg.retrieve[pkg.property(:ensure)])[1]
+ end
+ rescue
+ false
+ end
+ end
+end