rogerdpack-ruby_core_ri 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- data/README +7 -0
- data/bin/ruby_core_ri +23 -0
- data/lib/contrib/progressbar.rb +237 -0
- data/lib/contrib/uri_ext.rb +289 -0
- data/lib/ruby_core_source.rb +104 -0
- metadata +88 -0
data/README
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Retrieves ruby core source files for ri.
|
2
|
+
|
3
|
+
You can use this to install the ri/rdoc documentation for the core classes, if your distribution did not come with them (for example if you run "ri File" and it doesn't output anything).
|
4
|
+
|
5
|
+
To do so:
|
6
|
+
|
7
|
+
$ ruby_core_ri # download source
|
data/bin/ruby_core_ri
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'ruby_core_source'
|
3
|
+
|
4
|
+
myself = Gem.source_index.find_name('ruby_core_ri')
|
5
|
+
myself ||= Gem.source_index.find_name('rogerdpack-ruby_core_ri')
|
6
|
+
throw 'uninstall old gem versions first' if myself.length > 1
|
7
|
+
myself = myself[0]
|
8
|
+
|
9
|
+
# put it in a generic dir, until I can figure out how to get gem rdoc to accept it from elsewhere
|
10
|
+
to_dir = myself.full_gem_path + "/lib/downloaded_full_source"
|
11
|
+
puts "installing full source (for rdoc/ri purposes) to #{to_dir}"
|
12
|
+
Ruby_core_source.download_headers nil, to_dir, false
|
13
|
+
|
14
|
+
# I suppose we could run this next command ourselves...
|
15
|
+
# but having them run it helps the user understand what is going on.
|
16
|
+
puts "Installed. now run:
|
17
|
+
$ gem rdoc --rdoc --ri rogerdpack-ruby_core_ri
|
18
|
+
|
19
|
+
or, slightly safer (no rdoc)
|
20
|
+
|
21
|
+
$ gem rdoc --no-rdoc --ri rogerdpack-ruby_core_ri
|
22
|
+
it might break half way through on 1.9--possibly a bug in rdoc itself.
|
23
|
+
"
|
@@ -0,0 +1,237 @@
|
|
1
|
+
# = progressbar.rb
|
2
|
+
#
|
3
|
+
# == Copyright (C) 2001 Satoru Takabayashi
|
4
|
+
#
|
5
|
+
# Ruby License
|
6
|
+
#
|
7
|
+
# This module is free software. You may use, modify, and/or redistribute this
|
8
|
+
# software under the same terms as Ruby.
|
9
|
+
#
|
10
|
+
# This program is distributed in the hope that it will be useful, but WITHOUT
|
11
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
12
|
+
# FOR A PARTICULAR PURPOSE.
|
13
|
+
#
|
14
|
+
# == Author(s)
|
15
|
+
#
|
16
|
+
# * Satoru Takabayashi
|
17
|
+
|
18
|
+
# Author:: Satoru Takabayashi
|
19
|
+
# Copyright:: Copyright (c) 2001 Satoru Takabayashi
|
20
|
+
# License:: Ruby License
|
21
|
+
|
22
|
+
# = Console Progress Bar
|
23
|
+
#
|
24
|
+
# Console::ProgressBar is a terminal-based progress bar library.
|
25
|
+
#
|
26
|
+
# == Usage
|
27
|
+
#
|
28
|
+
# pbar = ConsoleProgressBar.new( "Demo", 100 )
|
29
|
+
# 100.times { pbar.inc }
|
30
|
+
# pbar.finish
|
31
|
+
#
|
32
|
+
|
33
|
+
module Console; end
|
34
|
+
|
35
|
+
class Console::ProgressBar
|
36
|
+
|
37
|
+
def initialize(title, total, out = STDERR)
|
38
|
+
@title = title
|
39
|
+
@total = total
|
40
|
+
@out = out
|
41
|
+
@bar_length = 80
|
42
|
+
@bar_mark = "o"
|
43
|
+
@total_overflow = true
|
44
|
+
@current = 0
|
45
|
+
@previous = 0
|
46
|
+
@is_finished = false
|
47
|
+
@start_time = Time.now
|
48
|
+
@format = "%-14s %3d%% %s %s"
|
49
|
+
@format_arguments = [:title, :percentage, :bar, :stat]
|
50
|
+
show_progress
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
def convert_bytes (bytes)
|
55
|
+
if bytes < 1024
|
56
|
+
sprintf("%6dB", bytes)
|
57
|
+
elsif bytes < 1024 * 1000 # 1000kb
|
58
|
+
sprintf("%5.1fKB", bytes.to_f / 1024)
|
59
|
+
elsif bytes < 1024 * 1024 * 1000 # 1000mb
|
60
|
+
sprintf("%5.1fMB", bytes.to_f / 1024 / 1024)
|
61
|
+
else
|
62
|
+
sprintf("%5.1fGB", bytes.to_f / 1024 / 1024 / 1024)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def transfer_rate
|
67
|
+
bytes_per_second = @current.to_f / (Time.now - @start_time)
|
68
|
+
sprintf("%s/s", convert_bytes(bytes_per_second))
|
69
|
+
end
|
70
|
+
|
71
|
+
def bytes
|
72
|
+
convert_bytes(@current)
|
73
|
+
end
|
74
|
+
|
75
|
+
def format_time (t)
|
76
|
+
t = t.to_i
|
77
|
+
sec = t % 60
|
78
|
+
min = (t / 60) % 60
|
79
|
+
hour = t / 3600
|
80
|
+
sprintf("%02d:%02d:%02d", hour, min, sec);
|
81
|
+
end
|
82
|
+
|
83
|
+
# ETA stands for Estimated Time of Arrival.
|
84
|
+
def eta
|
85
|
+
if @current == 0
|
86
|
+
"ETA: --:--:--"
|
87
|
+
else
|
88
|
+
elapsed = Time.now - @start_time
|
89
|
+
eta = elapsed * @total / @current - elapsed;
|
90
|
+
sprintf("ETA: %s", format_time(eta))
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def elapsed
|
95
|
+
elapsed = Time.now - @start_time
|
96
|
+
sprintf("Time: %s", format_time(elapsed))
|
97
|
+
end
|
98
|
+
|
99
|
+
def stat
|
100
|
+
if @is_finished then elapsed else eta end
|
101
|
+
end
|
102
|
+
|
103
|
+
def stat_for_file_transfer
|
104
|
+
if @is_finished then
|
105
|
+
sprintf("%s %s %s", bytes, transfer_rate, elapsed)
|
106
|
+
else
|
107
|
+
sprintf("%s %s %s", bytes, transfer_rate, eta)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def eol
|
112
|
+
if @is_finished then "\n" else "\r" end
|
113
|
+
end
|
114
|
+
|
115
|
+
def bar
|
116
|
+
len = percentage * @bar_length / 100
|
117
|
+
sprintf("|%s%s|", @bar_mark * len, " " * (@bar_length - len))
|
118
|
+
end
|
119
|
+
|
120
|
+
def percentage
|
121
|
+
if @total.zero?
|
122
|
+
100
|
123
|
+
else
|
124
|
+
@current * 100 / @total
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def title
|
129
|
+
@title[0,13] + ":"
|
130
|
+
end
|
131
|
+
|
132
|
+
def get_width
|
133
|
+
# FIXME: I don't know how portable it is.
|
134
|
+
default_width = 80
|
135
|
+
begin
|
136
|
+
tiocgwinsz = 0x5413
|
137
|
+
data = [0, 0, 0, 0].pack("SSSS")
|
138
|
+
if @out.ioctl(tiocgwinsz, data) >= 0 then
|
139
|
+
rows, cols, xpixels, ypixels = data.unpack("SSSS")
|
140
|
+
if cols >= 0 then cols else default_width end
|
141
|
+
else
|
142
|
+
default_width
|
143
|
+
end
|
144
|
+
rescue Exception
|
145
|
+
default_width
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
def show
|
150
|
+
arguments = @format_arguments.map {|method| send(method) }
|
151
|
+
line = sprintf(@format, *arguments)
|
152
|
+
|
153
|
+
width = get_width
|
154
|
+
if line.length == width - 1
|
155
|
+
@out.print(line + eol)
|
156
|
+
elsif line.length >= width
|
157
|
+
@bar_length = [@bar_length - (line.length - width + 1), 0].max
|
158
|
+
if @bar_length == 0 then @out.print(line + eol) else show end
|
159
|
+
else #line.length < width - 1
|
160
|
+
@bar_length += width - line.length + 1
|
161
|
+
show
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
def show_progress
|
166
|
+
if @total.zero?
|
167
|
+
cur_percentage = 100
|
168
|
+
prev_percentage = 0
|
169
|
+
else
|
170
|
+
cur_percentage = (@current * 100 / @total).to_i
|
171
|
+
prev_percentage = (@previous * 100 / @total).to_i
|
172
|
+
end
|
173
|
+
|
174
|
+
if cur_percentage > prev_percentage || @is_finished
|
175
|
+
show
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
public
|
180
|
+
def file_transfer_mode
|
181
|
+
@format_arguments = [:title, :percentage, :bar, :stat_for_file_transfer]
|
182
|
+
end
|
183
|
+
|
184
|
+
def bar_mark= (mark)
|
185
|
+
@bar_mark = String(mark)[0..0]
|
186
|
+
end
|
187
|
+
|
188
|
+
def total_overflow= (boolv)
|
189
|
+
@total_overflow = boolv ? true : false
|
190
|
+
end
|
191
|
+
|
192
|
+
def format= (format)
|
193
|
+
@format = format
|
194
|
+
end
|
195
|
+
|
196
|
+
def format_arguments= (arguments)
|
197
|
+
@format_arguments = arguments
|
198
|
+
end
|
199
|
+
|
200
|
+
def finish
|
201
|
+
@current = @total
|
202
|
+
@is_finished = true
|
203
|
+
show_progress
|
204
|
+
end
|
205
|
+
|
206
|
+
def halt
|
207
|
+
@is_finished = true
|
208
|
+
show_progress
|
209
|
+
end
|
210
|
+
|
211
|
+
def set (count)
|
212
|
+
if count < 0
|
213
|
+
raise "invalid count less than zero: #{count}"
|
214
|
+
elsif count > @total
|
215
|
+
if @total_overflow
|
216
|
+
@total = count + 1
|
217
|
+
else
|
218
|
+
raise "invalid count greater than total: #{count}"
|
219
|
+
end
|
220
|
+
end
|
221
|
+
@current = count
|
222
|
+
show_progress
|
223
|
+
@previous = @current
|
224
|
+
end
|
225
|
+
|
226
|
+
def inc (step = 1)
|
227
|
+
@current += step
|
228
|
+
@current = @total if @current > @total
|
229
|
+
show_progress
|
230
|
+
@previous = @current
|
231
|
+
end
|
232
|
+
|
233
|
+
def inspect
|
234
|
+
"(ProgressBar: #{@current}/#{@total})"
|
235
|
+
end
|
236
|
+
|
237
|
+
end
|
@@ -0,0 +1,289 @@
|
|
1
|
+
#
|
2
|
+
# I've striped down dependencies on Net::SSH and Facets to
|
3
|
+
# stay as simple as possible.
|
4
|
+
#
|
5
|
+
# Original code from Assaf Arkin, released under Apache License
|
6
|
+
# (http://buildr.rubyforge.org/license.html)
|
7
|
+
#
|
8
|
+
require 'cgi'
|
9
|
+
require 'uri'
|
10
|
+
require 'net/http'
|
11
|
+
require 'net/https'
|
12
|
+
require 'tempfile'
|
13
|
+
require 'fileutils'
|
14
|
+
|
15
|
+
# show progress of download
|
16
|
+
require File.join(File.dirname(__FILE__), 'progressbar')
|
17
|
+
|
18
|
+
# Not quite open-uri, but similar. Provides read and write methods for the resource represented by the URI.
|
19
|
+
# Currently supports reads for URI::HTTP and writes for URI::SFTP. Also provides convenience methods for
|
20
|
+
# downloads and uploads.
|
21
|
+
module URI
|
22
|
+
# Raised when trying to read/download a resource that doesn't exist.
|
23
|
+
class NotFoundError < RuntimeError; end
|
24
|
+
|
25
|
+
class << self
|
26
|
+
# :call-seq:
|
27
|
+
# read(uri, options?) => content
|
28
|
+
# read(uri, options?) { |chunk| ... }
|
29
|
+
#
|
30
|
+
# Reads from the resource behind this URI. The first form returns the content of the resource,
|
31
|
+
# the second form yields to the block with each chunk of content (usually more than one).
|
32
|
+
#
|
33
|
+
# For example:
|
34
|
+
# File.open "image.jpg", "w" do |file|
|
35
|
+
# URI.read("http://example.com/image.jpg") { |chunk| file.write chunk }
|
36
|
+
# end
|
37
|
+
# Shorter version:
|
38
|
+
# File.open("image.jpg", "w") { |file| file.write URI.read("http://example.com/image.jpg") }
|
39
|
+
#
|
40
|
+
# Supported options:
|
41
|
+
# * :modified -- Only download if file modified since this timestamp. Returns nil if not modified.
|
42
|
+
# * :progress -- Show the progress bar while reading.
|
43
|
+
def read(uri, options = nil, &block)
|
44
|
+
uri = URI.parse(uri.to_s) unless URI === uri
|
45
|
+
uri.read(options, &block)
|
46
|
+
end
|
47
|
+
|
48
|
+
# :call-seq:
|
49
|
+
# download(uri, target, options?)
|
50
|
+
#
|
51
|
+
# Downloads the resource to the target.
|
52
|
+
#
|
53
|
+
# The target may be a file name (string or task), in which case the file is created from the resource.
|
54
|
+
# The target may also be any object that responds to +write+, e.g. File, StringIO, Pipe.
|
55
|
+
#
|
56
|
+
# Use the progress bar when running in verbose mode.
|
57
|
+
def download(uri, target, options = nil)
|
58
|
+
uri = URI.parse(uri.to_s) unless URI === uri
|
59
|
+
uri.download(target, options)
|
60
|
+
end
|
61
|
+
|
62
|
+
# :call-seq:
|
63
|
+
# write(uri, content, options?)
|
64
|
+
# write(uri, options?) { |bytes| .. }
|
65
|
+
#
|
66
|
+
# Writes to the resource behind the URI. The first form writes the content from a string or an object
|
67
|
+
# that responds to +read+ and optionally +size+. The second form writes the content by yielding to the
|
68
|
+
# block. Each yield should return up to the specified number of bytes, the last yield returns nil.
|
69
|
+
#
|
70
|
+
# For example:
|
71
|
+
# File.open "killer-app.jar", "rb" do |file|
|
72
|
+
# write("sftp://localhost/jars/killer-app.jar") { |chunk| file.read(chunk) }
|
73
|
+
# end
|
74
|
+
# Or:
|
75
|
+
# write "sftp://localhost/jars/killer-app.jar", File.read("killer-app.jar")
|
76
|
+
#
|
77
|
+
# Supported options:
|
78
|
+
# * :progress -- Show the progress bar while reading.
|
79
|
+
def write(uri, *args, &block)
|
80
|
+
uri = URI.parse(uri.to_s) unless URI === uri
|
81
|
+
uri.write(*args, &block)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
class Generic
|
86
|
+
|
87
|
+
# :call-seq:
|
88
|
+
# read(options?) => content
|
89
|
+
# read(options?) { |chunk| ... }
|
90
|
+
#
|
91
|
+
# Reads from the resource behind this URI. The first form returns the content of the resource,
|
92
|
+
# the second form yields to the block with each chunk of content (usually more than one).
|
93
|
+
#
|
94
|
+
# For options, see URI::read.
|
95
|
+
def read(options = nil, &block)
|
96
|
+
fail "This protocol doesn't support reading (yet, how about helping by implementing it?)"
|
97
|
+
end
|
98
|
+
|
99
|
+
# :call-seq:
|
100
|
+
# download(target, options?)
|
101
|
+
#
|
102
|
+
# Downloads the resource to the target.
|
103
|
+
#
|
104
|
+
# The target may be a file name (string or task), in which case the file is created from the resource.
|
105
|
+
# The target may also be any object that responds to +write+, e.g. File, StringIO, Pipe.
|
106
|
+
#
|
107
|
+
# Use the progress bar when running in verbose mode.
|
108
|
+
def download(target, options = {})
|
109
|
+
case target
|
110
|
+
when String
|
111
|
+
# If download breaks we end up with a partial file which is
|
112
|
+
# worse than not having a file at all, so download to temporary
|
113
|
+
# file and then move over.
|
114
|
+
modified = File.stat(target).mtime if File.exist?(target)
|
115
|
+
temp = nil
|
116
|
+
Tempfile.open(File.basename(target)) do |tf|
|
117
|
+
tf.binmode
|
118
|
+
read(options.merge(:modified => modified)) { |chunk| tf.write chunk }
|
119
|
+
temp = tf
|
120
|
+
end
|
121
|
+
FileUtils.mkpath(File.dirname(target))
|
122
|
+
FileUtils.move(temp.path, target)
|
123
|
+
when File
|
124
|
+
read(options.merge(:modified => target.mtime)) { |chunk| target.write chunk }
|
125
|
+
target.flush
|
126
|
+
else
|
127
|
+
raise ArgumentError, "Expecting a target that is either a file name (string, task) or object that responds to write (file, pipe)." unless target.respond_to?(:write)
|
128
|
+
read(options) { |chunk| target.write chunk }
|
129
|
+
target.flush
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
# :call-seq:
|
134
|
+
# write(content, options?)
|
135
|
+
# write(options?) { |bytes| .. }
|
136
|
+
#
|
137
|
+
# Writes to the resource behind the URI. The first form writes the content from a string or an object
|
138
|
+
# that responds to +read+ and optionally +size+. The second form writes the content by yielding to the
|
139
|
+
# block. Each yield should return up to the specified number of bytes, the last yield returns nil.
|
140
|
+
#
|
141
|
+
# For options, see URI::write.
|
142
|
+
def write(*args, &block)
|
143
|
+
options = args.pop if Hash === args.last
|
144
|
+
options ||= {}
|
145
|
+
if String === args.first
|
146
|
+
ios = StringIO.new(args.first, "r")
|
147
|
+
write(options.merge(:size => args.first.size)) { |bytes| ios.read(bytes) }
|
148
|
+
elsif args.first.respond_to?(:read)
|
149
|
+
size = args.first.size rescue nil
|
150
|
+
write({ :size => size }.merge(options)) { |bytes| args.first.read(bytes) }
|
151
|
+
elsif args.empty? && block
|
152
|
+
write_internal(options, &block)
|
153
|
+
else
|
154
|
+
raise ArgumentError, "Either give me the content, or pass me a block, otherwise what would I upload?"
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
protected
|
159
|
+
|
160
|
+
# :call-seq:
|
161
|
+
# with_progress_bar(enable, file_name, size) { |progress| ... }
|
162
|
+
#
|
163
|
+
# Displays a progress bar while executing the block. The first argument must be true for the
|
164
|
+
# progress bar to show (TTY output also required), as a convenient for selectively using the
|
165
|
+
# progress bar from a single block.
|
166
|
+
#
|
167
|
+
# The second argument provides a filename to display, the third its size in bytes.
|
168
|
+
#
|
169
|
+
# The block is yielded with a progress object that implements a single method.
|
170
|
+
# Call << for each block of bytes down/uploaded.
|
171
|
+
def with_progress_bar(enable, file_name, size) #:nodoc:
|
172
|
+
if enable && $stdout.isatty
|
173
|
+
progress_bar = Console::ProgressBar.new(file_name, size)
|
174
|
+
# Extend the progress bar so we can display count/total.
|
175
|
+
class << progress_bar
|
176
|
+
def total()
|
177
|
+
convert_bytes(@total)
|
178
|
+
end
|
179
|
+
end
|
180
|
+
# Squeeze the filename into 30 characters.
|
181
|
+
if file_name.size > 30
|
182
|
+
base, ext = File.basename(file_name), File.extname(file_name)
|
183
|
+
truncated = "#{base[0..26-ext.to_s.size]}..#{ext}"
|
184
|
+
else
|
185
|
+
truncated = file_name
|
186
|
+
end
|
187
|
+
progress_bar.format = "#{CGI.unescape(truncated)}: %3d%% %s %s/%s %s"
|
188
|
+
progress_bar.format_arguments = [:percentage, :bar, :bytes, :total, :stat]
|
189
|
+
progress_bar.bar_mark = "o"
|
190
|
+
|
191
|
+
begin
|
192
|
+
class << progress_bar
|
193
|
+
def <<(bytes)
|
194
|
+
inc bytes.respond_to?(:size) ? bytes.size : bytes
|
195
|
+
end
|
196
|
+
end
|
197
|
+
yield progress_bar
|
198
|
+
ensure
|
199
|
+
progress_bar.finish
|
200
|
+
end
|
201
|
+
else
|
202
|
+
progress_bar = Object.new
|
203
|
+
class << progress_bar
|
204
|
+
def <<(bytes)
|
205
|
+
end
|
206
|
+
end
|
207
|
+
yield progress_bar
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
# :call-seq:
|
212
|
+
# proxy_uri() => URI?
|
213
|
+
#
|
214
|
+
# Returns the proxy server to use. Obtains the proxy from the relevant environment variable (e.g. HTTP_PROXY).
|
215
|
+
# Supports exclusions based on host name and port number from environment variable NO_PROXY.
|
216
|
+
def proxy_uri()
|
217
|
+
proxy = ENV["#{scheme.upcase}_PROXY"]
|
218
|
+
proxy = URI.parse(proxy) if String === proxy
|
219
|
+
excludes = (ENV["NO_PROXY"] || "").split(/\s*,\s*/).compact
|
220
|
+
excludes = excludes.map { |exclude| exclude =~ /:\d+$/ ? exclude : "#{exclude}:*" }
|
221
|
+
return proxy unless excludes.any? { |exclude| File.fnmatch(exclude, "#{host}:#{port}") }
|
222
|
+
end
|
223
|
+
|
224
|
+
def write_internal(options, &block) #:nodoc:
|
225
|
+
fail "This protocol doesn't support writing (yet, how about helping by implementing it?)"
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
class HTTP #:nodoc:
|
230
|
+
|
231
|
+
# See URI::Generic#read
|
232
|
+
def read(options = nil, &block)
|
233
|
+
options ||= {}
|
234
|
+
connect do |http|
|
235
|
+
puts "Requesting #{self}" #if verbose
|
236
|
+
headers = { 'If-Modified-Since' => CGI.rfc1123_date(options[:modified].utc) } if options[:modified]
|
237
|
+
request = Net::HTTP::Get.new(request_uri.empty? ? '/' : request_uri, headers)
|
238
|
+
request.basic_auth self.user, self.password if self.user
|
239
|
+
http.request request do |response|
|
240
|
+
case response
|
241
|
+
when Net::HTTPNotModified
|
242
|
+
# No modification, nothing to do.
|
243
|
+
puts 'Not modified since last download' #if verbose
|
244
|
+
return nil
|
245
|
+
when Net::HTTPRedirection
|
246
|
+
# Try to download from the new URI, handle relative redirects.
|
247
|
+
puts "Redirected to #{response['Location']}" #if verbose
|
248
|
+
return (self + URI.parse(response['location'])).read(options, &block)
|
249
|
+
when Net::HTTPOK
|
250
|
+
puts "Downloading #{self}" #if verbose
|
251
|
+
result = nil
|
252
|
+
with_progress_bar options[:progress], path.split('/').last, response.content_length do |progress|
|
253
|
+
if block
|
254
|
+
response.read_body do |chunk|
|
255
|
+
block.call chunk
|
256
|
+
progress << chunk
|
257
|
+
end
|
258
|
+
else
|
259
|
+
result = ''
|
260
|
+
response.read_body do |chunk|
|
261
|
+
result << chunk
|
262
|
+
progress << chunk
|
263
|
+
end
|
264
|
+
end
|
265
|
+
end
|
266
|
+
return result
|
267
|
+
when Net::HTTPNotFound
|
268
|
+
raise NotFoundError, "Looking for #{self} and all I got was a 404!"
|
269
|
+
else
|
270
|
+
raise RuntimeError, "Failed to download #{self}: #{response.message}"
|
271
|
+
end
|
272
|
+
end
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
276
|
+
private
|
277
|
+
|
278
|
+
def connect
|
279
|
+
if proxy = proxy_uri
|
280
|
+
proxy = URI.parse(proxy) if String === proxy
|
281
|
+
http = Net::HTTP.new(host, port, proxy.host, proxy.port, proxy.user, proxy.password)
|
282
|
+
else
|
283
|
+
http = Net::HTTP.new(host, port)
|
284
|
+
end
|
285
|
+
http.use_ssl = true if self.instance_of? URI::HTTPS
|
286
|
+
yield http
|
287
|
+
end
|
288
|
+
end
|
289
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'rbconfig'
|
2
|
+
require 'tempfile'
|
3
|
+
require 'tmpdir'
|
4
|
+
require 'yaml'
|
5
|
+
require File.join(File.dirname(__FILE__), 'contrib', 'uri_ext')
|
6
|
+
require 'archive/tar/minitar'
|
7
|
+
require 'zlib'
|
8
|
+
require 'fileutils'
|
9
|
+
require 'backports' # Dir.mktmpdir
|
10
|
+
|
11
|
+
module Ruby_core_source
|
12
|
+
|
13
|
+
# params
|
14
|
+
# hdrs: proc
|
15
|
+
# ex: proc { have_header("vm_core.h") and have_header("iseq.h") }
|
16
|
+
# name: string (config name for makefile)
|
17
|
+
#
|
18
|
+
def create_makefile_with_core(hdrs, name)
|
19
|
+
#
|
20
|
+
# First, see if the needed headers already exist somewhere
|
21
|
+
#
|
22
|
+
if hdrs.call
|
23
|
+
create_makefile(name)
|
24
|
+
return true
|
25
|
+
end
|
26
|
+
|
27
|
+
dest_dir = download_headers hdrs
|
28
|
+
|
29
|
+
with_cppflags("-I" + dest_dir) {
|
30
|
+
if hdrs.call
|
31
|
+
create_makefile(name)
|
32
|
+
return true
|
33
|
+
end
|
34
|
+
}
|
35
|
+
return false
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
#
|
40
|
+
# returns the location of headers downloaded and extracted from source
|
41
|
+
# you can pass it a specific dest_dir if you don't want it at the default location
|
42
|
+
# and can specify just_headers = false
|
43
|
+
# if you want all the source files to be downloaded there, not just *.{h, inc}
|
44
|
+
#
|
45
|
+
def download_headers hdrs, dest_dir = nil, just_headers = true, existing_pre_unpacked_dir = nil
|
46
|
+
|
47
|
+
ruby_dir = ""
|
48
|
+
if RUBY_PATCHLEVEL < 0
|
49
|
+
Tempfile.open("preview-revision") { |temp|
|
50
|
+
uri = URI.parse("http://cloud.github.com/downloads/mark-moseley/ruby_core_source/preview_revision.yml")
|
51
|
+
uri.download(temp)
|
52
|
+
revision_map = YAML::load(File.open(temp.path))
|
53
|
+
ruby_dir = revision_map[RUBY_REVISION]
|
54
|
+
return false if ruby_dir.nil?
|
55
|
+
}
|
56
|
+
else
|
57
|
+
ruby_dir = "ruby-" + RUBY_VERSION.to_s + "-p" + RUBY_PATCHLEVEL.to_s
|
58
|
+
end
|
59
|
+
|
60
|
+
#
|
61
|
+
# Check if core headers were already downloaded; if so, use them
|
62
|
+
#
|
63
|
+
dest_dir ||= Config::CONFIG["rubyhdrdir"] + "/" + ruby_dir
|
64
|
+
with_cppflags("-I" + dest_dir) {
|
65
|
+
if hdrs.call
|
66
|
+
return dest_dir
|
67
|
+
end
|
68
|
+
} if hdrs
|
69
|
+
|
70
|
+
#
|
71
|
+
# Download the source headers
|
72
|
+
#
|
73
|
+
uri_path = "http://ftp.ruby-lang.org/pub/ruby/" + RUBY_VERSION[0..2] + "/" + ruby_dir + ".tar.gz"
|
74
|
+
Tempfile.open("ruby-src") { |temp|
|
75
|
+
temp.binmode
|
76
|
+
uri = URI.parse(uri_path)
|
77
|
+
unless existing_pre_unpacked_dir
|
78
|
+
uri.download(temp)
|
79
|
+
tgz = Zlib::GzipReader.new(File.open(temp.path, 'rb'))
|
80
|
+
end
|
81
|
+
|
82
|
+
FileUtils.mkdir_p(dest_dir)
|
83
|
+
require File.dirname(__FILE__) + "/dir_mktmpdir" unless Dir.respond_to? :mktmpdir
|
84
|
+
Dir.mktmpdir { |dir|
|
85
|
+
dir = existing_pre_unpacked_dir if existing_pre_unpacked_dir
|
86
|
+
Archive::Tar::Minitar.unpack(tgz, dir) unless existing_pre_unpacked_dir
|
87
|
+
if just_headers
|
88
|
+
inc_dir = dir + "/" + ruby_dir + "/*.inc"
|
89
|
+
hdr_dir = dir + "/" + ruby_dir + "/*.h"
|
90
|
+
glob = [inc_dir, hdr_dir]
|
91
|
+
FileUtils.cp(Dir.glob(glob), dest_dir)
|
92
|
+
else
|
93
|
+
FileUtils.cp_r(Dir.glob(dir + "/" + ruby_dir + "/*"), dest_dir)
|
94
|
+
end
|
95
|
+
|
96
|
+
}
|
97
|
+
}
|
98
|
+
dest_dir
|
99
|
+
end
|
100
|
+
|
101
|
+
module_function :create_makefile_with_core
|
102
|
+
module_function :download_headers
|
103
|
+
|
104
|
+
end
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rogerdpack-ruby_core_ri
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.8
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mark Moseley
|
8
|
+
- Roger Pack
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2009-09-17 00:00:00 -07:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: archive-tar-minitar
|
18
|
+
type: :runtime
|
19
|
+
version_requirement:
|
20
|
+
version_requirements: !ruby/object:Gem::Requirement
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 0.5.2
|
25
|
+
version:
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: backports
|
28
|
+
type: :runtime
|
29
|
+
version_requirement:
|
30
|
+
version_requirements: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 1.8.4
|
35
|
+
version:
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rdoc
|
38
|
+
type: :runtime
|
39
|
+
version_requirement:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: 2.4.3
|
45
|
+
version:
|
46
|
+
description: Retrieve Ruby core source files for ri/rdoc generation
|
47
|
+
email: rogerdpack@gmail.com
|
48
|
+
executables:
|
49
|
+
- ruby_core_ri
|
50
|
+
extensions: []
|
51
|
+
|
52
|
+
extra_rdoc_files:
|
53
|
+
- README
|
54
|
+
files:
|
55
|
+
- README
|
56
|
+
- lib/ruby_core_source.rb
|
57
|
+
- lib/contrib/uri_ext.rb
|
58
|
+
- lib/contrib/progressbar.rb
|
59
|
+
- bin/ruby_core_ri
|
60
|
+
has_rdoc: false
|
61
|
+
homepage: http://github.com/rogerdpack
|
62
|
+
licenses:
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options:
|
65
|
+
- --charset=UTF-8
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: 1.8.2
|
73
|
+
version:
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: "0"
|
79
|
+
version:
|
80
|
+
requirements: []
|
81
|
+
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 1.3.5
|
84
|
+
signing_key:
|
85
|
+
specification_version: 3
|
86
|
+
summary: Retrieve Ruby core source files for ri
|
87
|
+
test_files: []
|
88
|
+
|