gem-fast 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ Welcome!
@@ -0,0 +1,24 @@
1
+ require 'rubygems'
2
+ require 'rubygems/user_interaction'
3
+ require "rubygems/remote_fetcher"
4
+ $:.unshift File.dirname(__FILE__)+"/../lib"
5
+
6
+ require 'gem-fast/utils'
7
+ require 'gem-fast/remote_fetcher'
8
+ module GemFast
9
+ RUBYGEMPLUS_CACHE = File.join((File.writable?(Gem.dir) ? Gem.dir : Gem.user_dir), 'cache')
10
+ RUBYGEMPLUS_USER_AGENT = "rubygem-gemfast"
11
+ def self.curl?
12
+ curl_ok = false
13
+ begin
14
+ if `curl --version`.strip.size > 0
15
+ curl_ok = true
16
+ end
17
+ rescue Exception => e
18
+ end
19
+ curl_ok
20
+ end
21
+
22
+ end
23
+
24
+
@@ -0,0 +1,75 @@
1
+ require 'gem-fast/ui'
2
+ module GemFast
3
+ module Command
4
+ class Base
5
+ include GemFast::UI
6
+ attr_accessor :args
7
+
8
+ def initialize(args)
9
+ @args = args
10
+ end
11
+
12
+ def usage
13
+ <<-EOTXT
14
+ === Command List:
15
+ sudo gem-fast patch apply, apply patch to rubygems then you will use curl to download gems
16
+ sudo gem-fast patch revert, revert back to original
17
+
18
+
19
+ EOTXT
20
+ end
21
+
22
+ end
23
+ class InvalidCommand < RuntimeError; end
24
+ class CommandFailed < RuntimeError; end
25
+
26
+ class << self
27
+
28
+ include GemFast::UI
29
+ def run(command, args, retries=0)
30
+ begin
31
+ run_internal(command, args.dup)
32
+ rescue InvalidCommand
33
+ error "Unknown command. Run 'autoweb help' for usage information."
34
+ rescue CommandFailed => e
35
+ error e.message
36
+ rescue Interrupt => e
37
+ error "\n[canceled]"
38
+ end
39
+ end
40
+
41
+ def run_internal(command, args)
42
+ klass, method = parse(command)
43
+ runner = klass.new(args)
44
+ raise InvalidCommand unless runner.respond_to?(method)
45
+ runner.send(method)
46
+ end
47
+
48
+ def parse(command)
49
+ parts = command.split(':')
50
+ case parts.size
51
+ when 1
52
+ begin
53
+ return eval("GemFast::Command::#{command.capitalize}"), :index
54
+ #rescue NameError, NoMethodError
55
+ # return Autoweb::Command::Help, command
56
+ end
57
+ when 2
58
+ begin
59
+ return GemFast::Command.const_get(parts[0].capitalize), parts[1]
60
+ rescue NameError
61
+ raise InvalidCommand
62
+ end
63
+ else
64
+ raise InvalidCommand
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
70
+
71
+ Dir["#{File.dirname(__FILE__)}/../../commands/*.rb"].each { |c|
72
+ unless (/_helper\.rb$/=~c)
73
+ require c
74
+ end
75
+ }
@@ -0,0 +1,141 @@
1
+ module GemFast
2
+ class RemoteFetcher < Gem::RemoteFetcher
3
+
4
+ def download(spec, source_uri, install_dir = Gem.dir)
5
+ return super unless scheme_supported?(source_uri)
6
+ CurlUnsafeDownloadStrategy.new(source_uri + "gems/#{spec.file_name}", spec.file_name).fetch
7
+ end
8
+
9
+ def fetch_path(uri, mtime = nil, head = false)
10
+ return super unless scheme_supported?(uri)
11
+
12
+ path = CurlUnsafeDownloadStrategy.new(uri,nil).fetch
13
+ data = nil
14
+ File.open(path, "rb"){|f|data = f.read}
15
+ data = Gem.gunzip data if data and not head and uri.to_s =~ /gz$/
16
+ data
17
+ end
18
+
19
+ def fetch_size(url)
20
+ puts "fetch size : #{url}"
21
+ super
22
+ end
23
+
24
+ private
25
+ def scheme_supported?(uri)
26
+ uri && uri.to_s.strip =~ %r[^https?://]
27
+ end
28
+
29
+ def ensure_tmp_dir(install_dir)
30
+ gem_file_name = spec.file_name
31
+ local_gem_path = File.join RUBYGEMPLUS_CACHE, gem_file_name
32
+ FileUtils.mkdir_p cache_dir rescue nil unless File.exist? cache_dir
33
+ end
34
+ end
35
+
36
+
37
+ class AbstractDownloadStrategy
38
+ include Util
39
+
40
+ def initialize url, name=nil
41
+ @url=url
42
+ @unique_token="#{name}" unless name.to_s.empty? or name == '__UNKNOWN__'
43
+ end
44
+
45
+ def expand_safe_system_args args
46
+ args.each_with_index do |arg, ii|
47
+ if arg.is_a? Hash
48
+ unless ARGV.verbose?
49
+ args[ii] = arg[:quiet_flag]
50
+ else
51
+ args.delete_at ii
52
+ end
53
+ return args
54
+ end
55
+ end
56
+ # 2 as default because commands are eg. svn up, git pull
57
+ args.insert(2, '-q') unless ARGV.verbose?
58
+ return args
59
+ end
60
+
61
+ def quiet_safe_system *args
62
+ safe_system *expand_safe_system_args(args)
63
+ end
64
+ end
65
+
66
+ class CurlDownloadStrategy <AbstractDownloadStrategy
67
+ attr_reader :tarball_path
68
+
69
+ def initialize url, name
70
+ super
71
+ if @unique_token
72
+ @tarball_path=File.join(RUBYGEMPLUS_CACHE,@unique_token)
73
+ else
74
+ @tarball_path=File.join(RUBYGEMPLUS_CACHE,File.basename(@url.to_s))
75
+ end
76
+ end
77
+
78
+ def cached_location
79
+ @tarball_path
80
+ end
81
+
82
+ # Private method, can be overridden if needed.
83
+ def _fetch
84
+ curl @url, '-o', @tarball_path
85
+ end
86
+
87
+ def fetch
88
+ say "Downloading #{@url}"
89
+ unless File.exist?(@tarball_path)
90
+ begin
91
+ _fetch
92
+ rescue Exception
93
+ # ignore_interrupts { @tarball_path.unlink if @tarball_path.exist? }
94
+ raise
95
+ end
96
+ else
97
+ puts "File already downloaded and cached to #{RUBYGEMPLUS_CACHE}"
98
+ end
99
+ return @tarball_path # thus performs checksum verification
100
+ end
101
+
102
+ private
103
+ def chdir
104
+ entries=Dir['*']
105
+ case entries.length
106
+ when 0 then raise "Empty archive"
107
+ when 1 then Dir.chdir entries.first rescue nil
108
+ end
109
+ end
110
+ end
111
+
112
+ # Download via an HTTP POST.
113
+ # Query parameters on the URL are converted into POST parameters
114
+ class CurlPostDownloadStrategy <CurlDownloadStrategy
115
+ def _fetch
116
+ base_url,data = @url.split('?')
117
+ curl base_url, '-d', data, '-o', @tarball_path
118
+ end
119
+
120
+
121
+ end
122
+
123
+ # Use this strategy to download but not unzip a file.
124
+ # Useful for installing jars.
125
+ class NoUnzipCurlDownloadStrategy <CurlDownloadStrategy
126
+ def stage
127
+ FileUtils.cp @tarball_path, File.basename(@url)
128
+ end
129
+ end
130
+
131
+ # This Download Strategy is provided for use with sites that
132
+ # only provide HTTPS and also have a broken cert.
133
+ # Try not to need this, as we probably won't accept the forulae
134
+ # into trunk.
135
+ class CurlUnsafeDownloadStrategy <CurlDownloadStrategy
136
+ def _fetch
137
+ curl @url, '--insecure', '-o', @tarball_path
138
+ end
139
+ end
140
+
141
+ end
@@ -0,0 +1,73 @@
1
+ module GemFast
2
+ module Util
3
+ include Gem::UserInteraction
4
+
5
+ def curl *args
6
+ begin
7
+ safe_system 'curl', '-f#LA', RUBYGEMPLUS_USER_AGENT, *args unless args.empty?
8
+ rescue ExecutionError => e
9
+ if GemFast.curl?
10
+ raise e
11
+ else
12
+ not_install_curl
13
+ end
14
+ rescue Errno::ENOENT => e
15
+ not_install_curl
16
+ end
17
+
18
+ end
19
+
20
+ def not_install_curl
21
+ alert_error("use: 'gem uninstall gem-fast' to return back, Curl not installed on your mathine!")
22
+ exit(1)
23
+ end
24
+
25
+ def safe_system cmd, *args
26
+ raise ExecutionError.new(cmd, args, $?) unless system(cmd, *args)
27
+ end
28
+
29
+ def system cmd, *args
30
+ yield if block_given?
31
+ args.collect!{|arg| arg.to_s}
32
+ `#{cmd} #{args.join(" ")}`
33
+ $?.success?
34
+ end
35
+
36
+
37
+ class ExecutionError <RuntimeError
38
+ attr :exit_status
39
+ attr :command
40
+
41
+ def initialize cmd, args = [], es = nil
42
+ @command = cmd
43
+ super "Failure while executing: #{cmd} #{pretty(args)*' '}"
44
+ @exit_status = es.exitstatus rescue 1
45
+ end
46
+
47
+ def was_running_configure?
48
+ @command == './configure'
49
+ end
50
+
51
+ private
52
+
53
+ def pretty args
54
+ args.collect do |arg|
55
+ if arg.to_s.include? ' '
56
+ "'#{ arg.gsub "'", "\\'" }'"
57
+ else
58
+ arg
59
+ end
60
+ end
61
+ end
62
+ end
63
+
64
+ class BuildError <ExecutionError
65
+ attr :env
66
+
67
+ def initialize cmd, args = [], es = nil
68
+ super
69
+ @env = ENV.to_hash
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,3 @@
1
+ module GemFast
2
+ VERSION = '0.0.6'
3
+ end
@@ -0,0 +1,10 @@
1
+ require "gem-fast"
2
+
3
+ # see http://help.rubygems.org/discussions/problems/378-gempre_install-does-not-working-as-it-named
4
+ # Gem.pre_install do
5
+ # if !GemFast.curl?
6
+ # raise Gem::InstallError, "You should install curl first! If you already install it , please add it to your $PATH\n\t OR you can run 'gem uninstall gem-fast' to return back."
7
+ # end
8
+ # end
9
+
10
+ Gem::RemoteFetcher.instance_variable_set "@fetcher", GemFast::RemoteFetcher.new(Gem.configuration[:http_proxy])
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gem-fast
3
+ version: !ruby/object:Gem::Version
4
+ hash: 19
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 6
10
+ version: 0.0.6
11
+ platform: ruby
12
+ authors:
13
+ - dazuiba
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-10-28 00:00:00 +08:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: "Gem-fast, make your gem install faster!, Replace gem fetcher with curl "
23
+ email: come2u@gmail.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - README.md
32
+ - lib/gem-fast/command.rb
33
+ - lib/gem-fast/remote_fetcher.rb
34
+ - lib/gem-fast/utils.rb
35
+ - lib/gem-fast/version.rb
36
+ - lib/gem-fast.rb
37
+ - lib/rubygems_plugin.rb
38
+ has_rdoc: true
39
+ homepage: http://github.com/dazuiba/gem-fast.git
40
+ licenses: []
41
+
42
+ post_install_message: |+
43
+
44
+ ========================================================================
45
+
46
+ Thanks for installing Gem-Fast!
47
+ Gem-Fast will use curl to make your gem install faster!
48
+
49
+ Try it now use: gem install rails
50
+
51
+ ========================================================================
52
+
53
+ rdoc_options: []
54
+
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ hash: 59
63
+ segments:
64
+ - 1
65
+ - 8
66
+ - 6
67
+ version: 1.8.6
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ hash: 3
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ requirements: []
78
+
79
+ rubyforge_project:
80
+ rubygems_version: 1.3.7
81
+ signing_key:
82
+ specification_version: 3
83
+ summary: Gem for the rest
84
+ test_files: []
85
+