rbbt-util 5.12.0 → 5.12.1
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.
- checksums.yaml +4 -4
- data/lib/rbbt/persist.rb +6 -2
- data/lib/rbbt/tsv/parallel/traverse.rb +8 -0
- data/lib/rbbt/tsv/util.rb +8 -0
- data/lib/rbbt/util/misc/format.rb +1 -1
- data/lib/rbbt/util/misc/inspect.rb +0 -10
- data/lib/rbbt/util/misc/pipes.rb +23 -11
- data/lib/rbbt/util/misc/system.rb +10 -0
- data/lib/rbbt/workflow.rb +1 -0
- data/lib/rbbt/workflow/accessor.rb +2 -24
- data/lib/rbbt/workflow/examples.rb +68 -0
- data/lib/rbbt/workflow/usage.rb +17 -22
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b59e7f300db3c25c5e9cd000c369f0ccae3b96e3
|
4
|
+
data.tar.gz: 8a4fd1ba66536df107ae3d23426c79b60801a080
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f4720ab8616fd717fd8d945bed47cfb579b7bf524cd83630b5eb7bdb2fcd4f2058a83b156448001be3dbc488058ce147efd2e14e7bcc866b5c207776b07d39e
|
7
|
+
data.tar.gz: f47fffb35b77b270b0a02e1fda74e67d1cc6fd4b67e7cc12ba0881b679fd5a2478cb2e01ea08bcd4e2766df5becbd21f1054fd60998aa6127ce3ea374c1fec61
|
data/lib/rbbt/persist.rb
CHANGED
@@ -110,9 +110,13 @@ module Persist
|
|
110
110
|
res.pop
|
111
111
|
res
|
112
112
|
when :marshal
|
113
|
-
|
113
|
+
Open.open(path) do |stream|
|
114
|
+
Marshal.load(stream)
|
115
|
+
end
|
114
116
|
when :yaml
|
115
|
-
|
117
|
+
Open.open(path) do |stream|
|
118
|
+
YAML.load(stream)
|
119
|
+
end
|
116
120
|
when :float
|
117
121
|
Open.read(path).to_f
|
118
122
|
when :integer
|
@@ -152,6 +152,14 @@ module TSV
|
|
152
152
|
end
|
153
153
|
when Array
|
154
154
|
traverse_array(obj, options, &block)
|
155
|
+
when String
|
156
|
+
if Open.remote? obj or Misc.is_filename? obj
|
157
|
+
Open.open(obj) do |s|
|
158
|
+
traverse_obj(s, options, &block)
|
159
|
+
end
|
160
|
+
else
|
161
|
+
raise "Can not open obj for traversal #{Misc.fingerprint obj}"
|
162
|
+
end
|
155
163
|
when nil
|
156
164
|
raise "Can not traverse nil object into #{stream_name(options)}"
|
157
165
|
else
|
data/lib/rbbt/tsv/util.rb
CHANGED
@@ -69,6 +69,8 @@ module TSV
|
|
69
69
|
|
70
70
|
def self.get_filename(file)
|
71
71
|
case
|
72
|
+
when (defined? Step and Step === file)
|
73
|
+
file.path
|
72
74
|
when String === file
|
73
75
|
file
|
74
76
|
when file.respond_to?(:filename)
|
@@ -112,6 +114,12 @@ module TSV
|
|
112
114
|
stream || get_stream(file.join.path)
|
113
115
|
when TSV::Dumper
|
114
116
|
file.stream
|
117
|
+
when Array
|
118
|
+
Misc.open_pipe do |sin|
|
119
|
+
file.each do |l|
|
120
|
+
sin.puts l
|
121
|
+
end
|
122
|
+
end
|
115
123
|
else
|
116
124
|
raise "Cannot get stream from: #{file.inspect}"
|
117
125
|
end
|
@@ -105,16 +105,6 @@ module Misc
|
|
105
105
|
end
|
106
106
|
end
|
107
107
|
|
108
|
-
def self.filename?(string)
|
109
|
-
String === string and string.length > 0 and string.length < 250 and File.exists?(string)
|
110
|
-
end
|
111
|
-
|
112
|
-
def self.is_filename?(string)
|
113
|
-
return true if string.respond_to? :exists
|
114
|
-
return true if String === string and string.length < 265 and File.exists? string
|
115
|
-
return false
|
116
|
-
end
|
117
|
-
|
118
108
|
def self.digest(text)
|
119
109
|
Digest::MD5.hexdigest(text)
|
120
110
|
end
|
data/lib/rbbt/util/misc/pipes.rb
CHANGED
@@ -161,16 +161,30 @@ module Misc
|
|
161
161
|
str
|
162
162
|
end
|
163
163
|
|
164
|
-
def self.consume_stream(io)
|
165
|
-
return
|
166
|
-
|
167
|
-
|
168
|
-
return if io.eof?
|
169
|
-
Thread.pass
|
170
|
-
end
|
164
|
+
def self.consume_stream(io, in_thread = false)
|
165
|
+
return if Path === io
|
166
|
+
return unless io.respond_to? :read
|
167
|
+
if io.respond_to? :closed? and io.closed?
|
171
168
|
io.join if io.respond_to? :join
|
172
|
-
|
173
|
-
|
169
|
+
return
|
170
|
+
end
|
171
|
+
if in_thread
|
172
|
+
Thread.new do
|
173
|
+
consume_stream(io, false)
|
174
|
+
end
|
175
|
+
else
|
176
|
+
begin
|
177
|
+
while block = io.read(2048)
|
178
|
+
return if io.eof?
|
179
|
+
Thread.pass
|
180
|
+
end
|
181
|
+
io.join if io.respond_to? :join
|
182
|
+
rescue
|
183
|
+
Log.error "Exception consuming stream: #{io.inspect}"
|
184
|
+
ddd caller
|
185
|
+
Log.exception $!
|
186
|
+
io.abort if io.respond_to? :abort
|
187
|
+
end
|
174
188
|
end
|
175
189
|
end
|
176
190
|
|
@@ -316,7 +330,6 @@ module Misc
|
|
316
330
|
end
|
317
331
|
sizes = parts.collect{|p| p.length }
|
318
332
|
last_min = nil
|
319
|
-
count ||= 0
|
320
333
|
while lines.compact.any?
|
321
334
|
min = keys.compact.sort.first
|
322
335
|
str = []
|
@@ -334,7 +347,6 @@ module Misc
|
|
334
347
|
parts[i] = p
|
335
348
|
end
|
336
349
|
else
|
337
|
-
count += 1
|
338
350
|
str << [sep * (sizes[i]-1)] if sizes[i] > 0
|
339
351
|
end
|
340
352
|
end
|
@@ -87,4 +87,14 @@ end
|
|
87
87
|
res
|
88
88
|
end
|
89
89
|
|
90
|
+
def self.filename?(string)
|
91
|
+
String === string and string.length > 0 and string.length < 250 and File.exists?(string)
|
92
|
+
end
|
93
|
+
|
94
|
+
def self.is_filename?(string)
|
95
|
+
return true if string.respond_to? :exists
|
96
|
+
return true if String === string and string.length < 265 and File.exists? string
|
97
|
+
return false
|
98
|
+
end
|
99
|
+
|
90
100
|
end
|
data/lib/rbbt/workflow.rb
CHANGED
@@ -250,7 +250,8 @@ class Step
|
|
250
250
|
when :tsv
|
251
251
|
TSV.open Open.open(file(name)), options
|
252
252
|
when :array
|
253
|
-
Open.read(file(name)).split /\n|,\s*/
|
253
|
+
#Open.read(file(name)).split /\n|,\s*/
|
254
|
+
Open.read(file(name)).split "\n"
|
254
255
|
when :yaml
|
255
256
|
YAML.load(Open.open(file(name)))
|
256
257
|
when :marshal
|
@@ -284,29 +285,6 @@ end
|
|
284
285
|
|
285
286
|
module Workflow
|
286
287
|
|
287
|
-
def self.load_inputs(dir, input_names, input_types)
|
288
|
-
inputs = {}
|
289
|
-
dir = Path.setup(dir.dup)
|
290
|
-
input_names.each do |input|
|
291
|
-
file = dir[input].find
|
292
|
-
Log.debug "Trying #{ input }: #{file}"
|
293
|
-
next unless file.exists?
|
294
|
-
|
295
|
-
case input_types[input]
|
296
|
-
when :tsv, :array, :text
|
297
|
-
Log.debug "Pointing #{ input } to #{file}"
|
298
|
-
inputs[input.to_sym] = file
|
299
|
-
when :boolean
|
300
|
-
inputs[input.to_sym] = (file.read.strip == 'true')
|
301
|
-
else
|
302
|
-
Log.debug "Loading #{ input } from #{file}"
|
303
|
-
inputs[input.to_sym] = file.read.strip
|
304
|
-
end
|
305
|
-
|
306
|
-
end
|
307
|
-
IndiferentHash.setup(inputs)
|
308
|
-
end
|
309
|
-
|
310
288
|
def log(status, message = nil, &block)
|
311
289
|
Step.log(status, message, nil, &block)
|
312
290
|
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module Workflow
|
2
|
+
attr_accessor :example_dir
|
3
|
+
|
4
|
+
def example_dir
|
5
|
+
@example_dir ||= self.libdir.examples
|
6
|
+
end
|
7
|
+
|
8
|
+
def examples
|
9
|
+
return {} unless self.libdir.examples.exists?
|
10
|
+
examples = {}
|
11
|
+
example_dir.glob("*/*").each do |example_dir|
|
12
|
+
example = File.basename(example_dir)
|
13
|
+
task_name = File.basename(File.dirname(example_dir))
|
14
|
+
examples[task_name] ||= []
|
15
|
+
examples[task_name] << example
|
16
|
+
end
|
17
|
+
IndiferentHash.setup examples
|
18
|
+
examples
|
19
|
+
end
|
20
|
+
|
21
|
+
def example(task_name, example)
|
22
|
+
tasks[task_name.to_sym].input_types.collect do |input,type|
|
23
|
+
next unless example_dir[task_name][example][input].exists?
|
24
|
+
[input, type, example_dir[task_name][example][input].find]
|
25
|
+
end.compact
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.load_inputs(dir, input_names, input_types)
|
29
|
+
inputs = {}
|
30
|
+
dir = Path.setup(dir.dup)
|
31
|
+
input_names.each do |input|
|
32
|
+
file = dir[input].find
|
33
|
+
Log.debug "Trying #{ input }: #{file}"
|
34
|
+
next unless file.exists?
|
35
|
+
|
36
|
+
case input_types[input]
|
37
|
+
when :tsv, :array, :text
|
38
|
+
Log.debug "Pointing #{ input } to #{file}"
|
39
|
+
inputs[input.to_sym] = file
|
40
|
+
when :boolean
|
41
|
+
inputs[input.to_sym] = (file.read.strip == 'true')
|
42
|
+
else
|
43
|
+
Log.debug "Loading #{ input } from #{file}"
|
44
|
+
inputs[input.to_sym] = file.read.strip
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
IndiferentHash.setup(inputs)
|
49
|
+
end
|
50
|
+
|
51
|
+
def example_step(task_name, example)
|
52
|
+
inputs = {}
|
53
|
+
example(task_name, example).each do |input,type,file|
|
54
|
+
|
55
|
+
case type
|
56
|
+
when :tsv, :array, :text
|
57
|
+
Log.debug "Pointing #{ input } to #{file}"
|
58
|
+
inputs[input.to_sym] = file
|
59
|
+
when :boolean
|
60
|
+
inputs[input.to_sym] = (file.read.strip == 'true')
|
61
|
+
else
|
62
|
+
Log.debug "Loading #{ input } from #{file}"
|
63
|
+
inputs[input.to_sym] = file.read.strip
|
64
|
+
end
|
65
|
+
end
|
66
|
+
Sequence.job(task_name, example, inputs)
|
67
|
+
end
|
68
|
+
end
|
data/lib/rbbt/workflow/usage.rb
CHANGED
@@ -75,31 +75,26 @@ module Workflow
|
|
75
75
|
|
76
76
|
task.doc(dependencies)
|
77
77
|
|
78
|
-
if self.
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
puts Misc.format_definition_list_item(input, example_dir[input].read)
|
95
|
-
end
|
78
|
+
if self.examples.include? task_name
|
79
|
+
self.examples[task_name].each do |example|
|
80
|
+
|
81
|
+
puts Log.color(:magenta, "Example " << example) + " -- " + Log.color(:blue, example_dir[task_name][example])
|
82
|
+
|
83
|
+
inputs = self.example(task_name, example)
|
84
|
+
|
85
|
+
inputs.each do |input, type, file|
|
86
|
+
case type
|
87
|
+
when :tsv, :array, :text
|
88
|
+
head = file.read.split("\n")[0..5].compact * "\n\n"
|
89
|
+
head = head[0..500]
|
90
|
+
puts Misc.format_definition_list_item(input, head, 100, -1).gsub(/\n\s*\n/,"\n")
|
91
|
+
else
|
92
|
+
puts Misc.format_definition_list_item(input, file.read)
|
93
|
+
end
|
96
94
|
end
|
95
|
+
puts
|
97
96
|
end
|
98
|
-
|
99
|
-
puts
|
100
97
|
end
|
101
|
-
|
102
98
|
end
|
103
|
-
end
|
104
99
|
end
|
105
100
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rbbt-util
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.12.
|
4
|
+
version: 5.12.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Miguel Vazquez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -207,6 +207,7 @@ files:
|
|
207
207
|
- lib/rbbt/workflow/annotate.rb
|
208
208
|
- lib/rbbt/workflow/definition.rb
|
209
209
|
- lib/rbbt/workflow/doc.rb
|
210
|
+
- lib/rbbt/workflow/examples.rb
|
210
211
|
- lib/rbbt/workflow/soap.rb
|
211
212
|
- lib/rbbt/workflow/step.rb
|
212
213
|
- lib/rbbt/workflow/step/run.rb
|