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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fea2c562a8e3611c8c9767589ec160a36c1b988d
4
- data.tar.gz: 42c868b4354a14c64c9eb5ea45b4d447c3d1c757
3
+ metadata.gz: b59e7f300db3c25c5e9cd000c369f0ccae3b96e3
4
+ data.tar.gz: 8a4fd1ba66536df107ae3d23426c79b60801a080
5
5
  SHA512:
6
- metadata.gz: c85bd1f0ed345e6277daed12a41145134f81914e5d1b678db4676296dcb9a8e1ae1bc66c0b3dcc866dc9cab1ebcb80d50cb7181f4e71d755ecb721e3dffa9f55
7
- data.tar.gz: fd38d3d2ef666f8b8b4eae6ce66b8ce45b8c5cb6a57e3bbc28c2900f239495a9f991080026e09dc7fbaca480518095e426f482afcc104d07f656835b80509bf2
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
- Marshal.load(Open.open(path))
113
+ Open.open(path) do |stream|
114
+ Marshal.load(stream)
115
+ end
114
116
  when :yaml
115
- YAML.load(Open.open(path))
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
@@ -53,7 +53,7 @@ module Misc
53
53
  len = Log.uncolor(dt).length
54
54
 
55
55
  if indent < 0
56
- text = format_paragraph(dd, size, indent.abs+1, 0)
56
+ text = format_paragraph(dd, size, indent.abs-1, 0)
57
57
  text = dt << "\n" << text
58
58
  else
59
59
  offset = len - indent
@@ -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
@@ -161,16 +161,30 @@ module Misc
161
161
  str
162
162
  end
163
163
 
164
- def self.consume_stream(io)
165
- return unless io.respond_to? :read
166
- begin
167
- while block = io.read(2048)
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
- rescue
173
- io.abort if io.respond_to? :abort
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
@@ -3,6 +3,7 @@ require 'rbbt/workflow/task'
3
3
  require 'rbbt/workflow/step'
4
4
  require 'rbbt/workflow/accessor'
5
5
  require 'rbbt/workflow/doc'
6
+ require 'rbbt/workflow/examples'
6
7
 
7
8
  module Workflow
8
9
 
@@ -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
@@ -75,31 +75,26 @@ module Workflow
75
75
 
76
76
  task.doc(dependencies)
77
77
 
78
- if self.libdir.examples[task_name].exists?
79
- self.libdir.examples[task_name].glob("*").each do |example_dir|
80
- example = File.basename(example_dir)
81
-
82
- puts Log.color(:magenta, "Example " << example) + " -- " + Log.color(:blue, example_dir)
83
-
84
- inputs = {}
85
-
86
- task.input_types.each do |input,type|
87
- if example_dir[input].exists?
88
- case type
89
- when :tsv, :array, :text
90
- head = example_dir[input].read.split("\n")[0..5].compact * "\n\n"
91
- head = head[0..500]
92
- puts Misc.format_definition_list_item(input, head).gsub("\n\n","\n")
93
- else
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.0
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-15 00:00:00.000000000 Z
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