mini_portile 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -0
- data/Rakefile +1 -1
- data/examples/Rakefile +1 -1
- data/lib/mini_portile.rb +73 -36
- metadata +22 -41
data/History.txt
CHANGED
data/Rakefile
CHANGED
data/examples/Rakefile
CHANGED
@@ -4,7 +4,7 @@ $recipes = {}
|
|
4
4
|
|
5
5
|
ICONV_VERSION = "1.13.1"
|
6
6
|
$recipes[:libiconv] = MiniPortile.new "libiconv", ICONV_VERSION
|
7
|
-
$recipes[:libiconv].files << "
|
7
|
+
$recipes[:libiconv].files << "ftp://ftp.gnu.org/pub/gnu/libiconv/libiconv-#{ICONV_VERSION}.tar.gz"
|
8
8
|
|
9
9
|
$recipes[:sqlite3] = MiniPortile.new "sqlite3", "3.7.5"
|
10
10
|
$recipes[:sqlite3].files << "http://sqlite.org/sqlite-autoconf-3070500.tar.gz"
|
data/lib/mini_portile.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'rbconfig'
|
2
2
|
require 'net/http'
|
3
|
+
require 'net/ftp'
|
3
4
|
require 'fileutils'
|
4
5
|
require 'tempfile'
|
5
6
|
require 'digest/md5'
|
@@ -250,42 +251,53 @@ private
|
|
250
251
|
# and adaptations of Wayne's RailsInstaller
|
251
252
|
def download_file(url, full_path, count = 3)
|
252
253
|
return if File.exist?(full_path)
|
253
|
-
|
254
|
-
|
254
|
+
uri = URI.parse(url)
|
255
255
|
begin
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
else
|
262
|
-
http = Net::HTTP
|
256
|
+
case uri.scheme.downcase
|
257
|
+
when /ftp/
|
258
|
+
download_file_ftp(uri, full_path)
|
259
|
+
when /http|https/
|
260
|
+
download_file_http(url, full_path, count)
|
263
261
|
end
|
262
|
+
rescue Exception => e
|
263
|
+
File.unlink full_path if File.exists?(full_path)
|
264
|
+
output "ERROR: #{e.message}"
|
265
|
+
raise "Failed to complete download task"
|
266
|
+
end
|
267
|
+
end
|
264
268
|
|
265
|
-
|
266
|
-
|
267
|
-
case response
|
268
|
-
when Net::HTTPNotFound
|
269
|
-
output "404 - Not Found"
|
270
|
-
return false
|
269
|
+
def download_file_http(url, full_path, count = 3)
|
270
|
+
filename = File.basename(full_path)
|
271
271
|
|
272
|
-
|
273
|
-
|
274
|
-
|
272
|
+
if ENV['http_proxy']
|
273
|
+
protocol, userinfo, host, port = URI::split(ENV['http_proxy'])
|
274
|
+
proxy_user, proxy_pass = userinfo.split(/:/) if userinfo
|
275
|
+
http = Net::HTTP::Proxy(host, port, proxy_user, proxy_pass)
|
276
|
+
else
|
277
|
+
http = Net::HTTP
|
278
|
+
end
|
279
|
+
|
280
|
+
message "Downloading #{filename} "
|
281
|
+
http.get_response(URI.parse(url)) do |response|
|
282
|
+
case response
|
283
|
+
when Net::HTTPNotFound
|
284
|
+
output "404 - Not Found"
|
285
|
+
return false
|
275
286
|
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
return download_file(url, full_path, count - 1)
|
287
|
+
when Net::HTTPClientError
|
288
|
+
output "Error: Client Error: #{response.inspect}"
|
289
|
+
return false
|
280
290
|
|
281
|
-
|
282
|
-
|
283
|
-
|
291
|
+
when Net::HTTPRedirection
|
292
|
+
raise "Too many redirections for the original URL, halting." if count <= 0
|
293
|
+
url = response["location"]
|
294
|
+
return download_file(url, full_path, count - 1)
|
284
295
|
|
296
|
+
when Net::HTTPOK
|
297
|
+
with_tempfile(filename, full_path) do |temp_file|
|
285
298
|
size = 0
|
286
299
|
progress = 0
|
287
300
|
total = response.header["Content-Length"].to_i
|
288
|
-
|
289
301
|
response.read_body do |chunk|
|
290
302
|
temp_file << chunk
|
291
303
|
size += chunk.size
|
@@ -295,20 +307,45 @@ private
|
|
295
307
|
end
|
296
308
|
progress = new_progress
|
297
309
|
end
|
298
|
-
|
299
310
|
output
|
300
|
-
|
301
|
-
temp_file.close
|
302
|
-
File.unlink full_path if File.exists?(full_path)
|
303
|
-
FileUtils.mkdir_p File.dirname(full_path)
|
304
|
-
FileUtils.mv temp_file.path, full_path, :force => true
|
305
311
|
end
|
306
312
|
end
|
313
|
+
end
|
314
|
+
end
|
307
315
|
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
316
|
+
def download_file_ftp(uri, full_path)
|
317
|
+
filename = File.basename(uri.path)
|
318
|
+
with_tempfile(filename, full_path) do |temp_file|
|
319
|
+
size = 0
|
320
|
+
progress = 0
|
321
|
+
Net::FTP.open(uri.host, uri.user, uri.password) do |ftp|
|
322
|
+
ftp.passive = true
|
323
|
+
ftp.login
|
324
|
+
remote_dir = File.dirname(uri.path)
|
325
|
+
ftp.chdir(remote_dir) unless remote_dir == '.'
|
326
|
+
total = ftp.size(filename)
|
327
|
+
ftp.getbinaryfile(filename, nil, 8192) do |chunk|
|
328
|
+
temp_file << chunk
|
329
|
+
size += chunk.size
|
330
|
+
new_progress = (size * 100) / total
|
331
|
+
unless new_progress == progress
|
332
|
+
message "\rDownloading %s (%3d%%) " % [filename, new_progress]
|
333
|
+
end
|
334
|
+
progress = new_progress
|
335
|
+
end
|
336
|
+
end
|
337
|
+
output
|
312
338
|
end
|
313
339
|
end
|
340
|
+
|
341
|
+
def with_tempfile(filename, full_path)
|
342
|
+
temp_file = Tempfile.new("download-#{filename}")
|
343
|
+
temp_file.binmode
|
344
|
+
yield temp_file
|
345
|
+
temp_file.close
|
346
|
+
File.unlink full_path if File.exists?(full_path)
|
347
|
+
FileUtils.mkdir_p File.dirname(full_path)
|
348
|
+
FileUtils.mv temp_file.path, full_path, :force => true
|
349
|
+
end
|
350
|
+
|
314
351
|
end
|
metadata
CHANGED
@@ -1,34 +1,27 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: mini_portile
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.4.0
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 3
|
9
|
-
- 0
|
10
|
-
version: 0.3.0
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Luis Lavena
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
date: 2012-03-23 00:00:00 Z
|
12
|
+
date: 2012-10-25 00:00:00.000000000 Z
|
19
13
|
dependencies: []
|
20
|
-
|
21
|
-
|
14
|
+
description: Simplistic port-like solution for developers. It provides a standard
|
15
|
+
and simplified way to compile against dependency libraries without messing up your
|
16
|
+
system.
|
22
17
|
email: luislavena@gmail.com
|
23
18
|
executables: []
|
24
|
-
|
25
19
|
extensions: []
|
26
|
-
|
27
|
-
extra_rdoc_files:
|
20
|
+
extra_rdoc_files:
|
28
21
|
- README.rdoc
|
29
22
|
- History.txt
|
30
23
|
- LICENSE.txt
|
31
|
-
files:
|
24
|
+
files:
|
32
25
|
- examples/Rakefile
|
33
26
|
- lib/mini_portile.rb
|
34
27
|
- Rakefile
|
@@ -36,44 +29,32 @@ files:
|
|
36
29
|
- History.txt
|
37
30
|
- LICENSE.txt
|
38
31
|
homepage: http://github.com/luislavena/mini_portile
|
39
|
-
licenses:
|
32
|
+
licenses:
|
40
33
|
- MIT
|
41
34
|
post_install_message:
|
42
|
-
rdoc_options:
|
35
|
+
rdoc_options:
|
43
36
|
- --main
|
44
37
|
- README.rdoc
|
45
38
|
- --title
|
46
39
|
- MiniPortile -- Documentation
|
47
|
-
require_paths:
|
40
|
+
require_paths:
|
48
41
|
- lib
|
49
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
43
|
none: false
|
51
|
-
requirements:
|
52
|
-
- -
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
hash: 57
|
55
|
-
segments:
|
56
|
-
- 1
|
57
|
-
- 8
|
58
|
-
- 7
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
59
47
|
version: 1.8.7
|
60
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
49
|
none: false
|
62
|
-
requirements:
|
63
|
-
- -
|
64
|
-
- !ruby/object:Gem::Version
|
65
|
-
hash: 17
|
66
|
-
segments:
|
67
|
-
- 1
|
68
|
-
- 3
|
69
|
-
- 5
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
70
53
|
version: 1.3.5
|
71
54
|
requirements: []
|
72
|
-
|
73
55
|
rubyforge_project:
|
74
|
-
rubygems_version: 1.8.
|
56
|
+
rubygems_version: 1.8.24
|
75
57
|
signing_key:
|
76
58
|
specification_version: 3
|
77
59
|
summary: Simplistic port-like solution for developers
|
78
60
|
test_files: []
|
79
|
-
|