evoker 0.0.8 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/evoker.rb +3 -2
- data/lib/evoker/local_cache.rb +67 -30
- data/lib/evoker/version.rb +10 -1
- metadata +5 -4
data/lib/evoker.rb
CHANGED
@@ -21,6 +21,7 @@ module Evoker
|
|
21
21
|
# task :default => Evoker::ENTITIES
|
22
22
|
ENTITIES = Rake::FileList[]
|
23
23
|
|
24
|
+
# Specialized task class for downloaded entities
|
24
25
|
class EntityTask < Rake::FileTask
|
25
26
|
##
|
26
27
|
# Parsed yaml config for the task
|
@@ -209,10 +210,10 @@ module Evoker
|
|
209
210
|
# Get smart constant's effective value
|
210
211
|
#
|
211
212
|
# Effective value is:
|
212
|
-
# 1.
|
213
|
+
# 1. +name.to_s.upcase+ environment variable, if present
|
213
214
|
# 2. Otherwise, user-defined top-level constant named `name.to_s.upcase`
|
214
215
|
# 3. Otherwise, default set with {smart_const}
|
215
|
-
# 4. Otherwise, nil
|
216
|
+
# 4. Otherwise, +nil+
|
216
217
|
#
|
217
218
|
# @param name [#to_s] constant's name
|
218
219
|
def smart_const_get(name)
|
data/lib/evoker/local_cache.rb
CHANGED
@@ -11,50 +11,87 @@ module Evoker
|
|
11
11
|
|
12
12
|
module_function
|
13
13
|
|
14
|
-
#
|
14
|
+
# Cache result of a file task in local directory.
|
15
|
+
#
|
16
|
+
# If cached `output_file` exists and matches the checksum (if one is
|
17
|
+
# given), task to copy file from cache directory to target is
|
18
|
+
# returned, and block is not executed.
|
15
19
|
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
# If cached `output_file` exists but does not match the checksum, it is
|
21
|
+
# removed.
|
22
|
+
#
|
23
|
+
# If `output file` does not exist or did not match the checksum,
|
24
|
+
# block is executed. Block should return a file task. This task will
|
25
|
+
# have extra code appended:
|
26
|
+
#
|
27
|
+
# - a checksum test: if checksum is given - error is raised if
|
28
|
+
# created file does not match the checksum
|
29
|
+
# - copying created file to cache directory
|
30
|
+
#
|
31
|
+
# Cache directory is taken from a smart constant (see
|
32
|
+
# {#smart_const_get}) `:cache_path`, default is 'cache'.
|
33
|
+
#
|
34
|
+
# @param [String] output_file File to uncache or create
|
35
|
+
# @param [String] checksum SHA-256 checksum of file (optional, but recommended)
|
36
|
+
# @yield Task to create file if not found in cache
|
37
|
+
# @return Task to uncache or create file
|
38
|
+
def cached(output_file, checksum=nil)
|
39
|
+
raise 'Block for Evoker::cached not provided' unless block_given?
|
24
40
|
|
25
41
|
cached_path_elts = []
|
26
42
|
cached_path_elts << smart_const_get(:cache_path)
|
27
|
-
cached_path_elts <<
|
28
|
-
cached_path_elts <<
|
29
|
-
cached_path_elts << File.basename(
|
43
|
+
cached_path_elts << checksum[0..1] if checksum
|
44
|
+
cached_path_elts << checksum[2..3] if checksum
|
45
|
+
cached_path_elts << File.basename(output_file)
|
30
46
|
cached_path = File.join(*cached_path_elts)
|
31
47
|
|
48
|
+
if File.exists?(cached_path) &&
|
49
|
+
checksum &&
|
50
|
+
Digest::SHA256.file(cached_path).hexdigest != checksum
|
51
|
+
puts "WARN: checksum mismatch for cached #{File.basename(output_file)}, removing."
|
52
|
+
FileUtils::rm cached_path
|
53
|
+
end
|
54
|
+
|
32
55
|
if File.exists?(cached_path)
|
33
|
-
|
34
|
-
|
35
|
-
|
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
|
56
|
+
# Cached file exists and matches the given checksum
|
57
|
+
rv = file output_file do
|
58
|
+
FileUtils::cp cached_path, output_file
|
42
59
|
end
|
43
60
|
else
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
61
|
+
# Cached file does not exist
|
62
|
+
rv = yield output_file
|
63
|
+
|
64
|
+
# Cache file after downloading
|
65
|
+
task rv do
|
66
|
+
if checksum &&
|
67
|
+
Digest::SHA256.file(output_file).hexdigest != checksum
|
68
|
+
raise "Checksum mismatch for downloaded #{File.basename(output_file)}."
|
50
69
|
end
|
51
70
|
FileUtils::mkdir_p(File.dirname(cached_path))
|
52
|
-
FileUtils::cp
|
71
|
+
FileUtils::cp output_file, cached_path
|
53
72
|
end
|
54
73
|
end
|
55
|
-
|
74
|
+
|
75
|
+
CLEAN << output_file
|
56
76
|
CLOBBER << cached_path
|
57
77
|
|
58
|
-
|
78
|
+
rv
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
# Download a file using wget, or copy it from local cache
|
83
|
+
#
|
84
|
+
# @param [#to_s] url address to download from
|
85
|
+
# @param [Hash] opts options (same as wget, + :checksum)
|
86
|
+
# @option opts [#to_s] :checksum sha256 sum of file to download
|
87
|
+
def cached_wget(url, opts={})
|
88
|
+
opts[:output_file] ||= begin
|
89
|
+
require 'uri'
|
90
|
+
URI.parse(url).path.split('/').last
|
91
|
+
end
|
92
|
+
|
93
|
+
cached(opts[:output_file], opts[:checksum]) do
|
94
|
+
wget url, opts
|
95
|
+
end
|
59
96
|
end
|
60
97
|
end
|
data/lib/evoker/version.rb
CHANGED
@@ -1,10 +1,19 @@
|
|
1
1
|
module Evoker
|
2
|
+
# Version information
|
2
3
|
module VERSION
|
4
|
+
# Major version number
|
3
5
|
MAJOR = 0
|
6
|
+
|
7
|
+
# Minor version number
|
4
8
|
MINOR = 0
|
5
|
-
|
9
|
+
|
10
|
+
# Tiny version number
|
11
|
+
TINY = 9
|
12
|
+
|
13
|
+
# Full version number as string
|
6
14
|
STRING = [MAJOR, MINOR, TINY].join('.')
|
7
15
|
|
16
|
+
# Raise an error if Evoker version is older than required.
|
8
17
|
def VERSION.require_version(major, minor=0, tiny=0)
|
9
18
|
unless ([MAJOR, MINOR, TINY] <=> [major, minor, tiny]) >= 0
|
10
19
|
raise "Evoker version #{MAJOR}.#{MINOR}.#{TINY} is below required #{major}.#{minor}.#{tiny}"
|
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.9
|
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-05-03 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
16
|
-
requirement: &
|
16
|
+
requirement: &70142202183640 !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: *70142202183640
|
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.
|
@@ -64,3 +64,4 @@ signing_key:
|
|
64
64
|
specification_version: 3
|
65
65
|
summary: Rake add-on to download and manage project's external dependencies
|
66
66
|
test_files: []
|
67
|
+
has_rdoc:
|