lib/chef/provider/package/easy_install.rb in chef-0.9.8.rc.0 vs lib/chef/provider/package/easy_install.rb in chef-0.9.8
- old
+ new
@@ -16,26 +16,38 @@
# limitations under the License.
#
require 'chef/provider/package'
require 'chef/mixin/command'
+require 'chef/mixin/shell_out'
require 'chef/resource/package'
+require 'chef/mixin/shell_out'
+
class Chef
class Provider
class Package
class EasyInstall < Chef::Provider::Package
+ include Chef::Mixin::ShellOut
+
def install_check(name)
- command = "python -c \"import sys; print sys.path\""
check = false
- status = popen4(command) do |pid, stdin, stdout, stderr|
- stdout.each do |line|
- if line.include? "#{name}"
- check = true
- end
+
+ begin
+ # first check to see if we can import it
+ output = shell_out!("python -c \"import #{name}\"").stderr
+ unless output.include? "ImportError"
+ check = true
end
+ rescue
+ # then check to see if its on the path
+ output = shell_out!("python -c \"import sys; print sys.path\"").stdout
+ if output.downcase.include? "#{name.downcase}"
+ check = true
+ end
end
+
check
end
def easy_install_binary_path
path = @new_resource.easy_install_binary
@@ -48,21 +60,23 @@
@current_resource.version(nil)
# get the currently installed version if installed
package_version = nil
if install_check(@new_resource.package_name)
- command = "python -c \"import #{@new_resource.package_name}; print #{@new_resource.package_name}.__path__\""
- status = popen4(command) do |pid, stdin, stdout, stderr|
- install_location = stdout.readline
- install_location[/\S\S(.*)\/(.*)-(.*)-py(.*).egg\S/]
+ begin
+ output = shell_out!("python -c \"import #{@new_resource.package_name}; print #{@new_resource.package_name}.__version__\"").stdout
+ package_version = output.strip
+ rescue
+ output = shell_out!("python -c \"import #{@new_resource.package_name}; print #{@new_resource.package_name}.__path__\"").stdout
+ output[/\S\S(.*)\/(.*)-(.*)-py(.*).egg\S/]
package_version = $3
end
end
if package_version == @new_resource.version
Chef::Log.debug("#{@new_resource.package_name} at version #{@new_resource.version}")
- @current_resource.version(@new_resource.version)
+ @current_resource.version(@new_resource.version)
else
Chef::Log.debug("#{@new_resource.package_name} at version #{package_version}")
@current_resource.version(package_version)
end
@@ -71,20 +85,13 @@
def candidate_version
return @candidate_version if @candidate_version
# do a dry run to get the latest version
- command = "#{easy_install_binary_path} -n #{@new_resource.package_name}"
- status = popen4(command) do |pid, stdin, stdout, stderr|
- dry_run_output = ""
- stdout.each do |line|
- dry_run_output << line
- end
- dry_run_output[/(.*)Best match: (.*) (.*)\n/]
- @candidate_version = $3
- @candidate_version
- end
+ result = shell_out!("#{easy_install_binary_path} -n #{@new_resource.package_name}", :returns=>[0,1])
+ @candidate_version = result.stdout[/(.*)Best match: (.*) (.*)$/, 3]
+ @candidate_version
end
def install_package(name, version)
run_command(:command => "#{easy_install_binary_path} \"#{name}==#{version}\"")
end
@@ -102,6 +109,6 @@
end
end
end
end
-end
+end
\ No newline at end of file