core-source 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- metadata +20 -15
- data/README.rdoc +0 -64
- data/lib/VERSION.rdoc +0 -1
- data/lib/contrib/progressbar.rb +0 -239
- data/lib/contrib/uri_ext.rb +0 -291
- data/lib/core-source.rb +0 -61
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 5
|
9
|
+
version: 0.2.5
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Asher
|
@@ -14,14 +14,23 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-11-28 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
|
-
dependencies:
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: minitar
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
version: "0"
|
31
|
+
type: :runtime
|
32
|
+
version_requirements: *id001
|
33
|
+
description: Fork of ruby_core_source modified to support CFLAGS and permit use of whichever build system (mkmf, rpmkmf, or other modules) while utilizing core source. This fork was created because the existing ruby_core_source takes over the build definition, preventing definition of CFLAGS and other settings that mkmf requires be defined by an enclosing block.
|
25
34
|
email: asher@ridiculouspower.com
|
26
35
|
executables: []
|
27
36
|
|
@@ -29,12 +38,8 @@ extensions: []
|
|
29
38
|
|
30
39
|
extra_rdoc_files: []
|
31
40
|
|
32
|
-
files:
|
33
|
-
|
34
|
-
- lib/contrib/uri_ext.rb
|
35
|
-
- lib/core-source.rb
|
36
|
-
- lib/VERSION.rdoc
|
37
|
-
- README.rdoc
|
41
|
+
files: []
|
42
|
+
|
38
43
|
has_rdoc: true
|
39
44
|
homepage: http://rubygems.org/gems/core-source
|
40
45
|
licenses: []
|
data/README.rdoc
DELETED
@@ -1,64 +0,0 @@
|
|
1
|
-
== Sender
|
2
|
-
|
3
|
-
http://rubygems.org/gems/weakhash
|
4
|
-
|
5
|
-
== DESCRIPTION:
|
6
|
-
|
7
|
-
Fork of ruby_core_source modified to support CFLAGS and permit use of
|
8
|
-
whichever build system (mkmf, rpmkmf, or other modules) while utilizing
|
9
|
-
core source.
|
10
|
-
|
11
|
-
This fork was created because the existing ruby_core_source takes over
|
12
|
-
the build definition, preventing definition of CFLAGS and other settings
|
13
|
-
that mkmf requires be defined by an enclosing block.
|
14
|
-
|
15
|
-
== INSTALL:
|
16
|
-
|
17
|
-
* sudo gem install rp_ruby_core_source
|
18
|
-
|
19
|
-
== EXAMPLE:
|
20
|
-
|
21
|
-
require 'mkmfmf' # mkmfmf is a drop-in replacement for mkmf; see http://rubygems.org/gems/mkmfmf
|
22
|
-
require 'core-source'
|
23
|
-
|
24
|
-
target = "gdb_helper"
|
25
|
-
|
26
|
-
required_core_headers = [ "vm_core.h",
|
27
|
-
"iseq.h",
|
28
|
-
"eval_intern.h",
|
29
|
-
"version.h",
|
30
|
-
"node.h" ]
|
31
|
-
|
32
|
-
default_cflags = "-march=x86-64 -gfull -fcatch-undefined-behavior -fno-common -fsigned-char -pipe"
|
33
|
-
|
34
|
-
# Create our makefile from sources
|
35
|
-
if ensure_core_headers( required_core_headers )
|
36
|
-
with_cflags( default_cflags ) do
|
37
|
-
create_makefile( target )
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
== LICENSE:
|
42
|
-
|
43
|
-
(The MIT License)
|
44
|
-
|
45
|
-
Copyright (c) 2010 Asher
|
46
|
-
|
47
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
48
|
-
a copy of this software and associated documentation files (the
|
49
|
-
'Software'), to deal in the Software without restriction, including
|
50
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
51
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
52
|
-
permit persons to whom the Software is furnished to do so, subject to
|
53
|
-
the following conditions:
|
54
|
-
|
55
|
-
The above copyright notice and this permission notice shall be
|
56
|
-
included in all copies or substantial portions of the Software.
|
57
|
-
|
58
|
-
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
59
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
60
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
61
|
-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
62
|
-
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
63
|
-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
64
|
-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/lib/VERSION.rdoc
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.1
|
data/lib/contrib/progressbar.rb
DELETED
@@ -1,239 +0,0 @@
|
|
1
|
-
# Contrib code taken from ruby_core_source
|
2
|
-
|
3
|
-
# = progressbar.rb
|
4
|
-
#
|
5
|
-
# == Copyright (C) 2001 Satoru Takabayashi
|
6
|
-
#
|
7
|
-
# Ruby License
|
8
|
-
#
|
9
|
-
# This module is free software. You may use, modify, and/or redistribute this
|
10
|
-
# software under the same terms as Ruby.
|
11
|
-
#
|
12
|
-
# This program is distributed in the hope that it will be useful, but WITHOUT
|
13
|
-
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
14
|
-
# FOR A PARTICULAR PURPOSE.
|
15
|
-
#
|
16
|
-
# == Author(s)
|
17
|
-
#
|
18
|
-
# * Satoru Takabayashi
|
19
|
-
|
20
|
-
# Author:: Satoru Takabayashi
|
21
|
-
# Copyright:: Copyright (c) 2001 Satoru Takabayashi
|
22
|
-
# License:: Ruby License
|
23
|
-
|
24
|
-
# = Console Progress Bar
|
25
|
-
#
|
26
|
-
# Console::ProgressBar is a terminal-based progress bar library.
|
27
|
-
#
|
28
|
-
# == Usage
|
29
|
-
#
|
30
|
-
# pbar = ConsoleProgressBar.new( "Demo", 100 )
|
31
|
-
# 100.times { pbar.inc }
|
32
|
-
# pbar.finish
|
33
|
-
#
|
34
|
-
|
35
|
-
module Console; end
|
36
|
-
|
37
|
-
class Console::ProgressBar
|
38
|
-
|
39
|
-
def initialize(title, total, out = STDERR)
|
40
|
-
@title = title
|
41
|
-
@total = total
|
42
|
-
@out = out
|
43
|
-
@bar_length = 80
|
44
|
-
@bar_mark = "o"
|
45
|
-
@total_overflow = true
|
46
|
-
@current = 0
|
47
|
-
@previous = 0
|
48
|
-
@is_finished = false
|
49
|
-
@start_time = Time.now
|
50
|
-
@format = "%-14s %3d%% %s %s"
|
51
|
-
@format_arguments = [:title, :percentage, :bar, :stat]
|
52
|
-
show_progress
|
53
|
-
end
|
54
|
-
|
55
|
-
private
|
56
|
-
def convert_bytes (bytes)
|
57
|
-
if bytes < 1024
|
58
|
-
sprintf("%6dB", bytes)
|
59
|
-
elsif bytes < 1024 * 1000 # 1000kb
|
60
|
-
sprintf("%5.1fKB", bytes.to_f / 1024)
|
61
|
-
elsif bytes < 1024 * 1024 * 1000 # 1000mb
|
62
|
-
sprintf("%5.1fMB", bytes.to_f / 1024 / 1024)
|
63
|
-
else
|
64
|
-
sprintf("%5.1fGB", bytes.to_f / 1024 / 1024 / 1024)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def transfer_rate
|
69
|
-
bytes_per_second = @current.to_f / (Time.now - @start_time)
|
70
|
-
sprintf("%s/s", convert_bytes(bytes_per_second))
|
71
|
-
end
|
72
|
-
|
73
|
-
def bytes
|
74
|
-
convert_bytes(@current)
|
75
|
-
end
|
76
|
-
|
77
|
-
def format_time (t)
|
78
|
-
t = t.to_i
|
79
|
-
sec = t % 60
|
80
|
-
min = (t / 60) % 60
|
81
|
-
hour = t / 3600
|
82
|
-
sprintf("%02d:%02d:%02d", hour, min, sec);
|
83
|
-
end
|
84
|
-
|
85
|
-
# ETA stands for Estimated Time of Arrival.
|
86
|
-
def eta
|
87
|
-
if @current == 0
|
88
|
-
"ETA: --:--:--"
|
89
|
-
else
|
90
|
-
elapsed = Time.now - @start_time
|
91
|
-
eta = elapsed * @total / @current - elapsed;
|
92
|
-
sprintf("ETA: %s", format_time(eta))
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
def elapsed
|
97
|
-
elapsed = Time.now - @start_time
|
98
|
-
sprintf("Time: %s", format_time(elapsed))
|
99
|
-
end
|
100
|
-
|
101
|
-
def stat
|
102
|
-
if @is_finished then elapsed else eta end
|
103
|
-
end
|
104
|
-
|
105
|
-
def stat_for_file_transfer
|
106
|
-
if @is_finished then
|
107
|
-
sprintf("%s %s %s", bytes, transfer_rate, elapsed)
|
108
|
-
else
|
109
|
-
sprintf("%s %s %s", bytes, transfer_rate, eta)
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
def eol
|
114
|
-
if @is_finished then "\n" else "\r" end
|
115
|
-
end
|
116
|
-
|
117
|
-
def bar
|
118
|
-
len = percentage * @bar_length / 100
|
119
|
-
sprintf("|%s%s|", @bar_mark * len, " " * (@bar_length - len))
|
120
|
-
end
|
121
|
-
|
122
|
-
def percentage
|
123
|
-
if @total.zero?
|
124
|
-
100
|
125
|
-
else
|
126
|
-
@current * 100 / @total
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
def title
|
131
|
-
@title[0,13] + ":"
|
132
|
-
end
|
133
|
-
|
134
|
-
def get_width
|
135
|
-
# FIXME: I don't know how portable it is.
|
136
|
-
default_width = 80
|
137
|
-
begin
|
138
|
-
tiocgwinsz = 0x5413
|
139
|
-
data = [0, 0, 0, 0].pack("SSSS")
|
140
|
-
if @out.ioctl(tiocgwinsz, data) >= 0 then
|
141
|
-
rows, cols, xpixels, ypixels = data.unpack("SSSS")
|
142
|
-
if cols >= 0 then cols else default_width end
|
143
|
-
else
|
144
|
-
default_width
|
145
|
-
end
|
146
|
-
rescue Exception
|
147
|
-
default_width
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
def show
|
152
|
-
arguments = @format_arguments.map {|method| send(method) }
|
153
|
-
line = sprintf(@format, *arguments)
|
154
|
-
|
155
|
-
width = get_width
|
156
|
-
if line.length == width - 1
|
157
|
-
@out.print(line + eol)
|
158
|
-
elsif line.length >= width
|
159
|
-
@bar_length = [@bar_length - (line.length - width + 1), 0].max
|
160
|
-
if @bar_length == 0 then @out.print(line + eol) else show end
|
161
|
-
else #line.length < width - 1
|
162
|
-
@bar_length += width - line.length + 1
|
163
|
-
show
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
|
-
def show_progress
|
168
|
-
if @total.zero?
|
169
|
-
cur_percentage = 100
|
170
|
-
prev_percentage = 0
|
171
|
-
else
|
172
|
-
cur_percentage = (@current * 100 / @total).to_i
|
173
|
-
prev_percentage = (@previous * 100 / @total).to_i
|
174
|
-
end
|
175
|
-
|
176
|
-
if cur_percentage > prev_percentage || @is_finished
|
177
|
-
show
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
|
-
public
|
182
|
-
def file_transfer_mode
|
183
|
-
@format_arguments = [:title, :percentage, :bar, :stat_for_file_transfer]
|
184
|
-
end
|
185
|
-
|
186
|
-
def bar_mark= (mark)
|
187
|
-
@bar_mark = String(mark)[0..0]
|
188
|
-
end
|
189
|
-
|
190
|
-
def total_overflow= (boolv)
|
191
|
-
@total_overflow = boolv ? true : false
|
192
|
-
end
|
193
|
-
|
194
|
-
def format= (format)
|
195
|
-
@format = format
|
196
|
-
end
|
197
|
-
|
198
|
-
def format_arguments= (arguments)
|
199
|
-
@format_arguments = arguments
|
200
|
-
end
|
201
|
-
|
202
|
-
def finish
|
203
|
-
@current = @total
|
204
|
-
@is_finished = true
|
205
|
-
show_progress
|
206
|
-
end
|
207
|
-
|
208
|
-
def halt
|
209
|
-
@is_finished = true
|
210
|
-
show_progress
|
211
|
-
end
|
212
|
-
|
213
|
-
def set (count)
|
214
|
-
if count < 0
|
215
|
-
raise "invalid count less than zero: #{count}"
|
216
|
-
elsif count > @total
|
217
|
-
if @total_overflow
|
218
|
-
@total = count + 1
|
219
|
-
else
|
220
|
-
raise "invalid count greater than total: #{count}"
|
221
|
-
end
|
222
|
-
end
|
223
|
-
@current = count
|
224
|
-
show_progress
|
225
|
-
@previous = @current
|
226
|
-
end
|
227
|
-
|
228
|
-
def inc (step = 1)
|
229
|
-
@current += step
|
230
|
-
@current = @total if @current > @total
|
231
|
-
show_progress
|
232
|
-
@previous = @current
|
233
|
-
end
|
234
|
-
|
235
|
-
def inspect
|
236
|
-
"(ProgressBar: #{@current}/#{@total})"
|
237
|
-
end
|
238
|
-
|
239
|
-
end
|
data/lib/contrib/uri_ext.rb
DELETED
@@ -1,291 +0,0 @@
|
|
1
|
-
# Contrib code taken from ruby_core_source, modified only to enable progress bar
|
2
|
-
|
3
|
-
#
|
4
|
-
# I've striped down dependencies on Net::SSH and Facets to
|
5
|
-
# stay as simple as possible.
|
6
|
-
#
|
7
|
-
# Original code from Assaf Arkin, released under Apache License
|
8
|
-
# (http://buildr.rubyforge.org/license.html)
|
9
|
-
#
|
10
|
-
require 'cgi'
|
11
|
-
require 'uri'
|
12
|
-
require 'net/http'
|
13
|
-
require 'net/https'
|
14
|
-
require 'tempfile'
|
15
|
-
require 'fileutils'
|
16
|
-
|
17
|
-
# show progress of download
|
18
|
-
require File.join(File.dirname(__FILE__), 'progressbar')
|
19
|
-
|
20
|
-
# Not quite open-uri, but similar. Provides read and write methods for the resource represented by the URI.
|
21
|
-
# Currently supports reads for URI::HTTP and writes for URI::SFTP. Also provides convenience methods for
|
22
|
-
# downloads and uploads.
|
23
|
-
module URI
|
24
|
-
# Raised when trying to read/download a resource that doesn't exist.
|
25
|
-
class NotFoundError < RuntimeError; end
|
26
|
-
|
27
|
-
class << self
|
28
|
-
# :call-seq:
|
29
|
-
# read(uri, options?) => content
|
30
|
-
# read(uri, options?) { |chunk| ... }
|
31
|
-
#
|
32
|
-
# Reads from the resource behind this URI. The first form returns the content of the resource,
|
33
|
-
# the second form yields to the block with each chunk of content (usually more than one).
|
34
|
-
#
|
35
|
-
# For example:
|
36
|
-
# File.open "image.jpg", "w" do |file|
|
37
|
-
# URI.read("http://example.com/image.jpg") { |chunk| file.write chunk }
|
38
|
-
# end
|
39
|
-
# Shorter version:
|
40
|
-
# File.open("image.jpg", "w") { |file| file.write URI.read("http://example.com/image.jpg") }
|
41
|
-
#
|
42
|
-
# Supported options:
|
43
|
-
# * :modified -- Only download if file modified since this timestamp. Returns nil if not modified.
|
44
|
-
# * :progress -- Show the progress bar while reading.
|
45
|
-
def read(uri, options = nil, &block)
|
46
|
-
uri = URI.parse(uri.to_s) unless URI === uri
|
47
|
-
uri.read(options, &block)
|
48
|
-
end
|
49
|
-
|
50
|
-
# :call-seq:
|
51
|
-
# download(uri, target, options?)
|
52
|
-
#
|
53
|
-
# Downloads the resource to the target.
|
54
|
-
#
|
55
|
-
# The target may be a file name (string or task), in which case the file is created from the resource.
|
56
|
-
# The target may also be any object that responds to +write+, e.g. File, StringIO, Pipe.
|
57
|
-
#
|
58
|
-
# Use the progress bar when running in verbose mode.
|
59
|
-
def download(uri, target, options = nil)
|
60
|
-
uri = URI.parse(uri.to_s) unless URI === uri
|
61
|
-
uri.download(target, options)
|
62
|
-
end
|
63
|
-
|
64
|
-
# :call-seq:
|
65
|
-
# write(uri, content, options?)
|
66
|
-
# write(uri, options?) { |bytes| .. }
|
67
|
-
#
|
68
|
-
# Writes to the resource behind the URI. The first form writes the content from a string or an object
|
69
|
-
# that responds to +read+ and optionally +size+. The second form writes the content by yielding to the
|
70
|
-
# block. Each yield should return up to the specified number of bytes, the last yield returns nil.
|
71
|
-
#
|
72
|
-
# For example:
|
73
|
-
# File.open "killer-app.jar", "rb" do |file|
|
74
|
-
# write("sftp://localhost/jars/killer-app.jar") { |chunk| file.read(chunk) }
|
75
|
-
# end
|
76
|
-
# Or:
|
77
|
-
# write "sftp://localhost/jars/killer-app.jar", File.read("killer-app.jar")
|
78
|
-
#
|
79
|
-
# Supported options:
|
80
|
-
# * :progress -- Show the progress bar while reading.
|
81
|
-
def write(uri, *args, &block)
|
82
|
-
uri = URI.parse(uri.to_s) unless URI === uri
|
83
|
-
uri.write(*args, &block)
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
class Generic
|
88
|
-
|
89
|
-
# :call-seq:
|
90
|
-
# read(options?) => content
|
91
|
-
# read(options?) { |chunk| ... }
|
92
|
-
#
|
93
|
-
# Reads from the resource behind this URI. The first form returns the content of the resource,
|
94
|
-
# the second form yields to the block with each chunk of content (usually more than one).
|
95
|
-
#
|
96
|
-
# For options, see URI::read.
|
97
|
-
def read(options = nil, &block)
|
98
|
-
fail "This protocol doesn't support reading (yet, how about helping by implementing it?)"
|
99
|
-
end
|
100
|
-
|
101
|
-
# :call-seq:
|
102
|
-
# download(target, options?)
|
103
|
-
#
|
104
|
-
# Downloads the resource to the target.
|
105
|
-
#
|
106
|
-
# The target may be a file name (string or task), in which case the file is created from the resource.
|
107
|
-
# The target may also be any object that responds to +write+, e.g. File, StringIO, Pipe.
|
108
|
-
#
|
109
|
-
# Use the progress bar when running in verbose mode.
|
110
|
-
def download(target, options = {})
|
111
|
-
case target
|
112
|
-
when String
|
113
|
-
# If download breaks we end up with a partial file which is
|
114
|
-
# worse than not having a file at all, so download to temporary
|
115
|
-
# file and then move over.
|
116
|
-
modified = File.stat(target).mtime if File.exist?(target)
|
117
|
-
temp = nil
|
118
|
-
Tempfile.open(File.basename(target)) do |tf|
|
119
|
-
tf.binmode
|
120
|
-
read(options.merge(:modified => modified)) { |chunk| tf.write chunk }
|
121
|
-
temp = tf
|
122
|
-
end
|
123
|
-
FileUtils.mkpath(File.dirname(target))
|
124
|
-
FileUtils.move(temp.path, target)
|
125
|
-
when File
|
126
|
-
read(options.merge(:modified => target.mtime)) { |chunk| target.write chunk }
|
127
|
-
target.flush
|
128
|
-
else
|
129
|
-
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)
|
130
|
-
read(options) { |chunk| target.write chunk }
|
131
|
-
target.flush
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
# :call-seq:
|
136
|
-
# write(content, options?)
|
137
|
-
# write(options?) { |bytes| .. }
|
138
|
-
#
|
139
|
-
# Writes to the resource behind the URI. The first form writes the content from a string or an object
|
140
|
-
# that responds to +read+ and optionally +size+. The second form writes the content by yielding to the
|
141
|
-
# block. Each yield should return up to the specified number of bytes, the last yield returns nil.
|
142
|
-
#
|
143
|
-
# For options, see URI::write.
|
144
|
-
def write(*args, &block)
|
145
|
-
options = args.pop if Hash === args.last
|
146
|
-
options ||= {}
|
147
|
-
if String === args.first
|
148
|
-
ios = StringIO.new(args.first, "r")
|
149
|
-
write(options.merge(:size => args.first.size)) { |bytes| ios.read(bytes) }
|
150
|
-
elsif args.first.respond_to?(:read)
|
151
|
-
size = args.first.size rescue nil
|
152
|
-
write({ :size => size }.merge(options)) { |bytes| args.first.read(bytes) }
|
153
|
-
elsif args.empty? && block
|
154
|
-
write_internal(options, &block)
|
155
|
-
else
|
156
|
-
raise ArgumentError, "Either give me the content, or pass me a block, otherwise what would I upload?"
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
protected
|
161
|
-
|
162
|
-
# :call-seq:
|
163
|
-
# with_progress_bar(enable, file_name, size) { |progress| ... }
|
164
|
-
#
|
165
|
-
# Displays a progress bar while executing the block. The first argument must be true for the
|
166
|
-
# progress bar to show (TTY output also required), as a convenient for selectively using the
|
167
|
-
# progress bar from a single block.
|
168
|
-
#
|
169
|
-
# The second argument provides a filename to display, the third its size in bytes.
|
170
|
-
#
|
171
|
-
# The block is yielded with a progress object that implements a single method.
|
172
|
-
# Call << for each block of bytes down/uploaded.
|
173
|
-
def with_progress_bar(enable, file_name, size) #:nodoc:
|
174
|
-
if enable && $stdout.isatty
|
175
|
-
progress_bar = Console::ProgressBar.new(file_name, size)
|
176
|
-
# Extend the progress bar so we can display count/total.
|
177
|
-
class << progress_bar
|
178
|
-
def total()
|
179
|
-
convert_bytes(@total)
|
180
|
-
end
|
181
|
-
end
|
182
|
-
# Squeeze the filename into 30 characters.
|
183
|
-
if file_name.size > 30
|
184
|
-
base, ext = File.basename(file_name), File.extname(file_name)
|
185
|
-
truncated = "#{base[0..26-ext.to_s.size]}..#{ext}"
|
186
|
-
else
|
187
|
-
truncated = file_name
|
188
|
-
end
|
189
|
-
progress_bar.format = "#{CGI.unescape(truncated)}: %3d%% %s %s/%s %s"
|
190
|
-
progress_bar.format_arguments = [:percentage, :bar, :bytes, :total, :stat]
|
191
|
-
progress_bar.bar_mark = "o"
|
192
|
-
|
193
|
-
begin
|
194
|
-
class << progress_bar
|
195
|
-
def <<(bytes)
|
196
|
-
inc bytes.respond_to?(:size) ? bytes.size : bytes
|
197
|
-
end
|
198
|
-
end
|
199
|
-
yield progress_bar
|
200
|
-
ensure
|
201
|
-
progress_bar.finish
|
202
|
-
end
|
203
|
-
else
|
204
|
-
progress_bar = Object.new
|
205
|
-
class << progress_bar
|
206
|
-
def <<(bytes)
|
207
|
-
end
|
208
|
-
end
|
209
|
-
yield progress_bar
|
210
|
-
end
|
211
|
-
end
|
212
|
-
|
213
|
-
# :call-seq:
|
214
|
-
# proxy_uri() => URI?
|
215
|
-
#
|
216
|
-
# Returns the proxy server to use. Obtains the proxy from the relevant environment variable (e.g. HTTP_PROXY).
|
217
|
-
# Supports exclusions based on host name and port number from environment variable NO_PROXY.
|
218
|
-
def proxy_uri()
|
219
|
-
proxy = ENV["#{scheme.upcase}_PROXY"]
|
220
|
-
proxy = URI.parse(proxy) if String === proxy
|
221
|
-
excludes = (ENV["NO_PROXY"] || "").split(/\s*,\s*/).compact
|
222
|
-
excludes = excludes.map { |exclude| exclude =~ /:\d+$/ ? exclude : "#{exclude}:*" }
|
223
|
-
return proxy unless excludes.any? { |exclude| File.fnmatch(exclude, "#{host}:#{port}") }
|
224
|
-
end
|
225
|
-
|
226
|
-
def write_internal(options, &block) #:nodoc:
|
227
|
-
fail "This protocol doesn't support writing (yet, how about helping by implementing it?)"
|
228
|
-
end
|
229
|
-
end
|
230
|
-
|
231
|
-
class HTTP #:nodoc:
|
232
|
-
|
233
|
-
# See URI::Generic#read
|
234
|
-
def read(options = nil, &block)
|
235
|
-
options ||= {}
|
236
|
-
connect do |http|
|
237
|
-
puts "Requesting #{self}" #if verbose
|
238
|
-
headers = { 'If-Modified-Since' => CGI.rfc1123_date(options[:modified].utc) } if options[:modified]
|
239
|
-
request = Net::HTTP::Get.new(request_uri.empty? ? '/' : request_uri, headers)
|
240
|
-
request.basic_auth self.user, self.password if self.user
|
241
|
-
http.request request do |response|
|
242
|
-
case response
|
243
|
-
when Net::HTTPNotModified
|
244
|
-
# No modification, nothing to do.
|
245
|
-
puts 'Not modified since last download' #if verbose
|
246
|
-
return nil
|
247
|
-
when Net::HTTPRedirection
|
248
|
-
# Try to download from the new URI, handle relative redirects.
|
249
|
-
puts "Redirected to #{response['Location']}" #if verbose
|
250
|
-
return (self + URI.parse(response['location'])).read(options, &block)
|
251
|
-
when Net::HTTPOK
|
252
|
-
puts "Downloading #{self}" #if verbose
|
253
|
-
result = nil
|
254
|
-
with_progress_bar options[:progress], path.split('/').last, response.content_length do |progress|
|
255
|
-
if block
|
256
|
-
response.read_body do |chunk|
|
257
|
-
block.call chunk
|
258
|
-
progress << chunk
|
259
|
-
end
|
260
|
-
else
|
261
|
-
result = ''
|
262
|
-
response.read_body do |chunk|
|
263
|
-
result << chunk
|
264
|
-
progress << chunk
|
265
|
-
end
|
266
|
-
end
|
267
|
-
end
|
268
|
-
return result
|
269
|
-
when Net::HTTPNotFound
|
270
|
-
raise NotFoundError, "Looking for #{self} and all I got was a 404!"
|
271
|
-
else
|
272
|
-
raise RuntimeError, "Failed to download #{self}: #{response.message}"
|
273
|
-
end
|
274
|
-
end
|
275
|
-
end
|
276
|
-
end
|
277
|
-
|
278
|
-
private
|
279
|
-
|
280
|
-
def connect
|
281
|
-
if proxy = proxy_uri
|
282
|
-
proxy = URI.parse(proxy) if String === proxy
|
283
|
-
http = Net::HTTP.new(host, port, proxy.host, proxy.port, proxy.user, proxy.password)
|
284
|
-
else
|
285
|
-
http = Net::HTTP.new(host, port)
|
286
|
-
end
|
287
|
-
http.use_ssl = true if self.instance_of? URI::HTTPS
|
288
|
-
yield http
|
289
|
-
end
|
290
|
-
end
|
291
|
-
end
|
data/lib/core-source.rb
DELETED
@@ -1,61 +0,0 @@
|
|
1
|
-
|
2
|
-
require_relative 'contrib/uri_ext.rb'
|
3
|
-
require_relative 'contrib/progressbar.rb'
|
4
|
-
|
5
|
-
require 'rbconfig'
|
6
|
-
require 'yaml'
|
7
|
-
require 'archive/tar/minitar'
|
8
|
-
require 'zlib'
|
9
|
-
require 'fileutils'
|
10
|
-
require 'tmpdir'
|
11
|
-
require 'tempfile'
|
12
|
-
|
13
|
-
STATUS_BAR_WIDTH = 80
|
14
|
-
|
15
|
-
def ensure_core_headers( headers )
|
16
|
-
|
17
|
-
unless headers.select { |header| have_header( header ) }.empty?
|
18
|
-
return true
|
19
|
-
end
|
20
|
-
|
21
|
-
ruby_dir = ""
|
22
|
-
if RUBY_PATCHLEVEL < 0
|
23
|
-
Tempfile.open("preview-revision") { |temp|
|
24
|
-
uri_path = "http://cloud.github.com/downloads/mark-moseley/ruby_core_source/preview_revision.yml"
|
25
|
-
uri = URI.parse(uri_path)
|
26
|
-
uri.download(temp, {:progress => true})
|
27
|
-
revision_map = YAML::load(File.open(temp.path))
|
28
|
-
ruby_dir = revision_map[RUBY_REVISION]
|
29
|
-
return false if ruby_dir.nil?
|
30
|
-
}
|
31
|
-
else
|
32
|
-
ruby_dir = "ruby-" + RUBY_VERSION.to_s + "-p" + RUBY_PATCHLEVEL.to_s
|
33
|
-
end
|
34
|
-
|
35
|
-
#
|
36
|
-
# Download the headers
|
37
|
-
#
|
38
|
-
uri_path = "http://ftp.ruby-lang.org/pub/ruby/1.9/" + ruby_dir + ".tar.gz"
|
39
|
-
Tempfile.open("ruby-src") { |temp|
|
40
|
-
|
41
|
-
temp.binmode
|
42
|
-
uri = URI.parse(uri_path)
|
43
|
-
uri.download(temp, {:progress => true})
|
44
|
-
|
45
|
-
tgz = Zlib::GzipReader.new(File.open(temp, "rb"))
|
46
|
-
|
47
|
-
Dir.mktmpdir { |dir|
|
48
|
-
inc_dir = dir + "/" + ruby_dir + "/*.inc"
|
49
|
-
hdr_dir = dir + "/" + ruby_dir + "/*.h"
|
50
|
-
Archive::Tar::Minitar.unpack(tgz, dir)
|
51
|
-
FileUtils.cp( Dir.glob([ inc_dir, hdr_dir ] ), Config::CONFIG["rubyhdrdir"])
|
52
|
-
}
|
53
|
-
}
|
54
|
-
|
55
|
-
return true unless headers.select { |header| have_header( header ) }.empty?
|
56
|
-
|
57
|
-
raise LoadError 'Could not find core headers ' + headers.join( ', ' ) + '.'
|
58
|
-
|
59
|
-
|
60
|
-
end
|
61
|
-
|