lib/ruboto/util/setup.rb in ruboto-0.13.0.rc.0 vs lib/ruboto/util/setup.rb in ruboto-0.13.0

- old
+ new

@@ -1,22 +1,23 @@ -require 'pty' require 'ruboto/sdk_versions' +require 'ruboto/util/verify' module Ruboto module Util module Setup + include Ruboto::Util::Verify REPOSITORY_BASE = 'https://dl-ssl.google.com/android/repository' REPOSITORY_URL = "#{REPOSITORY_BASE}/repository-8.xml" ######################################### # # Core Set up Method # def setup_ruboto(accept_all, api_levels = [SdkVersions::DEFAULT_TARGET_SDK]) @platform_sdk_loc = {} - api_levels = [read_project_api_level, *api_levels].compact.uniq + api_levels = [project_api_level, *api_levels].compact.uniq install_all(accept_all, api_levels) unless check_all(api_levels) config_path(accept_all) end # @@ -61,18 +62,10 @@ else "android-sdk-#{android_package_os_id}" end end - def read_project_api_level - begin - return $1 if File.read('project.properties') =~ /target=(.*)/ - rescue - # ignored - end - end - def path_setup_file case RbConfig::CONFIG['host_os'] when /^darwin(.*)/ then '.profile' when /^linux(.*)/ then @@ -427,37 +420,33 @@ unless accept_all print 'Would you like to download and install it? (Y/n): ' a = STDIN.gets.chomp.upcase end if accept_all || a == 'Y' || a.empty? - update_cmd = "android --silent update sdk --no-ui --filter #{api_level},sysimg-#{api_level.slice(/\d+$/)} --all" + update_cmd = "android update sdk --no-ui --filter #{api_level},sysimg-#{api_level.slice(/\d+$/)} --all" update_sdk(update_cmd, accept_all) check_for_android_platform(api_level) end end def update_sdk(update_cmd, accept_all) if accept_all - begin - PTY.spawn(update_cmd) do |stdin, stdout, pid| - begin - output = '' - question_pattern = /.*Do you accept the license '[a-z-]+-[0-9a-f]{8}' \[y\/n\]: /m - STDOUT.sync = true - stdin.each_char do |text| - print text - output << text - if output =~ question_pattern - stdout.puts 'y' - output.sub! question_pattern, '' - end + IO.popen(update_cmd, 'r+') do |cmd_io| + begin + output = '' + question_pattern = /.*Do you accept the license '[a-z-]+-[0-9a-f]{8}' \[y\/n\]: /m + STDOUT.sync = true + cmd_io.each_char do |text| + print text + output << text + if output =~ question_pattern + cmd_io.puts 'y' + output.sub! question_pattern, '' end - rescue Errno::EIO - # This probably just means that the process has finished giving output. end + rescue Errno::EIO + # This probably just means that the process has finished giving output. end - rescue PTY::ChildExited - puts 'The child process exited!' end else system update_cmd end end