lib/phantomjs/platform.rb in phantomjs-1.6.0.0 vs lib/phantomjs/platform.rb in phantomjs-1.8.1.0

- old
+ new

@@ -8,15 +8,33 @@ def architecture RbConfig::CONFIG['host_cpu'] end def phantomjs_path - File.expand_path File.join(Phantomjs.base_dir, platform, 'bin/phantomjs') + if system_phantomjs_installed? + system_phantomjs_path + else + File.expand_path File.join(Phantomjs.base_dir, platform, 'bin/phantomjs') + end end + def system_phantomjs_path + `which phantomjs`.delete("\n") + rescue + end + + def system_phantomjs_version + `phantomjs --version`.delete("\n") + rescue + end + + def system_phantomjs_installed? + system_phantomjs_version == Phantomjs.version + end + def installed? - File.exist? phantomjs_path + File.exist?(phantomjs_path) || system_phantomjs_installed? end # TODO: Clean this up, it looks like a pile of... def install! STDERR.puts "Phantomjs does not appear to be installed in #{phantomjs_path}, installing!" @@ -27,12 +45,12 @@ temp_dir = File.join('/tmp', 'phantomjs_install') FileUtils.rm_rf temp_dir FileUtils.mkdir_p temp_dir Dir.chdir temp_dir do - unless system "wget #{package_url}" - raise "Failed to load phantomjs from #{package_url} :(" + unless system "curl -O #{package_url}" or system "wget #{package_url}" + raise "\n\nFailed to load phantomjs! :(\nYou need to have cURL or wget installed on your system.\nIf you have, the source of phantomjs might be unavailable: #{package_url}\n\n" end case package_url.split('.').last when 'bz2' system "bunzip2 #{File.basename(package_url)}" @@ -45,14 +63,18 @@ # Find the phantomjs build we just extracted extracted_dir = Dir['phantomjs*'].find { |path| File.directory?(path) } # Move the extracted phantomjs build to $HOME/.phantomjs/version/platform - FileUtils.mv extracted_dir, File.join(Phantomjs.base_dir, platform) + if FileUtils.mv extracted_dir, File.join(Phantomjs.base_dir, platform) + STDOUT.puts "\nSuccessfully installed phantomjs. Yay!" + end # Clean up remaining files in tmp - FileUtils.rm_rf temp_dir + if FileUtils.rm_rf temp_dir + STDOUT.puts "Removed temporarily downloaded files." + end end raise "Failed to install phantomjs. Sorry :(" unless File.exist?(phantomjs_path) end @@ -70,11 +92,11 @@ def platform 'x86_64-linux' end def package_url - 'http://phantomjs.googlecode.com/files/phantomjs-1.6.0-linux-x86_64-dynamic.tar.bz2' + 'http://phantomjs.googlecode.com/files/phantomjs-1.8.1-linux-x86_64.tar.bz2' end end end class Linux32 < Platform @@ -86,11 +108,11 @@ def platform 'x86_32-linux' end def package_url - 'http://phantomjs.googlecode.com/files/phantomjs-1.6.0-linux-i686-dynamic.tar.bz2' + 'http://phantomjs.googlecode.com/files/phantomjs-1.8.1-linux-i686.tar.bz2' end end end class OsX < Platform @@ -102,10 +124,10 @@ def platform 'darwin' end def package_url - 'http://phantomjs.googlecode.com/files/phantomjs-1.6.0-macosx-static.zip' + 'http://phantomjs.googlecode.com/files/phantomjs-1.8.1-macosx.zip' end end end end end