diff --git a/attributes/default.rb b/attributes/default.rb index 85c96eb..49cc23c 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -1,4 +1,4 @@ -# + # # Author:: Seth Chisamore () # Cookbook Name:: python # Attribute:: default @@ -18,21 +18,34 @@ # limitations under the License. # +default['python']['binary_name'] = 'python' default['python']['install_method'] = 'package' - +major_version = platform_version.split('.').first.to_i if python['install_method'] == 'package' + default['python']['prefix_dir'] = '/usr' case platform - when "smartos" - default['python']['prefix_dir'] = '/opt/local' - else - default['python']['prefix_dir'] = '/usr' + when "debian" + default['python']['python_pkgs'] = ["python","python-dev"] + when "rhel" + if major_version < 6 + default['python']['binary_name'] = 'python26' + default['python']['python_pkgs'] = ["python26", "python26-devel"] + else + default['python']['python_pkgs'] = ["python","python-devel"] + end + when "freebsd" + default['python']['python_pkgs'] = ["python"] + when "smartos" + default['python']['prefix_dir'] = '/opt/local' + default['python']['python_pkgs'] = ["python27"] + else + default['python']['python_pkgs'] = ["python","python-dev"] end + else default['python']['prefix_dir'] = '/usr/local' end -default['python']['binary'] = "#{node['python']['prefix_dir']}/bin/python" - default['python']['url'] = 'http://www.python.org/ftp/python' default['python']['version'] = '2.7.5' default['python']['checksum'] = '3b477554864e616a041ee4d7cef9849751770bc7c39adaf78a94ea145c488059' diff --git a/recipes/package.rb b/recipes/package.rb index 18c1a00..1b5aa6e 100644 --- a/recipes/package.rb +++ b/recipes/package.rb @@ -24,19 +24,9 @@ # repo & package if platform_family?('rhel') && major_version < 6 include_recipe 'yum::epel' - python_pkgs = ["python26", "python26-devel"] - node.default['python']['binary'] = "/usr/bin/python26" -else - python_pkgs = value_for_platform_family( - "debian" => ["python","python-dev"], - "rhel" => ["python","python-devel"], - "freebsd" => ["python"], - "smartos" => ["python27"], - "default" => ["python","python-dev"] - ) end -python_pkgs.each do |pkg| +node['python']['python_pkgs'].each do |pkg| package pkg do action :install end diff --git a/recipes/pip.rb b/recipes/pip.rb index 1f89070..cef3c6e 100644 --- a/recipes/pip.rb +++ b/recipes/pip.rb @@ -32,11 +32,12 @@ else pip_binary = "/usr/local/bin/pip" end +python_binary = "#{node['python']['prefix_dir']}/bin/#{node['python']['binary_name']}" cookbook_file "#{Chef::Config[:file_cache_path]}/ez_setup.py" do source 'ez_setup.py' mode "0644" - not_if "#{node['python']['binary']} -c 'import setuptools'" + not_if "#{python_binary} -c 'import setuptools'" end cookbook_file "#{Chef::Config[:file_cache_path]}/get-pip.py" do @@ -48,15 +49,15 @@ execute "install-setuptools" do cwd Chef::Config[:file_cache_path] command <<-EOF - #{node['python']['binary']} ez_setup.py + #{python_binary} ez_setup.py EOF - not_if "#{node['python']['binary']} -c 'import setuptools'" + not_if "#{python_binary} -c 'import setuptools'" end execute "install-pip" do cwd Chef::Config[:file_cache_path] command <<-EOF - #{node['python']['binary']} get-pip.py + #{python_binary} get-pip.py EOF not_if { ::File.exists?(pip_binary) } end diff --git a/recipes/source.rb b/recipes/source.rb index 1409ab6..ee24990 100644 --- a/recipes/source.rb +++ b/recipes/source.rb @@ -60,9 +60,10 @@ # Link install as the default python, to support Python 3.x # Otherwise the pip and virtualenv recipes won't work properly -link node['python']['binary'] do +python_binary = "#{node['python']['prefix_dir']}/bin/#{node['python']['binary_name']}" +link python_binary do to install_path - not_if { ::File.exists?(node['python']['binary']) } + not_if { ::File.exists?(python_binary) } end