summaryrefslogtreecommitdiff
path: root/lib/facter
diff options
context:
space:
mode:
authorSergey Stankevich <stankevich@users.noreply.github.com>2013-12-18 03:19:29 -0800
committerSergey Stankevich <stankevich@users.noreply.github.com>2013-12-18 03:19:29 -0800
commit9c60f2fcda9f361a85f4d8d0c5086d0dbc7a03e0 (patch)
treea006079539a58c4210be904cf92013e55164fcc8 /lib/facter
parent44ea60543b37ce5ddb9ff9b7411dbf7a0330f0e6 (diff)
parent607b527a11657ddd24545ebc33f0c0984d4c0093 (diff)
Merge pull request #43 from jalli/master
Add support for older pip/virtualenv versions, including facter facts for versions
Diffstat (limited to 'lib/facter')
-rw-r--r--lib/facter/pip_version.rb19
-rw-r--r--lib/facter/python_version.rb28
-rw-r--r--lib/facter/virtualenv_version.rb19
3 files changed, 66 insertions, 0 deletions
diff --git a/lib/facter/pip_version.rb b/lib/facter/pip_version.rb
new file mode 100644
index 0000000..48dd0bf
--- /dev/null
+++ b/lib/facter/pip_version.rb
@@ -0,0 +1,19 @@
+# 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
+ Facter::Util::Resolution.exec('pip --version')
+ end
+end
+
+Facter.add("pip_version") do
+ has_weight 50
+ setcode do
+ if pkg.retrieve[pkg.property(:ensure)] != 'purged'
+ /^.*(\d+\.\d+\.\d+).*$/.match(pkg.retrieve[pkg.property(:ensure)])[1]
+ end
+ end
+end
diff --git a/lib/facter/python_version.rb b/lib/facter/python_version.rb
new file mode 100644
index 0000000..a2bdb26
--- /dev/null
+++ b/lib/facter/python_version.rb
@@ -0,0 +1,28 @@
+# 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
+ if pkg.retrieve[pkg.property(:ensure)] != 'purged'
+ /^(\d+\.\d+\.\d+).*$/.match(pkg.retrieve[pkg.property(:ensure)])[1]
+ end
+ end
+end
+
+Facter.add("python_version") do
+ has_weight 100
+ setcode do
+ /^.*(\d+\.\d+\.\d+)$/.match(Facter::Util::Resolution.exec('python -V'))[1]
+ end
+end
+
+Facter.add("python_version") do
+ has_weight 50
+ setcode do
+ if pkg.retrieve[pkg.property(:ensure)] != 'purged'
+ /^.*(\d+\.\d+\.\d+).*$/.match(pkg.retrieve[pkg.property(:ensure)])[1]
+ end
+ end
+end
diff --git a/lib/facter/virtualenv_version.rb b/lib/facter/virtualenv_version.rb
new file mode 100644
index 0000000..c923b09
--- /dev/null
+++ b/lib/facter/virtualenv_version.rb
@@ -0,0 +1,19 @@
+# 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
+ Facter::Util::Resolution.exec('virtualenv --version')
+ end
+end
+
+Facter.add("virtualenv_version") do
+ has_weight 50
+ setcode do
+ if pkg.retrieve[pkg.property(:ensure)] != 'purged'
+ /^.*(\d+\.\d+\.\d+).*$/.match(pkg.retrieve[pkg.property(:ensure)])[1]
+ end
+ end
+end