evoker 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/evoker/local_cache.rb +60 -0
- data/lib/evoker/version.rb +1 -1
- metadata +5 -4
@@ -0,0 +1,60 @@
|
|
1
|
+
# Caching of individual downloaded files in a local directory
|
2
|
+
|
3
|
+
require 'digest'
|
4
|
+
require 'fileutils'
|
5
|
+
|
6
|
+
require 'evoker'
|
7
|
+
require 'rake/clean'
|
8
|
+
|
9
|
+
module Evoker
|
10
|
+
smart_const(:cache_path, 'cache')
|
11
|
+
|
12
|
+
module_function
|
13
|
+
|
14
|
+
# Download a file using wget, or copy it from local cache
|
15
|
+
#
|
16
|
+
# @param [#to_s] url address to download from
|
17
|
+
# @param [Hash] opts options (same as wget, + :checksum)
|
18
|
+
# @option opts [#to_s] :checksum sha256 sum of file to download
|
19
|
+
def cached_wget(url, opts={})
|
20
|
+
opts[:output_file] ||= begin
|
21
|
+
require 'uri'
|
22
|
+
URI.parse(url).path.split('/').last
|
23
|
+
end
|
24
|
+
|
25
|
+
cached_path_elts = []
|
26
|
+
cached_path_elts << smart_const_get(:cache_path)
|
27
|
+
cached_path_elts << opts[:checksum][0..1] if opts[:checksum]
|
28
|
+
cached_path_elts << opts[:checksum][2..3] if opts[:checksum]
|
29
|
+
cached_path_elts << File.basename(opts[:output_file])
|
30
|
+
cached_path = File.join(*cached_path_elts)
|
31
|
+
|
32
|
+
if File.exists?(cached_path)
|
33
|
+
if opts[:checksum] &&
|
34
|
+
Digest::SHA256.file(cached_path).hexdigest != opts[:checksum]
|
35
|
+
puts "WARN: checksum mismatch for cached #{File.basename(opts[:output_file])}, removing."
|
36
|
+
FileUtils::rm cached_path
|
37
|
+
else
|
38
|
+
# no checksum or checksum match, we can proceed
|
39
|
+
file opts[:output_file] do
|
40
|
+
FileUtils::cp cached_path, opts[:output_file]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
else
|
44
|
+
wget url, opts
|
45
|
+
# add caching after downloading
|
46
|
+
task opts[:output_file] do
|
47
|
+
if opts[:checksum] &&
|
48
|
+
Digest::SHA256.file(opts[:output_file]).hexdigest != opts[:checksum]
|
49
|
+
raise "Checksum mismatch for downloaded #{File.basename(opts[:output_file])}."
|
50
|
+
end
|
51
|
+
FileUtils::mkdir_p(File.dirname(cached_path))
|
52
|
+
FileUtils::cp opts[:output_file], cached_path
|
53
|
+
end
|
54
|
+
end
|
55
|
+
CLEAN << opts[:output_file]
|
56
|
+
CLOBBER << cached_path
|
57
|
+
|
58
|
+
file opts[:output_file]
|
59
|
+
end
|
60
|
+
end
|
data/lib/evoker/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: evoker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-04-15 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
16
|
-
requirement: &
|
16
|
+
requirement: &70170471088160 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: 0.9.2
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70170471088160
|
25
25
|
description: ! 'Evoker is an add-on to Rake to download and manage project''s external
|
26
26
|
|
27
27
|
dependencied, update them as needed, cache them, etc.
|
@@ -32,6 +32,7 @@ executables: []
|
|
32
32
|
extensions: []
|
33
33
|
extra_rdoc_files: []
|
34
34
|
files:
|
35
|
+
- lib/evoker/local_cache.rb
|
35
36
|
- lib/evoker/python.rb
|
36
37
|
- lib/evoker/s3cache.rb
|
37
38
|
- lib/evoker/version.rb
|