ruby-changes:35612
From: nobu <ko1@a...>
Date: Tue, 23 Sep 2014 20:56:36 +0900 (JST)
Subject: [ruby-changes:35612] nobu:r47694 (trunk): downloader.rb: shorthands for usual URI
nobu 2014-09-23 20:56:30 +0900 (Tue, 23 Sep 2014) New Revision: 47694 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=47694 Log: downloader.rb: shorthands for usual URI * tool/downloader.rb (Downloader.uri_to_download): add shorthands for commonly used URI. Modified files: trunk/tool/downloader.rb trunk/tool/get-config_files trunk/tool/make-snapshot Index: tool/get-config_files =================================================================== --- tool/get-config_files (revision 47693) +++ tool/get-config_files (revision 47694) @@ -3,8 +3,7 @@ require File.expand_path('../downloader' https://github.com/ruby/ruby/blob/trunk/tool/get-config_files#L3 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 Index: tool/downloader.rb =================================================================== --- tool/downloader.rb (revision 47693) +++ tool/downloader.rb (revision 47694) @@ -1,6 +1,29 @@ https://github.com/ruby/ruby/blob/trunk/tool/downloader.rb#L1 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 https://github.com/ruby/ruby/blob/trunk/tool/downloader.rb#L57 # '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 https://github.com/ruby/ruby/blob/trunk/tool/downloader.rb#L76 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) Index: tool/make-snapshot =================================================================== --- tool/make-snapshot (revision 47693) +++ tool/make-snapshot (revision 47694) @@ -224,8 +224,7 @@ def package(rev, destdir) https://github.com/ruby/ruby/blob/trunk/tool/make-snapshot#L224 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) https://github.com/ruby/ruby/blob/trunk/tool/make-snapshot#L282 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/