rbbt 1.1.5 → 1.1.6
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/rbbt/util/open.rb +30 -10
- data/lib/rbbt/util/rake.rb +152 -36
- metadata +2 -2
data/lib/rbbt/util/open.rb
CHANGED
@@ -15,6 +15,7 @@ module Open
|
|
15
15
|
end
|
16
16
|
|
17
17
|
class DirectoryNotFoundError < StandardError; end
|
18
|
+
class OpenURLError < StandardError; end
|
18
19
|
|
19
20
|
private
|
20
21
|
|
@@ -42,13 +43,13 @@ module Open
|
|
42
43
|
end
|
43
44
|
end
|
44
45
|
end
|
45
|
-
|
46
|
+
|
46
47
|
# Checks if +url+ is a remote file.
|
47
48
|
def self.remote(url)
|
48
49
|
url =~ /^(?:http|ssh|https|ftp):\/\//
|
49
50
|
end
|
50
51
|
|
51
|
-
|
52
|
+
|
52
53
|
# Checks if +url+ is a gzip file.
|
53
54
|
def self.gziped(url)
|
54
55
|
if remote(url)
|
@@ -58,14 +59,27 @@ module Open
|
|
58
59
|
end
|
59
60
|
end
|
60
61
|
|
62
|
+
|
63
|
+
@@last_time = Time.now
|
64
|
+
def self.wait(lag = 0)
|
65
|
+
time = Time.now
|
66
|
+
|
67
|
+
if time < @@last_time + lag
|
68
|
+
sleep @@last_time + lag - time
|
69
|
+
end
|
70
|
+
|
71
|
+
@@last_time = Time.now
|
72
|
+
end
|
73
|
+
|
61
74
|
public
|
62
75
|
# Reads the file specified by url. If the url es local it just opens
|
63
76
|
# the file, if it is remote if checks the cache first. In any case, it
|
64
77
|
# unzips gzip files automatically.
|
65
78
|
#
|
66
79
|
# Options:
|
67
|
-
# * :quiet
|
80
|
+
# * :quiet => Do not print the progress of downloads
|
68
81
|
# * :nocache => do not use the cache.
|
82
|
+
# * :nice => secconds to wait between online queries
|
69
83
|
#
|
70
84
|
def self.read(url, options = {})
|
71
85
|
|
@@ -75,18 +89,24 @@ module Open
|
|
75
89
|
return data
|
76
90
|
end
|
77
91
|
|
92
|
+
wait(options[:nice]) if options[:nice]
|
78
93
|
tmp = TmpFile.tmp_file("open-")
|
79
94
|
`wget -O #{tmp} '#{url}' #{options[:quiet] ? '-q' : '' }`
|
80
|
-
if gziped(url)
|
81
|
-
`mv #{tmp} #{tmp}.gz; gunzip #{tmp}`
|
82
|
-
end
|
83
95
|
|
96
|
+
if $!.success?
|
97
|
+
if gziped(url)
|
98
|
+
`mv #{tmp} #{tmp}.gz; gunzip #{tmp}`
|
99
|
+
end
|
84
100
|
|
85
|
-
|
101
|
+
cache(url, File.open(tmp){|file| file.read}) unless options[:nocache]
|
86
102
|
|
87
|
-
|
88
|
-
|
89
|
-
|
103
|
+
data = File.open(tmp){|file| file.read}
|
104
|
+
FileUtils.rm tmp
|
105
|
+
return data
|
106
|
+
else
|
107
|
+
raise OpenURLError, "Error reading remote url: #{ url }"
|
108
|
+
end
|
109
|
+
|
90
110
|
when IO === url
|
91
111
|
url.read
|
92
112
|
else
|
data/lib/rbbt/util/rake.rb
CHANGED
@@ -1,67 +1,183 @@
|
|
1
1
|
require 'rake'
|
2
2
|
|
3
|
+
# Include the step_def and step methods to simplify Pipelines. Steps depend on
|
4
|
+
# the step strictly above by default. The output of the step is save marshaled,
|
5
|
+
# except for Strings which are save as text. The input of the step, the output
|
6
|
+
# of the previous step if availabe is accessed with the input method
|
7
|
+
#
|
8
|
+
# Example::
|
9
|
+
#
|
10
|
+
# step :text do
|
11
|
+
# "Text to revert"
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# step :revert do
|
15
|
+
# text = input
|
16
|
+
# text.reverse
|
17
|
+
# end
|
18
|
+
#
|
3
19
|
module Rake::Pipeline
|
4
20
|
|
5
|
-
|
6
|
-
|
21
|
+
module Rake::Pipeline::Step
|
22
|
+
|
23
|
+
class << self
|
24
|
+
|
25
|
+
@@step_descriptions = {}
|
26
|
+
def step_descriptions
|
27
|
+
@@step_descriptions
|
28
|
+
end
|
29
|
+
|
30
|
+
def add_description(re, step, message)
|
31
|
+
@@step_descriptions[re] = "#{ step }: #{ message }"
|
32
|
+
end
|
33
|
+
|
34
|
+
@@last_step = nil
|
35
|
+
def step_def(name, dependencies = nil)
|
36
|
+
|
37
|
+
re = Regexp.new(/(?:^|\/)#{name}\/.*$/)
|
38
|
+
|
39
|
+
# Take the last_description and associate it with the name
|
40
|
+
if Rake.application.last_description
|
41
|
+
add_description(re, name, Rake.application.last_description)
|
42
|
+
end
|
43
|
+
|
44
|
+
if dependencies.nil? && ! @@last_step.nil?
|
45
|
+
dependencies = @@last_step
|
46
|
+
end
|
47
|
+
@@last_step = name
|
48
|
+
|
49
|
+
# Generate the Hash definition
|
50
|
+
case
|
51
|
+
when dependencies.nil?
|
52
|
+
re
|
53
|
+
when String === dependencies || Symbol === dependencies
|
54
|
+
{re => lambda{|filename| filename.sub(name.to_s,dependencies.to_s) }}
|
55
|
+
when Array === dependencies
|
56
|
+
{re => lambda{|filename| dependencies.collect{|dep| filename.sub(name.to_s, dep.to_s) } }}
|
57
|
+
when Proc === dependencies
|
58
|
+
{re => dependencies}
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
module Rake::Pipeline::Info
|
67
|
+
|
68
|
+
def self.info_file(filename)
|
69
|
+
filename.sub(/^(.*?)(?:[^\/]*)\/([^\/]*)$/, '\1.info/\2.yaml')
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.load_info(t)
|
73
|
+
filename = t.name
|
74
|
+
info_filename = info_file(filename)
|
75
|
+
|
76
|
+
if File.exists? info_filename
|
77
|
+
YAML.load(File.open(info_filename))
|
78
|
+
else
|
79
|
+
{}
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.save_info(t, info = {})
|
84
|
+
filename = t.name
|
85
|
+
info_filename = info_file(filename)
|
86
|
+
|
87
|
+
FileUtils.mkdir_p File.dirname(info_filename) unless File.exists? File.dirname(info_filename)
|
88
|
+
File.open(info_filename,'w'){|file|
|
89
|
+
file.write YAML.dump info
|
90
|
+
}
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
|
96
|
+
NON_ASCII_PRINTABLE = /[^\x20-\x7e\s]/
|
97
|
+
def is_binary?(file)
|
98
|
+
binary = file.read(1024) =~ NON_ASCII_PRINTABLE
|
99
|
+
file.rewind
|
100
|
+
binary
|
7
101
|
end
|
8
102
|
|
9
103
|
def step_descriptions
|
10
104
|
Rake::Pipeline::Step.step_descriptions
|
11
105
|
end
|
12
106
|
|
107
|
+
|
108
|
+
def step_def(*args)
|
109
|
+
Rake::Pipeline::Step.step_def(*args)
|
110
|
+
end
|
111
|
+
|
13
112
|
def infile(t, &block)
|
14
|
-
File.open(t.prerequisites.first)do |f|
|
113
|
+
File.open(t.prerequisites.first) do |f|
|
15
114
|
block.call(f)
|
16
115
|
end
|
17
116
|
end
|
18
117
|
|
19
118
|
def outfile(t, &block)
|
20
|
-
File.open(t.name, 'w')do |f|
|
119
|
+
File.open(t.name, 'w') do |f|
|
21
120
|
block.call(f)
|
22
121
|
end
|
23
122
|
end
|
24
123
|
|
124
|
+
def load_input(t)
|
125
|
+
return nil if t.prerequisites.first.nil?
|
126
|
+
infile(t){|f|
|
127
|
+
if is_binary?(f)
|
128
|
+
Marshal.load(f)
|
129
|
+
else
|
130
|
+
f.read
|
131
|
+
end
|
132
|
+
}
|
133
|
+
end
|
25
134
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
def add_description(re, step, message)
|
37
|
-
@@step_descriptions[re] = "#{ step }: #{ message }"
|
135
|
+
def save_output(t, output)
|
136
|
+
case
|
137
|
+
when output.nil?
|
138
|
+
nil
|
139
|
+
when String === output
|
140
|
+
outfile(t){|f| f.write output }
|
141
|
+
else
|
142
|
+
outfile(t){|f| f.write Marshal.dump(output) }
|
38
143
|
end
|
39
144
|
|
40
|
-
|
145
|
+
end
|
41
146
|
|
42
|
-
|
43
|
-
re = Regexp.new(/#{name}\/.*/)
|
44
|
-
|
45
|
-
# Take the last_description and associate it with the name
|
46
|
-
if Rake.application.last_description
|
47
|
-
add_description(re, name, Rake.application.last_description)
|
48
|
-
end
|
147
|
+
# We cannot load the input variable before the block.call, so we need another method
|
49
148
|
|
149
|
+
# Load the input data from the previous step
|
150
|
+
def input
|
151
|
+
load_input(@@current_task) if @@current_task
|
152
|
+
end
|
50
153
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
when Array === dependencies
|
58
|
-
{re => lambda{|filename| dependencies.collect{|dep| filename.sub(name.to_s, dep.to_s) } }}
|
59
|
-
when Proc === dependencies
|
60
|
-
{re => dependencies}
|
61
|
-
end
|
62
|
-
end
|
154
|
+
# Add values to the info file
|
155
|
+
def info(values = {})
|
156
|
+
info = Rake::Pipeline::Info.load_info(@@current_task)
|
157
|
+
info = info.merge values
|
158
|
+
Rake::Pipeline::Info.save_info(@@current_task, info)
|
159
|
+
info
|
63
160
|
end
|
161
|
+
|
162
|
+
|
163
|
+
# Define a new step, it depends on the previously defined by default. It
|
164
|
+
# saves the output of the block so it can be loaded by the input method of
|
165
|
+
# the next step
|
166
|
+
def step(name, dependencies = nil, &block)
|
167
|
+
rule step_def(name, dependencies) do |t|
|
168
|
+
|
169
|
+
# Save the task object to be able to load the input
|
170
|
+
@@current_task = t
|
171
|
+
|
172
|
+
output = block.call(t)
|
173
|
+
|
174
|
+
save_output(t, output)
|
175
|
+
end
|
64
176
|
|
177
|
+
end
|
65
178
|
end
|
66
179
|
|
180
|
+
if __FILE__ == $0
|
67
181
|
|
182
|
+
p Rake::Pipeline::Info.info_file('work/diseases/t')
|
183
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rbbt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Miguel Vazquez
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-12-
|
12
|
+
date: 2009-12-31 00:00:00 +01:00
|
13
13
|
default_executable: rbbt_config
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|