tool/downloader.rb: split particular sites

* tool/downloader.rb (Downloader): split particular sites from the
  main class.

* tool/downloader.rb (Downloader.download): show messages if
  verbose mode.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47725 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2014-09-28 02:54:59 +00:00
Родитель ceb32c67a0
Коммит 3bbea8ed37
3 изменённых файлов: 45 добавлений и 39 удалений

Просмотреть файл

@ -1082,19 +1082,20 @@ $(srcdir)/tool/config.sub:
$(Q) $(BASERUBY) -C $(@D) get-config_files $(@F)
update-gems: PHONY
$(Q) $(RUNRUBY) -I$(srcdir)/tool -rdownloader -ans \
$(ECHO) Downloading bundled gem files...
$(Q) $(RUNRUBY) -I$(srcdir)/tool -rdownloader -answ \
-C "$(srcdir)/gems" \
-e 'gem, ver = *$$F' \
-e 'gem = "#{gem}-#{ver}.gem"' \
-e 'puts "updating #{gem}"' \
-e 'Downloader.download(:rubygems, gem, $$gemdir)' \
-- -gemdir=$(srcdir)/gems $(srcdir)/gems/bundled_gems
-e 'Downloader::RubyGems.download(gem)' \
bundled_gems
update-unicode:
$(Q) $(BASERUBY) -I$(srcdir)/tool -rdownloader \
-e 'puts "Downloading Unicode data files..."' \
-e 'Downloader.download(:unicode, "UnicodeData.txt", "$(srcdir)/enc/unicode/data")' \
-e 'Downloader.download(:unicode, "CompositionExclusions.txt", "$(srcdir)/enc/unicode/data")' \
-e 'Downloader.download(:unicode, "NormalizationTest.txt", "$(srcdir)/enc/unicode/data")'
$(ECHO) Downloading Unicode data files...
$(Q) $(BASERUBY) -I$(srcdir)/tool -rdownloader -w \
-C "$(srcdir)/enc/unicode/data" \
-e 'ARGV.each{|f|Downloader::Unicode.download(f)}' \
UnicodeData.txt CompositionExclusions.txt NormalizationTest.txt
info: info-program info-libruby_a info-libruby_so info-arch
info-program:

Просмотреть файл

@ -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"
end
def self.rubygems(name)
"https://rubygems.org/downloads/#{name}"
end
def self.unicode(name)
"http://www.unicode.org/Public/UCD/latest/ucd/#{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 :unicode
url = unicode(url || name)
when Symbol
raise ArgumentError, "unkonwn site - #{from}"
else
url = from
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
class RubyGems < self
def self.download(name, *rest)
super("https://rubygems.org/downloads/#{name}", name, *rest)
end
end
Gems = RubyGems
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

Просмотреть файл

@ -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