Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Oct 2, 2018. It is now read-only.

allow users to override the python package name to install #58

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions attributes/default.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#
#
# Author:: Seth Chisamore (<[email protected]>)
# Cookbook Name:: python
# Attribute:: default
Expand All @@ -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'
Expand Down
12 changes: 1 addition & 11 deletions recipes/package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions recipes/pip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
5 changes: 3 additions & 2 deletions recipes/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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