diff options
Diffstat (limited to 'tool')
-rw-r--r-- | tool/downloader.rb | 27 | ||||
-rwxr-xr-x | tool/get-config_files | 3 | ||||
-rwxr-xr-x | tool/make-snapshot | 5 |
3 files changed, 28 insertions, 7 deletions
diff --git a/tool/downloader.rb b/tool/downloader.rb index ba6ddc15c5..4edbc430c1 100644 --- a/tool/downloader.rb +++ b/tool/downloader.rb @@ -1,6 +1,29 @@ 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" + end + + def self.rubygems(name) + "https://rubygems.org/downloads/#{name}" + end + + 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 Symbol + raise ArgumentError, "unkonwn site - #{from}" + else + url = from + end + URI(url) + end + def self.mode_for(data) data.start_with?("#!") ? 0755 : 0644 end @@ -34,7 +57,7 @@ class Downloader # 'enc/unicode/data/UnicodeData.txt' def self.download(url, name, dir = nil, ims = true) file = dir ? File.join(dir, name) : name - url = URI(url) + url = uri_to_download(url, name) begin data = url.read(http_options(file, ims)) rescue OpenURI::HTTPError => http_error @@ -53,7 +76,7 @@ class Downloader end true rescue => e - raise "failed to download #{name}\n#{e.message}: #{url}" + raise e.class, "failed to download #{name}\n#{e.message}: #{url}", e.backtrace end def self.download_if_modified_since(url, name, dir = nil) diff --git a/tool/get-config_files b/tool/get-config_files index a3fb6dfaf8..113fee0966 100755 --- a/tool/get-config_files +++ b/tool/get-config_files @@ -3,8 +3,7 @@ require File.expand_path('../downloader', __FILE__) ARGV.each {|n| STDOUT.print "Downloading #{n}..."; STDOUT.flush begin - url = "http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=%s;hb=HEAD" % n - Downloader.download(url, n) + Downloader.download(:gnu, n) STDOUT.puts rescue => e STDOUT.puts diff --git a/tool/make-snapshot b/tool/make-snapshot index 63d67a9052..555870da31 100755 --- a/tool/make-snapshot +++ b/tool/make-snapshot @@ -224,8 +224,7 @@ def package(rev, destdir) rescue LoadError abort "Error!!! Copy 'downloader.rb' from 'tool' directory of the recent ruby repository!" end - url = "http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=%s;hb=HEAD" % conf - Downloader.download(url, conf, "tool") + Downloader.download(:gnu, conf, "tool") end File.open(clean.add("cross.rb"), "w") do |f| f.puts "Object.__send__(:remove_const, :CROSS_COMPILING) if defined?(CROSS_COMPILING)" @@ -283,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("https://rubygems.org/downloads/#{gem_name}", gem_name, "gems") + Downloader.download(:rubygems, gem_name, "gems") end end end |