diff options
Diffstat (limited to 'tool')
-rw-r--r-- | tool/downloader.rb | 51 | ||||
-rwxr-xr-x | tool/make-snapshot | 4 |
2 files changed, 30 insertions, 25 deletions
diff --git a/tool/downloader.rb b/tool/downloader.rb index 8eb60ac2fc..e909c10e45 100644 --- a/tool/downloader.rb +++ b/tool/downloader.rb @@ -1,33 +1,24 @@ require 'open-uri' class Downloader - def self.gnu(name) - "http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=#{name};hb=HEAD" + class GNU < self + def self.download(name, *rest) + super("http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=#{name};hb=HEAD", name, *rest) + end end - def self.rubygems(name) - "https://rubygems.org/downloads/#{name}" + class RubyGems < self + def self.download(name, *rest) + super("https://rubygems.org/downloads/#{name}", name, *rest) + end end - def self.unicode(name) - "http://www.unicode.org/Public/UCD/latest/ucd/#{name}" - end + Gems = RubyGems - def self.uri_to_download(url, name) - from, url = url - case from - when :gnu - url = gnu(url || name) - when :rubygems, :gems - url = rubygems(url || name) - when :unicode - url = unicode(url || name) - when Symbol - raise ArgumentError, "unkonwn site - #{from}" - else - url = from + class Unicode < self + def self.download(name, *rest) + super("http://www.unicode.org/Public/UCD/latest/ucd/#{name}", name, *rest) end - URI(url) end def self.mode_for(data) @@ -62,11 +53,21 @@ class Downloader # download :unicode, 'UnicodeData.txt', 'enc/unicode/data' def self.download(url, name, dir = nil, ims = true) file = dir ? File.join(dir, name) : name - url = uri_to_download(url, name) + url = URI(url) + if $VERBOSE + $stdout.print "downloading #{name} ... " + $stdout.flush + end begin data = url.read(http_options(file, ims)) rescue OpenURI::HTTPError => http_error - return true if http_error.message =~ /^304 / # 304 Not Modified + if http_error.message =~ /^304 / # 304 Not Modified + if $VERBOSE + $stdout.puts "not modified" + $stdout.flush + end + return true + end raise end mtime = nil @@ -79,6 +80,10 @@ class Downloader mtime = Time.httpdate(mtime) File.utime(mtime, mtime, file) end + if $VERBOSE + $stdout.puts "done" + $stdout.flush + end true rescue => e raise e.class, "failed to download #{name}\n#{e.message}: #{url}", e.backtrace diff --git a/tool/make-snapshot b/tool/make-snapshot index 555870da31..05e075c581 100755 --- a/tool/make-snapshot +++ b/tool/make-snapshot @@ -224,7 +224,7 @@ def package(rev, destdir) rescue LoadError abort "Error!!! Copy 'downloader.rb' from 'tool' directory of the recent ruby repository!" end - Downloader.download(:gnu, conf, "tool") + Downloader::GNU.download(conf, "tool") end File.open(clean.add("cross.rb"), "w") do |f| f.puts "Object.__send__(:remove_const, :CROSS_COMPILING) if defined?(CROSS_COMPILING)" @@ -282,7 +282,7 @@ def package(rev, destdir) bundled_gems.split("\n").map(&:split).each do |gem, ver| gem_name = "#{gem}-#{ver}.gem" unless File.file?("gems/#{gem_name}") - Downloader.download(:rubygems, gem_name, "gems") + Downloader::RubyGems.download(gem_name, "gems") end end end |