Skip to content

Commit 03b5886

Browse files
joewilliamsdanielsdeleo
authored andcommitted
'better' install and version detection
1 parent 132ce42 commit 03b5886

1 file changed

Lines changed: 21 additions & 9 deletions

File tree

chef/lib/chef/provider/package/easy_install.rb

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,18 @@ def install_check(name)
3434

3535
begin
3636
# first check to see if we can import it
37-
output = shell_out!("python -c \"import #{name}\"").stderr
38-
unless output.include? "ImportError"
37+
output = shell_out!("python -c \"import #{name}\"", :returns=>[0,1]).stderr
38+
if output.include? "ImportError"
39+
# then check to see if its on the path
40+
output = shell_out!("python -c \"import sys; print sys.path\"", :returns=>[0,1]).stdout
41+
if output.downcase.include? "#{name.downcase}"
42+
check = true
43+
end
44+
else
3945
check = true
4046
end
4147
rescue
42-
# then check to see if its on the path
43-
output = shell_out!("python -c \"import sys; print sys.path\"").stdout
44-
if output.downcase.include? "#{name.downcase}"
45-
check = true
46-
end
48+
# it's probably not installed
4749
end
4850

4951
check
@@ -66,8 +68,18 @@ def load_current_resource
6668
output = shell_out!("python -c \"import #{@new_resource.package_name}; print #{@new_resource.package_name}.__version__\"").stdout
6769
package_version = output.strip
6870
rescue
69-
output = shell_out!("python -c \"import #{@new_resource.package_name}; print #{@new_resource.package_name}.__path__\"").stdout
70-
output[/\S\S(.*)\/(.*)-(.*)-py(.*).egg\S/]
71+
output = shell_out!("python -c \"import sys; print sys.path\"", :returns=>[0,1]).stdout
72+
73+
output_array = output.gsub(/[\[\]]/,'').split(/\s*,\s*/)
74+
package_path = ""
75+
76+
output_array.each do |entry|
77+
if entry.downcase.include?(@new_resource.package_name)
78+
package_path = entry
79+
end
80+
end
81+
82+
package_path[/\S\S(.*)\/(.*)-(.*)-py(.*).egg\S/]
7183
package_version = $3
7284
end
7385
end

0 commit comments

Comments
 (0)