summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSteven Danna <steve@opscode.com>2015-03-30 14:56:27 +0100
committerSteven Danna <steve@opscode.com>2015-03-31 12:01:13 +0100
commit9c5deecf8da150ca44b0494573f8c6b0d80d40fa (patch)
tree27a65ef665f803dd2a8bf088668f1c4898287020 /lib
parenteaa56e53be8d71665a5b9a828db54898b7b36fc8 (diff)
downloadchef-ssd/find-python.tar.gz
Use the same python interpreter as yum when possiblessd/find-python
We rely on a system python installation with the correct python libraries. To improve the chances that the python interpreter we call has the yum libary available, we use the same interpreter as yum uses. Fixes #3143
Diffstat (limited to 'lib')
-rw-r--r--lib/chef/provider/package/yum.rb30
1 files changed, 29 insertions, 1 deletions
diff --git a/lib/chef/provider/package/yum.rb b/lib/chef/provider/package/yum.rb
index 49c6f6beb5..b3d3d72844 100644
--- a/lib/chef/provider/package/yum.rb
+++ b/lib/chef/provider/package/yum.rb
@@ -19,6 +19,7 @@
require 'chef/config'
require 'chef/provider/package'
require 'chef/mixin/shell_out'
+require 'chef/mixin/which'
require 'chef/resource/package'
require 'singleton'
require 'chef/mixin/get_source_from_package'
@@ -647,6 +648,7 @@ class Chef
# Cache for our installed and available packages, pulled in from yum-dump.py
class YumCache
include Chef::Mixin::Command
+ include Chef::Mixin::Which
include Chef::Mixin::ShellOut
include Singleton
@@ -713,7 +715,7 @@ class Chef
status = nil
begin
- status = shell_out!("/usr/bin/python #{helper}#{opts}", :timeout => Chef::Config[:yum_timeout])
+ status = shell_out!("#{python_bin} #{helper}#{opts}", :timeout => Chef::Config[:yum_timeout])
status.stdout.each_line do |line|
one_line = true
@@ -779,6 +781,32 @@ class Chef
@next_refresh = :none
end
+ def python_bin
+ yum_executable = which("yum")
+ if yum_executable && shabang?(yum_executable)
+ extract_interpreter(yum_executable)
+ else
+ Chef::Log.warn("Yum executable not found or doesn't start with #!. Using default python.")
+ "/usr/bin/python"
+ end
+ rescue StandardError => e
+ Chef::Log.warn("An error occured attempting to determine correct python executable. Using default.")
+ Chef::Log.debug(e)
+ "/usr/bin/python"
+ end
+
+ def extract_interpreter(file)
+ ::File.open(file, 'r', &:readline)[2..-1].chomp
+ end
+
+ def shabang?(file)
+ ::File.open(file, 'r') do |f|
+ f.read(2) == '#!'
+ end
+ rescue Errno::ENOENT
+ false
+ end
+
def reload
@next_refresh = :all
end