Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 103 lines (87 sloc) 2.642 kb
a11d94e5 »
2012-09-13 stickler_extra
1 require 'pathname'
2 require 'yaml'
3 require 'bundler/setup'
4 require 'stickler'
5 require 'rubygems/mirror'
6 require 'rubygems/format'
7
8
9 $top = Pathname.new(__FILE__).dirname.expand_path
10 $data = $top.join('data')
11 $local = $data.join('local')
12 $mirror = $data.join('mirror')
13 $mirrorrc = $data.join('mirrorrc.yml')
14 $upstream = 'http://production.cf.rubygems.org/'
15 $mirror_config = [{'from' => $upstream, 'to' => $mirror.to_s}]
16
17
18 class Gem::Mirror
19 def update_gems
20 gems_to_fetch.each do |g|
21 @pool.job do
22 @fetcher.fetch(from('gems', g), to('gems', g))
23 begin
24 write_specification_for_gem(g, to('gems'), to('specifications'))
25 rescue => e
26 puts e
27 end
28 yield if block_given?
29 end
30 end
31
32 @pool.run_til_done
33 end
34
35 def delete_gems
36 gems_to_delete.each do |g|
37 @pool.job do
38 begin
39 remove_specification_for_gem(g, to('gems'), to('specifications'))
40 rescue => e
41 puts e
42 end
43 File.delete(to('gems', g))
44 yield if block_given?
45 end
46 end
47
48 @pool.run_til_done
49 end
50
51 private
52
53 def remove_specification_for_gem(gem_file, gem_dir, spec_dir)
54 gem_path = File.join(gem_dir, gem_file)
55 spec = specification_from_gem_file(gem_path)
56 spec_path = File.join(spec_dir, spec.spec_name)
57 rm_rf spec_path
58 end
59
60 def write_specification_for_gem(gem_file, gem_dir, spec_dir)
61 gem_path = File.join(gem_dir, gem_file)
62 spec = specification_from_gem_file(gem_path)
63 spec_path = File.join(spec_dir, spec.spec_name)
64 File.open(spec_path, 'w+') {|file| file << spec.to_ruby}
65 end
66
67 def specification_from_gem_file(path)
68 Gem::Format.from_file_by_path(path).spec
69 end
70 end
71
72
73 task :create_paths do
74 [$local, $mirror].each do |type|
75 ['gems', 'specifications'].each do |subdir|
76 mkdir_p type.join(subdir)
77 end
78 end
79 end
80
81 task :configure_mirror => :create_paths do
82 File.open($mirrorrc, 'w+') do |file|
83 file << $mirror_config.to_yaml
84 end unless $mirrorrc.exist?
85 end
86
87 desc 'update local mirror(s) from remote'
88 task :mirror => :configure_mirror do
89 configs = YAML.load_file($mirrorrc)
90 configs.each do |config|
91 mirror = Gem::Mirror.new(config['from'], File.expand_path(config['to']), 15)
92 puts "Fetching: #{mirror.from(Gem::Mirror::SPECS_FILE_Z)}"
93 mirror.update_specs
94 puts "Total gems: #{mirror.gems.size}"
95 num_to_fetch = mirror.gems_to_fetch.size
96 puts "Fetching #{num_to_fetch} gems"
97 mirror.update_gems #{ print '.' }
98 num_to_delete = mirror.gems_to_delete.size
99 puts "Deleting #{num_to_delete} gems"
100 mirror.delete_gems #{ print '.' }
101 end
102 end
Something went wrong with that request. Please try again.