summaryrefslogtreecommitdiff
path: root/tool/downloader.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-09-23 11:56:30 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-09-23 11:56:30 +0000
commit0b5227b8bd47211575e8239a2d2763dd3db3a979 (patch)
tree0a566c1fd1131619cba3b228ec201dc196c645b1 /tool/downloader.rb
parentc7cdc549fffc9ef6a2ef77841dc500d6ef2d087d (diff)
downloader.rb: shorthands for usual URI
* tool/downloader.rb (Downloader.uri_to_download): add shorthands for commonly used URI. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47694 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'tool/downloader.rb')
-rw-r--r--tool/downloader.rb27
1 files changed, 25 insertions, 2 deletions
diff --git a/tool/downloader.rb b/tool/downloader.rb
index ba6ddc1..4edbc43 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)