[Pkg-ruby-extras-maintainers] r686 - tools/gemsd

Daigo Moriwaki daigo-guest at costa.debian.org
Sun Jul 16 12:23:01 UTC 2006


Author: daigo-guest
Date: 2006-07-16 12:23:00 +0000 (Sun, 16 Jul 2006)
New Revision: 686

Modified:
   tools/gemsd/download_gems.rb
Log:
Selects the highest versions

Modified: tools/gemsd/download_gems.rb
===================================================================
--- tools/gemsd/download_gems.rb	2006-07-16 10:23:56 UTC (rev 685)
+++ tools/gemsd/download_gems.rb	2006-07-16 12:23:00 UTC (rev 686)
@@ -18,33 +18,38 @@
 require 'rubygems'
 require 'rubygems/remote_installer'
 require 'fileutils'
+$:.unshift( File.dirname(__FILE__).untaint )
 require "utils"
 
-FileUtils.rm_rf(DIR_DOWNLOAD); safe_mkdir(DIR_DOWNLOAD)
 
 def download_gems(source)
   rsf = Gem::RemoteSourceFetcher.new(source, nil)
   puts "Downloading the index for #{source}..."
   source_index = rsf.source_index
 
-  gems = []
-  source_index.each {|fullname, speck| gems << fullname}
+  gems = {}  # {spec.name => spec}
+  # Selects the highest versions
+  source_index.each do |fullname, spec| 
+    gems[spec.name] ||= spec
+    gems[spec.name] = spec if gems[spec.name].version < spec.version
+  end
 
-  gems.map do |name|
-    puts "Downloading #{name}..."
-    data = rsf.fetch_path("/gems/#{name}.gem")
-    File.open(File.join(DIR_DOWNLOAD, "#{name}.gem"), "w+") {|f| f.write data}
+  gems.each_value do |spec|
+    puts "Downloading #{spec.full_name}..."
+    data = rsf.fetch_path("/gems/#{spec.full_name}.gem")
+    File.open(File.join(DIR_DOWNLOAD, "#{spec.full_name}.gem"), "w+") {|f| f.write data}
   end
 end
 
+###
+# Main
+#
 
-ri = Gem::RemoteInstaller.new({})
-ri.sources.each do |source|
-  download_gems(source)
+if __FILE__ == $0
+  FileUtils.rm_rf(DIR_DOWNLOAD); safe_mkdir(DIR_DOWNLOAD)
+  ri = Gem::RemoteInstaller.new({})
+  ri.sources.each do |source|
+    download_gems(source)
+  end
 end
 
-
-exit 0
-
-#remote_gemspecs = Gem::RemoteInstaller.new({}).search(//)
-#remote_gemspecs = remote_gemspecs.flatten




More information about the pkg-ruby-extras-maintainers mailing list