Permalink
Browse files

Fetching gems from RubyForge once again

  • Loading branch information...
1 parent c12b86d commit fa69de91bba1f2cc63e024109cfd14f8340aae5a @qrush qrush committed Sep 7, 2009
Showing with 30 additions and 43 deletions.
  1. +1 −1 Rakefile
  2. +2 −0 app/models/dependency.rb
  3. +6 −0 lib/gemcutter.rb
  4. +13 −42 lib/tasks/gemcutter.rake
  5. +8 −0 test/unit/dependency_test.rb
View
@@ -9,4 +9,4 @@ require 'tasks/rails'
desc "Run all tests and features"
task :default => [:test, :features]
-task :cron => ['gemcutter:update']
+task :cron => ['gemcutter:fetch_from_rubyforge']
@@ -9,6 +9,8 @@ class Dependency < ActiveRecord::Base
named_scope :runtime, { :conditions => { :scope => 'runtime' }}
def self.create_from_gem_dependency!(dependency)
+ return unless dependency.respond_to?(:name)
+
rubygem = Rubygem.find_or_create_by_name(dependency.name)
self.create!(
View
@@ -72,6 +72,12 @@ def self.server_path(*more)
File.expand_path(File.join(File.dirname(__FILE__), '..', 'server', *more))
end
+ # Overridden so we don't get megabytes of the raw data printing out
+ def inspect
+ attrs = [:@rubygem, :@user, :@message, :@code].map { |attr| "#{attr}=#{instance_variable_get(attr) || 'nil'}" }
+ "<Gemcutter #{attrs.join(' ')}>"
+ end
+
def self.indexer
indexer = Gem::Indexer.new(Gemcutter.server_path, :build_legacy => false)
def indexer.say(message) end
@@ -235,52 +235,23 @@ namespace :gemcutter do
end
end
- desc 'Get the latest gems from rubyforge and index them here'
- task :update => :environment do
- return unless Rails.env.production?
-
+ task :fetch_from_rubyforge => :environment do
require 'open-uri'
- require 'rubygems/commands/list_command'
-
- ins = StringIO.new
- outs = StringIO.new
- Gem::DefaultUserInteraction.ui = Gem::StreamUI.new(ins, outs)
- Gem.sources = ["http://gems.rubyforge.org"]
-
- command = Gem::Commands::ListCommand.new
- command.options[:domain] = :remote
- command.options[:all] = true
- command.execute
-
- list = outs.string.split("\n")
- downloads = []
- list.each do |line|
- name, *versions = line.gsub(/[\(\),]/, "").split
- puts ">> Updating #{name}..."
-
- rubygem = Rubygem.find_by_name(name)
- if rubygem
- versions.each do |number|
- unless Version.exists?(:rubygem_id => rubygem.id, :number => number)
- downloads << "#{name}-#{number}.gem"
- end
- end
- else
- versions.each do |version|
- downloads << "#{name}-#{version}.gem"
- end
- end
+ rubyforge_gems = Marshal.load(Gem.gunzip(open("http://gems.rubyforge.org/specs.4.8.gz").read))
+ gemcutter_gems = Marshal.load(Gem.gunzip(open("http://gemcutter.org/specs.4.8.gz").read))
+ (rubyforge_gems - gemcutter_gems).each do |index|
+ index.pop if index.last == "ruby"
+ gem_name = "http://gems.rubyforge.org/gems/#{index.join('-')}.gem"
+ puts ">> Fetching #{gem_name}"
- end
-
- downloads.each do |download|
- puts "Downloading #{download}..."
begin
- cutter = Gemcutter.new(nil, StringIO.new(open("http://gems.rubyforge.org/gems/#{download}").read))
- cutter.pull_spec and cutter.find and cutter.build and cutter.save
- rescue Exception => e
- puts e.message
+ cutter = Gemcutter.new(nil, open(gem_name))
+ cutter.pull_spec and cutter.find and cutter.save
+ puts ">> #{cutter.message}"
+ rescue *HTTP_ERRORS => e
+ puts ">> #{e.message}"
end
end
+
end
end
@@ -42,4 +42,12 @@ class DependencyTest < ActiveSupport::TestCase
end
end
end
+
+ context "with a bad gem dependency" do
+ should "not fail" do
+ assert_nothing_raised do
+ Dependency.create_from_gem_dependency!(["ruby-ajp", ">= 0.2.0"])
+ end
+ end
+ end
end

0 comments on commit fa69de9

Please sign in to comment.