core_source 0.2.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/README.rdoc +64 -0
- data/lib/contrib/progressbar.rb +239 -0
- data/lib/contrib/uri_ext.rb +291 -0
- data/lib/core_source.rb +64 -0
- metadata +65 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZWU3Y2JhZmE5YmI4Y2NhMDM4NWE0MmRiMmNlYjFlYjlhMDRhNjVhNQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
N2QwMzNlY2FjYmQ1MmIwYTNmZTEzMjQxODlmNWRjODM2MGZmZjgyYw==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZDZjZWM1MzlkMDYyMzkwZjFlMzBjNWVlYzY2MDJjYjliMzdhMjkxYzc2NWI1
|
10
|
+
ZTg2YWYwMDE0N2ZmZDY5NjdhYmRjZDdiYzc3NzRiNGM1ZWRkYmFiNmIzZWE3
|
11
|
+
MzEzZThmMDBjOGU4OWJkYzVjODExOTBmODczYjc2ZDJjNTg4ZDg=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ODg2NmI3ZDY2MzM4M2I2MTVlODVjYjI5MDI4YzQ2YzM1NDllYTczZDFiNzdi
|
14
|
+
ZDQ0ZWZlYjUwZjk1NzIzZmU2ZmRlZTFiNGJiNzA3ODg0M2QwYmViMTk3YTk3
|
15
|
+
MTBlYWFkYWMzZmEyOGUxZjE5ZDQwNDBjNjI0ZjY1YTZiMTE0MzY=
|
data/README.rdoc
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
== Sender
|
2
|
+
|
3
|
+
http://rubygems.org/gems/core_source
|
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.
|
@@ -0,0 +1,239 @@
|
|
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
|
@@ -0,0 +1,291 @@
|
|
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
ADDED
@@ -0,0 +1,64 @@
|
|
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
|
+
version_path = RUBY_VERSION.to_f == 2.0 ? '2.0' : '1.9'
|
36
|
+
|
37
|
+
|
38
|
+
#
|
39
|
+
# Download the headers
|
40
|
+
#
|
41
|
+
uri_path = "http://ftp.ruby-lang.org/pub/ruby/#{version_path}/" + ruby_dir + ".tar.gz"
|
42
|
+
Tempfile.open("ruby-src") { |temp|
|
43
|
+
|
44
|
+
temp.binmode
|
45
|
+
uri = URI.parse(uri_path)
|
46
|
+
uri.download(temp, {:progress => true})
|
47
|
+
|
48
|
+
tgz = Zlib::GzipReader.new(File.open(temp, "rb"))
|
49
|
+
|
50
|
+
Dir.mktmpdir { |dir|
|
51
|
+
inc_dir = dir + "/" + ruby_dir + "/*.inc"
|
52
|
+
hdr_dir = dir + "/" + ruby_dir + "/*.h"
|
53
|
+
Archive::Tar::Minitar.unpack(tgz, dir)
|
54
|
+
FileUtils.cp( Dir.glob([ inc_dir, hdr_dir ] ), Config::CONFIG["rubyhdrdir"])
|
55
|
+
}
|
56
|
+
}
|
57
|
+
|
58
|
+
return true unless headers.select { |header| have_header( header ) }.empty?
|
59
|
+
|
60
|
+
raise LoadError 'Could not find core headers ' + headers.join( ', ' ) + '.'
|
61
|
+
|
62
|
+
|
63
|
+
end
|
64
|
+
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: core_source
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.8
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jarod Reid
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-09-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: minitar
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: Fork of ruby_core_source modified to support CFLAGS and permit use of
|
28
|
+
whichever build system (mkmf, rpmkmf, or other modules) while utilizing core source.
|
29
|
+
This fork was created because the existing ruby_core_source takes over the build
|
30
|
+
definition, preventing definition of CFLAGS and other settings that mkmf requires
|
31
|
+
be defined by an enclosing block.
|
32
|
+
email: jarod@solidalchemy.com
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- lib/contrib/progressbar.rb
|
38
|
+
- lib/contrib/uri_ext.rb
|
39
|
+
- lib/core_source.rb
|
40
|
+
- README.rdoc
|
41
|
+
homepage: http://github.com/fugufish/core-source
|
42
|
+
licenses: []
|
43
|
+
metadata: {}
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ! '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ! '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
requirements: []
|
59
|
+
rubyforge_project:
|
60
|
+
rubygems_version: 2.1.4
|
61
|
+
signing_key:
|
62
|
+
specification_version: 4
|
63
|
+
summary: Fork of ruby_core_source modified to support CFLAGS and permit use of whichever
|
64
|
+
build system (mkmf, rpmkmf, or other modules) while utilizing core source.
|
65
|
+
test_files: []
|