@@ -39,52 +39,40 @@ def whyrun_supported?
3939install_version = candidate_version
4040end
4141
42- # Set the timeout (units in seconds)
43- timeout = 900
44- if @new_resource . timeout
45- timeout = @new_resource . timeout
46- end
47-
4842if install_version
4943description = "install package#{ @new_resource } version#{ install_version } "
5044converge_by ( description ) do
51- Chef ::Log . info ( "Installing#{ @new_resource } version#{ install_version } " )
52- status = install_package ( @new_resource . package_name , install_version , timeout )
45+ Chef ::Log . info ( "Installing#{ @new_resource } version#{ install_version } " )
46+ status = install_package ( install_version )
47+ if status
48+ @new_resource . updated_by_last_action ( true )
49+ end
5350end
5451end
5552end
5653
5754action :upgrade do
58- # Set the timeout (units in seconds)
59- timeout = 900
60- if @new_resource . timeout
61- timeout = @new_resource . timeout
62- end
63-
6455if @current_resource . version !=candidate_version
6556orig_version = @current_resource . version ||"uninstalled"
6657description = "upgrade#{ @current_resource } version from#{ @current_resource . version } to#{ candidate_version } "
6758converge_by ( description ) do
68- Chef ::Log . info ( "Upgrading#{ @new_resource } version from#{ orig_version } to#{ candidate_version } " )
69- status = upgrade_package ( @new_resource . package_name , candidate_version , timeout )
59+ Chef ::Log . info ( "Upgrading#{ @new_resource } version from#{ orig_version } to#{ candidate_version } " )
60+ status = upgrade_package ( candidate_version )
61+ if status
62+ @new_resource . updated_by_last_action ( true )
63+ end
7064end
7165end
7266end
7367
7468action :remove do
75- # Set the timeout (units in seconds)
76- timeout = 900
77- if @new_resource . timeout
78- timeout = @new_resource . timeout
79- end
80-
8169if removing_package?
8270description = "remove package#{ @new_resource } "
8371converge_by ( description ) do
84- Chef ::Log . info ( "Removing#{ @new_resource } " )
85- remove_package ( @current_resource . package_name , @new_resource . version , timeout )
72+ Chef ::Log . info ( "Removing#{ @new_resource } " )
73+ remove_package ( @new_resource . version )
74+ @new_resource . updated_by_last_action ( true )
8675end
87- else
8876end
8977end
9078
@@ -100,10 +88,6 @@ def removing_package?
10088end
10189end
10290
103- def expand_options ( options )
104- options ?"#{ options } " :""
105- end
106-
10791# these methods are the required overrides of
10892# a provider that extends from Chef::Provider::Package
10993# so refactoring into core Chef should be easy
@@ -124,7 +108,7 @@ def current_installed_version
124108@current_installed_version ||=begin
125109delimeter = /==/
126110
127- version_check_cmd = "#{ pip_cmd ( @new_resource ) } freeze | grep -i '^#{ @new_resource . package_name } =='"
111+ version_check_cmd = "#{ which_pip ( @new_resource ) } freeze | grep -i '^#{ @new_resource . package_name } =='"
128112# incase you upgrade pip with pip!
129113if @new_resource . package_name . eql? ( 'pip' )
130114delimeter = /\s /
@@ -146,23 +130,29 @@ def candidate_version
146130end
147131end
148132
149- def install_package ( name , version , timeout )
150- v = "==#{ version } " unless version . eql? ( 'latest' )
151- shell_out! ( "#{ pip_cmd ( @new_resource ) } install#{ expand_options ( @new_resource . options ) } #{ name } #{ v } " , :timeout => timeout )
133+ def install_package ( version )
134+ pip_cmd ( 'install' , version =='latest' ?'' :"==#{ version } " )
135+ end
136+
137+ def upgrade_package ( version )
138+ @new_resource . options "#{ @new_resource . options } --upgrade"
139+ install_package ( version )
152140end
153141
154- def upgrade_package ( name , version , timeout )
155- v = "== #{ version } " unless version . eql? ( 'latest' )
156- shell_out! ( " #{ pip_cmd ( @new_resource ) } install --upgrade #{ expand_options ( @new_resource . options ) } #{ @new_resource . name } #{ v } " , :timeout => timeout )
142+ def remove_package ( version )
143+ @new_resource . options " #{ @new_resource . options } --yes"
144+ pip_cmd ( 'uninstall' )
157145end
158146
159- def remove_package ( name , version , timeout )
160- shell_out! ( "#{ pip_cmd ( @new_resource ) } uninstall -y#{ expand_options ( @new_resource . options ) } #{ @new_resource . name } " , :timeout => timeout )
147+ def pip_cmd ( subcommand , version = '' )
148+ options = { :timeout => @new_resource . timeout , :user => @new_resource . user , :group => @new_resource . group }
149+ options [ :environment ] = { 'HOME' => ::File . expand_path ( "~#{ @new_resource . user } " ) } if @new_resource . user
150+ shell_out! ( "#{ which_pip ( @new_resource ) } #{ subcommand } #{ @new_resource . options } #{ @new_resource . name } #{ version } " , options )
161151end
162152
163153# TODO remove when provider is moved into Chef core
164154# this allows PythonPip to work with Chef::Resource::Package
165- def pip_cmd ( nr )
155+ def which_pip ( nr )
166156if ( nr . respond_to? ( "virtualenv" ) &&nr . virtualenv )
167157 ::File . join ( nr . virtualenv , '/bin/pip' )
168158elsif "#{ node [ 'python' ] [ 'install_method' ] } " . eql? ( "source" )