[前][次][番号順一覧][スレッド一覧]

ruby-changes:35643

From: nobu <ko1@a...>
Date: Sun, 28 Sep 2014 11:55:14 +0900 (JST)
Subject: [ruby-changes:35643] nobu:r47725 (trunk): tool/downloader.rb: split particular sites

nobu	2014-09-28 11:54:59 +0900 (Sun, 28 Sep 2014)

  New Revision: 47725

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=47725

  Log:
    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.

  Modified files:
    trunk/common.mk
    trunk/tool/downloader.rb
    trunk/tool/make-snapshot
Index: common.mk
===================================================================
--- common.mk	(revision 47724)
+++ common.mk	(revision 47725)
@@ -1082,19 +1082,20 @@ $(srcdir)/tool/config.sub: https://github.com/ruby/ruby/blob/trunk/common.mk#L1082
 	$(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:
Index: tool/downloader.rb
===================================================================
--- tool/downloader.rb	(revision 47724)
+++ tool/downloader.rb	(revision 47725)
@@ -1,33 +1,24 @@ 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"
+  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 https://github.com/ruby/ruby/blob/trunk/tool/downloader.rb#L53
   #   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 https://github.com/ruby/ruby/blob/trunk/tool/downloader.rb#L80
       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
Index: tool/make-snapshot
===================================================================
--- tool/make-snapshot	(revision 47724)
+++ tool/make-snapshot	(revision 47725)
@@ -224,7 +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
-      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) 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(:rubygems, gem_name, "gems")
+          Downloader::RubyGems.download(gem_name, "gems")
         end
       end
     end

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]