summaryrefslogtreecommitdiff
path: root/tool/downloader.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-09-28 02:54:59 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-09-28 02:54:59 +0000
commit3bbea8ed37278c9cc584bb25624eee05efebb117 (patch)
treeb473eeb7f4a4c8db2038c7759de327bb051a45e8 /tool/downloader.rb
parentceb32c67a09d30b579089fa626cc6a2e0ecdb0a2 (diff)
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
Diffstat (limited to 'tool/downloader.rb')
-rw-r--r--tool/downloader.rb51
1 files changed, 28 insertions, 23 deletions
diff --git a/tool/downloader.rb b/tool/downloader.rb
index 8eb60ac..e909c10 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