mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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:
parent
ceb32c67a0
commit
3bbea8ed37
3 changed files with 45 additions and 39 deletions
19
common.mk
19
common.mk
|
@ -1082,19 +1082,20 @@ $(srcdir)/tool/config.sub:
|
||||||
$(Q) $(BASERUBY) -C $(@D) get-config_files $(@F)
|
$(Q) $(BASERUBY) -C $(@D) get-config_files $(@F)
|
||||||
|
|
||||||
update-gems: PHONY
|
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, ver = *$$F' \
|
||||||
-e 'gem = "#{gem}-#{ver}.gem"' \
|
-e 'gem = "#{gem}-#{ver}.gem"' \
|
||||||
-e 'puts "updating #{gem}"' \
|
-e 'Downloader::RubyGems.download(gem)' \
|
||||||
-e 'Downloader.download(:rubygems, gem, $$gemdir)' \
|
bundled_gems
|
||||||
-- -gemdir=$(srcdir)/gems $(srcdir)/gems/bundled_gems
|
|
||||||
|
|
||||||
update-unicode:
|
update-unicode:
|
||||||
$(Q) $(BASERUBY) -I$(srcdir)/tool -rdownloader \
|
$(ECHO) Downloading Unicode data files...
|
||||||
-e 'puts "Downloading Unicode data files..."' \
|
$(Q) $(BASERUBY) -I$(srcdir)/tool -rdownloader -w \
|
||||||
-e 'Downloader.download(:unicode, "UnicodeData.txt", "$(srcdir)/enc/unicode/data")' \
|
-C "$(srcdir)/enc/unicode/data" \
|
||||||
-e 'Downloader.download(:unicode, "CompositionExclusions.txt", "$(srcdir)/enc/unicode/data")' \
|
-e 'ARGV.each{|f|Downloader::Unicode.download(f)}' \
|
||||||
-e 'Downloader.download(:unicode, "NormalizationTest.txt", "$(srcdir)/enc/unicode/data")'
|
UnicodeData.txt CompositionExclusions.txt NormalizationTest.txt
|
||||||
|
|
||||||
info: info-program info-libruby_a info-libruby_so info-arch
|
info: info-program info-libruby_a info-libruby_so info-arch
|
||||||
info-program:
|
info-program:
|
||||||
|
|
|
@ -1,33 +1,24 @@
|
||||||
require 'open-uri'
|
require 'open-uri'
|
||||||
|
|
||||||
class Downloader
|
class Downloader
|
||||||
def self.gnu(name)
|
class GNU < self
|
||||||
"http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=#{name};hb=HEAD"
|
def self.download(name, *rest)
|
||||||
end
|
super("http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=#{name};hb=HEAD", name, *rest)
|
||||||
|
end
|
||||||
def self.rubygems(name)
|
end
|
||||||
"https://rubygems.org/downloads/#{name}"
|
|
||||||
end
|
class RubyGems < self
|
||||||
|
def self.download(name, *rest)
|
||||||
def self.unicode(name)
|
super("https://rubygems.org/downloads/#{name}", name, *rest)
|
||||||
"http://www.unicode.org/Public/UCD/latest/ucd/#{name}"
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.uri_to_download(url, name)
|
Gems = RubyGems
|
||||||
from, url = url
|
|
||||||
case from
|
class Unicode < self
|
||||||
when :gnu
|
def self.download(name, *rest)
|
||||||
url = gnu(url || name)
|
super("http://www.unicode.org/Public/UCD/latest/ucd/#{name}", name, *rest)
|
||||||
when :rubygems, :gems
|
|
||||||
url = rubygems(url || name)
|
|
||||||
when :unicode
|
|
||||||
url = unicode(url || name)
|
|
||||||
when Symbol
|
|
||||||
raise ArgumentError, "unkonwn site - #{from}"
|
|
||||||
else
|
|
||||||
url = from
|
|
||||||
end
|
end
|
||||||
URI(url)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.mode_for(data)
|
def self.mode_for(data)
|
||||||
|
@ -62,11 +53,21 @@ class Downloader
|
||||||
# download :unicode, 'UnicodeData.txt', 'enc/unicode/data'
|
# download :unicode, 'UnicodeData.txt', 'enc/unicode/data'
|
||||||
def self.download(url, name, dir = nil, ims = true)
|
def self.download(url, name, dir = nil, ims = true)
|
||||||
file = dir ? File.join(dir, name) : name
|
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
|
begin
|
||||||
data = url.read(http_options(file, ims))
|
data = url.read(http_options(file, ims))
|
||||||
rescue OpenURI::HTTPError => http_error
|
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
|
raise
|
||||||
end
|
end
|
||||||
mtime = nil
|
mtime = nil
|
||||||
|
@ -79,6 +80,10 @@ class Downloader
|
||||||
mtime = Time.httpdate(mtime)
|
mtime = Time.httpdate(mtime)
|
||||||
File.utime(mtime, mtime, file)
|
File.utime(mtime, mtime, file)
|
||||||
end
|
end
|
||||||
|
if $VERBOSE
|
||||||
|
$stdout.puts "done"
|
||||||
|
$stdout.flush
|
||||||
|
end
|
||||||
true
|
true
|
||||||
rescue => e
|
rescue => e
|
||||||
raise e.class, "failed to download #{name}\n#{e.message}: #{url}", e.backtrace
|
raise e.class, "failed to download #{name}\n#{e.message}: #{url}", e.backtrace
|
||||||
|
|
|
@ -224,7 +224,7 @@ def package(rev, destdir)
|
||||||
rescue LoadError
|
rescue LoadError
|
||||||
abort "Error!!! Copy 'downloader.rb' from 'tool' directory of the recent ruby repository!"
|
abort "Error!!! Copy 'downloader.rb' from 'tool' directory of the recent ruby repository!"
|
||||||
end
|
end
|
||||||
Downloader.download(:gnu, conf, "tool")
|
Downloader::GNU.download(conf, "tool")
|
||||||
end
|
end
|
||||||
File.open(clean.add("cross.rb"), "w") do |f|
|
File.open(clean.add("cross.rb"), "w") do |f|
|
||||||
f.puts "Object.__send__(:remove_const, :CROSS_COMPILING) if defined?(CROSS_COMPILING)"
|
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|
|
bundled_gems.split("\n").map(&:split).each do |gem, ver|
|
||||||
gem_name = "#{gem}-#{ver}.gem"
|
gem_name = "#{gem}-#{ver}.gem"
|
||||||
unless File.file?("gems/#{gem_name}")
|
unless File.file?("gems/#{gem_name}")
|
||||||
Downloader.download(:rubygems, gem_name, "gems")
|
Downloader::RubyGems.download(gem_name, "gems")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue