From 706c81645ab4a3a140b7a38eee8f165f3887a11d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20M=E4kinen?= Date: Mon, 12 Mar 2012 10:52:55 +0200 Subject: [PATCH] Fixed errors from python facts if no python is installed. --- python/lib/facter/python.rb | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/python/lib/facter/python.rb b/python/lib/facter/python.rb index 3506f7e..0b39745 100644 --- a/python/lib/facter/python.rb +++ b/python/lib/facter/python.rb @@ -3,9 +3,14 @@ Facter.add('pythonsitedir') do if File.exists?('/usr/local/bin/python') pythonbin='/usr/local/bin/python' else - pythonbin='python' + system('which python > /dev/null 2>&1') + if $? == 0 + pythonbin='python' + end + end + if pythonbin + %x{#{pythonbin} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()"}.chomp end - %x{#{pythonbin} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()"}.chomp end end @@ -14,8 +19,13 @@ Facter.add('pythonversion') do if File.exists?('/usr/local/bin/python') pythonbin='/usr/local/bin/python' else - pythonbin='python' + system('which python > /dev/null 2>&1') + if $? == 0 + pythonbin='python' + end + end + if pythonbin + %x{#{pythonbin} -c "import platform; print platform.python_version()"}.chomp end - %x{#{pythonbin} -c "import platform; print platform.python_version()"}.chomp end end