flor 0.9.2 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
  # flor CHANGELOG.md
3
3
 
4
4
 
5
+ ## flor 0.9.3 released 2017-02-07
6
+
7
+ - Rename the head 'tasker' as 'ganger'
8
+ - Allow for (tasker, conf, message) ruby taskers
9
+
10
+
5
11
  ## flor 0.9.2 released 2017-02-03
6
12
 
7
13
  - Allow for domain taskers (retasking)
data/Makefile CHANGED
@@ -18,6 +18,10 @@ gemspec_validate:
18
18
  name: gemspec_validate
19
19
  @echo "$(NAME) $(VERSION)"
20
20
 
21
+ syncver:
22
+ sed -E -i '' "s/VERSION = ['0-9.]+/VERSION = '$(shell grep -E "$(NAME) ([0-9.]+)" CHANGELOG.md | head -1 | sed -E 's/[^0-9\.]//g')'/" lib/$(NAME).rb
23
+ bundle install
24
+
21
25
  build: gemspec_validate
22
26
  gem build $(NAME).gemspec
23
27
  mkdir -p pkg
data/fail.txt CHANGED
@@ -1,7 +1,16 @@
1
-
2
- rspec ./spec/pcore/cursor_spec.rb:184 # Flor pcore cursor re-break/continue accepts "break" when breaking
3
- rspec ./spec/pcore/cursor_spec.rb:230 # Flor pcore cursor re-break/continue accepts "break" when continuing
4
- rspec ./spec/pcore/cursor_spec.rb:282 # Flor pcore cursor re-break/continue accepts "break" when continuing (nest-1)
5
- rspec ./spec/pcore/cursor_spec.rb:327 # Flor pcore cursor re-break/continue rejects "continue" when breaking
6
- rspec ./spec/pcore/cursor_spec.rb:371 # Flor pcore cursor re-break/continue rejects "move" when breaking
7
-
1
+ rspec ./spec/conf_spec.rb:35 # Flor::Conf.read fails when it cannot parse
2
+ rspec ./spec/core/on_error_spec.rb:33 # Flor core the on_error: attribute fails if the handler does not exist
3
+ rspec ./spec/core/on_error_spec.rb:46 # Flor core the on_error: attribute triggers when a child has an error
4
+ rspec ./spec/core/on_error_spec.rb:61 # Flor core the on_error: attribute accepts the name of a function
5
+ rspec ./spec/core/tags_spec.rb:116 # Flor core the tags attribute fails on non-string attributes
6
+ rspec ./spec/pcore/cmp_spec.rb:230 # Flor procedures < fails when arguments are not comparable
7
+ rspec ./spec/pcore/fail_spec.rb:20 # Flor procedures fail raises an error
8
+ rspec ./spec/pcore/fail_spec.rb:36 # Flor procedures fail raises an error when empty too
9
+ rspec ./spec/pcore/fail_spec.rb:55 # Flor procedures error is an alias to "fail"
10
+ rspec ./spec/pcore/move_spec.rb:22 # Flor pcore move fails if the target cannot be found
11
+ rspec ./spec/pcore/procedure_spec.rb:271 # Flor::Procedure status "closed" on-error #receive does not open the node
12
+ rspec ./spec/pcore/push_spec.rb:34 # Flor procedures push fails if it cannot push to the first child
13
+ rspec ./spec/pcore/set_spec.rb:79 # Flor procedures set fails when it cannot set a deep field
14
+ rspec ./spec/pcore/set_spec.rb:124 # Flor procedures set fails when it cannot set a deep variable
15
+ rspec ./spec/pcore/set_spec.rb:169 # Flor procedures set a sets locally if there is no a in the lookup chain
16
+ rspec ./spec/pcore/set_spec.rb:225 # Flor procedures set v.a sets locally if there is no a in the lookup chain
data/lib/flor.rb CHANGED
@@ -34,7 +34,7 @@ require 'raabro'
34
34
 
35
35
  module Flor
36
36
 
37
- VERSION = '0.9.2'
37
+ VERSION = '0.9.3'
38
38
  end
39
39
 
40
40
  require 'flor/colours'
data/lib/flor/colours.rb CHANGED
@@ -25,98 +25,47 @@
25
25
 
26
26
  module Flor
27
27
 
28
+ COLS = Hash[*%w[
29
+
30
+ reset 0;0
31
+ bright 1 dim 2 underlined 4 blink 5 reverse 7 hidden 8 default 39
32
+ black 30 red 31 green 32 yellow 33 blue 34 magenta 35 cyan 36
33
+ light_gray 37 dark_gray 90 light_red 91 light_green 92
34
+ light_yellow 93 light_blue 94 light_magenta 95 light_cyan 96 white 97
35
+ bg_default 49 bg_black 40 bg_red 41 bg_green 42 bg_yellow 43 bg_blue 44
36
+ bg_magenta 45 bg_cyan 46 bg_light_gray 47 bg_dark_gray 100
37
+ bg_light_red 101 bg_light_green 102 bg_light_yellow 103
38
+ bg_light_blue 104 bg_light_magenta 105 bg_light_cyan 106
39
+ bg_white 107
40
+
41
+ brown yellow purple magenta dark_grey dark_gray light_grey light_gray
42
+
43
+ rd red bl blue bu blue ba black bk black gn green gr green dg dark_gray
44
+ gy light_gray lg light_gray yl yellow ma magenta rs reset br bright
45
+ un underlined rv reverse bn blink blg bg_light_gray bri bright
46
+ und underlined rev reverse
47
+ ]]
48
+
28
49
  class Colours
29
50
 
30
- def reset; ""; end
31
-
32
- def bright; ""; end
33
- def dim; ""; end
34
- def underlined; ""; end
35
- def blink; ""; end
36
- def reverse; ""; end
37
- def hidden; ""; end
38
-
39
- def default; ""; end
40
- def black; ""; end
41
- def red; ""; end
42
- def green; ""; end
43
- def yellow; ""; end
44
- def blue; ""; end
45
- def magenta; ""; end
46
- def cyan; ""; end
47
- def light_gray; ""; end
48
-
49
- def dark_gray; ""; end
50
- def light_red; ""; end
51
- def light_green; ""; end
52
- def light_yellow; ""; end
53
- def light_blue; ""; end
54
- def light_magenta; ""; end
55
- def light_cyan; ""; end
56
- def white; ""; end
57
-
58
- def bg_default; ""; end
59
- def bg_black; ""; end
60
- def bg_red; ""; end
61
- def bg_green; ""; end
62
- def bg_yellow; ""; end
63
- def bg_blue; ""; end
64
- def bg_magenta; ""; end
65
- def bg_cyan; ""; end
66
- def bg_light_gray; ""; end
67
-
68
- def bg_dark_gray; ""; end
69
- def bg_light_red; ""; end
70
- def bg_light_green; ""; end
71
- def bg_light_yellow; ""; end
72
- def bg_light_blue; ""; end
73
- def bg_light_magenta; ""; end
74
- def bg_light_cyan; ""; end
75
- def bg_white; ""; end
76
-
77
- alias brown yellow
78
- alias purple magenta
79
- alias dark_grey dark_gray
80
- alias light_grey light_gray
81
-
82
- alias rd red
83
- alias bl blue
84
- alias bu blue
85
- alias ba black
86
- alias bk black
87
- alias gn green
88
- alias gr green
89
- alias dg dark_gray
90
- alias gy light_gray
91
- alias lg light_gray
92
- alias yl yellow
93
- alias ma magenta
94
-
95
- alias rs reset
96
- alias br bright
97
- alias un underlined
98
- alias rv reverse
99
- alias bn blink
100
-
101
- alias blg bg_light_gray
102
- alias bri bright
103
- alias und underlined
104
- alias rev reverse
51
+ Flor::COLS.each do |k, v|
52
+ if v.match(/\A\d/)
53
+ class_eval("def #{k}; \"[#{v}m\"; end")
54
+ else
55
+ class_eval("alias #{k} #{v}")
56
+ end
57
+ end
105
58
  end
106
59
 
107
- class NoColours < Colours
108
-
109
- %w[
110
- reset
111
- bright dim underlined blink reverse hidden
112
- default black red green yellow blue magenta cyan light_gray
113
- dark_gray light_red light_green light_yellow light_blue light_magenta
114
- light_cyan white
115
- bg_default bg_black bg_red bg_green bg_yellow bg_blue bg_magenta bg_cyan
116
- bg_light_gray
117
- bg_dark_gray bg_light_red bg_light_green bg_light_yellow bg_light_blue
118
- bg_light_magenta bg_light_cyan bg_white
119
- ].each { |m| define_method(m) { '' } }
60
+ class NoColours
61
+
62
+ Flor::COLS.each do |k, v|
63
+ if v.match(/\A\d/)
64
+ class_eval("def #{k}; ''; end")
65
+ else
66
+ class_eval("alias #{k} #{v}")
67
+ end
68
+ end
120
69
  end
121
70
 
122
71
  @colours = Colours.new
@@ -129,12 +78,14 @@ module Flor
129
78
 
130
79
  def self.colours(opts={})
131
80
 
132
- return @no_colours unless $stdout.tty?
81
+ return @colours if opts[:color] == true || opts[:colour] == true
82
+ return @no_colours if opts[:color] == false || opts[:colour] == false
133
83
 
134
- opts[:colour] = true unless opts.has_key?(:color) || opts.has_key?(:colour)
84
+ o = opts[:out] || $stdout
135
85
 
136
- return @colours if opts[:color] || opts[:colour]
137
- @no_colours
86
+ (o.respond_to?(:log_colours?) ? o.log_colours? : o.tty?) ?
87
+ @colours :
88
+ @no_colours
138
89
  end
139
90
  end
140
91
 
data/lib/flor/conf.rb CHANGED
@@ -61,8 +61,10 @@ module Flor
61
61
 
62
62
  def self.read_env
63
63
 
64
+ a =
65
+ (ENV['FLOR_DEBUG'] || '').split(',')
64
66
  h =
65
- (ENV['FLOR_DEBUG'] || '').split(',').inject({}) { |h, kv|
67
+ a.inject({}) { |h, kv|
66
68
  k, v = kv.split(':')
67
69
  k = 'sto' if k == 'db'
68
70
  k = "log_#{k}" if LOG_ALL_KEYS.include?(k)
@@ -72,6 +74,16 @@ module Flor
72
74
  LOG_ALL_KEYS.each { |k| h["log_#{k}"] = 1 } if h['log_all']
73
75
  LOG_DBG_KEYS.each { |k| h["log_#{k}"] = 1 } if h['log_dbg']
74
76
 
77
+ h['log_colours'] = true \
78
+ if a.include?('colours') || a.include?('colors')
79
+ # LOG_DEBUG=colours forces colors
80
+
81
+ if a.include?('stdout')
82
+ h['log_out'] = 'stdout'
83
+ elsif a.include?('stderr')
84
+ h['log_out'] = 'stderr'
85
+ end
86
+
75
87
  h
76
88
  end
77
89
 
@@ -340,7 +340,8 @@ module Flor
340
340
  m['fpoint'] = message['point']
341
341
  m['error'] = Flor.to_error(err)
342
342
 
343
- Flor.detail_msg(self, m, flag: true) if @unit.conf['log_err']
343
+ @unit.logger.log_err(self, m, flag: true)
344
+ #Flor.print_detail_msg(self, m, flag: true) if @unit.conf['log_err']
344
345
 
345
346
  #if m['error']['msg'].match(/\AToo many open files in system/)
346
347
  # puts "=" * 80 + ' ...'
@@ -359,7 +360,7 @@ module Flor
359
360
  @execution['tasks'][message['nid']] =
360
361
  { 'tasker' => message['tasker'], 'name' => message['taskname'] }
361
362
 
362
- @unit.tasker.task(message)
363
+ @unit.ganger.task(message)
363
364
  end
364
365
  alias detask task
365
366
 
@@ -456,7 +457,7 @@ module Flor
456
457
  oep = lookup_on_error_parent(message)
457
458
  return oep.trigger_on_error if oep
458
459
 
459
- Flor.detail_msg(self, message) if @unit.conf['log_err']
460
+ @unit.logger.log_err(self, message)
460
461
 
461
462
  []
462
463
  end
@@ -331,7 +331,7 @@ class Flor::Node
331
331
  return v unless v == :no
332
332
  end
333
333
 
334
- if mod != 'd' && @executor.unit.tasker.has_tasker?(@executor.exid, key)
334
+ if mod != 'd' && @executor.unit.has_tasker?(@executor.exid, key)
335
335
  return [ '_task', { 'task' => key }, -1 ]
336
336
  end
337
337
 
@@ -81,7 +81,7 @@ class Flor::Procedure < Flor::Node
81
81
 
82
82
  def debug_msg(msg=message)
83
83
 
84
- Flor.detail_msg(@executor, msg)
84
+ puts Flor.detail_msg(@executor, msg)
85
85
  end
86
86
 
87
87
  protected
@@ -27,23 +27,19 @@ module Flor
27
27
 
28
28
  class TransientExecutor < Executor
29
29
 
30
- class TransientTasker
31
-
32
- def has_tasker?(exid, tname); false; end
33
- end
34
-
35
30
  class TransientUnit
36
31
 
37
32
  attr_accessor :conf, :opts
38
- attr_reader :journal, :tasker, :loader
33
+ attr_reader :loader, :logger
34
+ attr_reader :journal
39
35
  attr_accessor :archive
40
36
 
41
37
  def initialize(conf)
42
38
 
43
39
  @conf = conf
44
40
  @opts = {}
41
+ @logger = TransientLogger.new(self)
45
42
  @journal = []
46
- @tasker = TransientTasker.new
47
43
  @archive = nil
48
44
  end
49
45
 
@@ -63,6 +59,26 @@ module Flor
63
59
 
64
60
  (@archive[exid] ||= {})[n['nid']] = Flor.dup(n) if @archive
65
61
  end
62
+
63
+ def has_tasker?(exid, tname)
64
+
65
+ false
66
+ end
67
+ end
68
+
69
+ class TransientLogger
70
+
71
+ def initialize(unit)
72
+
73
+ @unit = unit
74
+ end
75
+
76
+ def log_err(executor, message, opts={})
77
+
78
+ return unless @unit.conf['log_err']
79
+
80
+ Flor.print_detail_msg(executor, message, flag: true)
81
+ end
66
82
  end
67
83
 
68
84
  def initialize(conf={})
data/lib/flor/log.rb CHANGED
@@ -134,33 +134,37 @@ module Flor
134
134
 
135
135
  a << _c.rs
136
136
 
137
- puts a.join
137
+ (opts[:out] || $stdout).puts a.join
138
138
  end
139
139
 
140
- def self.print_src(src, opts={})
140
+ def self.print_src(src, opts={}, log_opts={})
141
141
 
142
- _c = colours(opts)
142
+ o = (log_opts[:out] ||= $stdout)
143
+ _c = colours(log_opts)
143
144
 
144
- puts "#{_c.dg}+---#{_c.rs}"
145
+ o.puts "#{_c.dg}+---#{_c.rs}"
145
146
 
146
- puts "#{_c.dg}| #{opts.inspect}#{_c.rs}" if opts.any?
147
+ o.puts "#{_c.dg}| #{opts.inspect}#{_c.rs}" if opts.any?
147
148
 
148
149
  if src.is_a?(String)
149
150
  src.split("\n").select { |l| l.strip.length > 0 }.each do |line|
150
- puts "#{_c.dg}| #{_c.yl}#{line}#{_c.rs}"
151
+ o.puts "#{_c.dg}| #{_c.yl}#{line}#{_c.rs}"
151
152
  end
152
153
  else
153
154
  ss = Flor.to_pretty_s(src).split("\n")
154
155
  ss.each do |line|
155
- puts "#{_c.dg}| #{_c.yl}#{line}#{_c.rs}"
156
+ o.puts "#{_c.dg}| #{_c.yl}#{line}#{_c.rs}"
156
157
  end
157
158
  end
158
159
 
159
- puts "#{_c.dg}.#{_c.rs}"
160
+ o.puts "#{_c.dg}.#{_c.rs}"
161
+
162
+ o.is_a?(StringIO) ? o.string : nil
160
163
  end
161
164
 
162
165
  def self.print_tree(tree, nid='0', opts={})
163
166
 
167
+ o = (opts[:out] ||= $stdout)
164
168
  _c = colours(opts)
165
169
 
166
170
  ind = ' ' * (opts[:ind] || 0)
@@ -172,12 +176,14 @@ module Flor
172
176
  c = tree[1].is_a?(Array) ? '' : " #{_c.yl}#{tree[1]}"
173
177
  l = " #{_c.dg}L#{tree[2]}"
174
178
 
175
- puts "#{ind}#{_c.dg}+--- #{opts[:title]}#{_c.rs}" if headers && nid == '0'
176
- puts "#{ind}#{_c.dg}| #{nid} #{h}#{c}#{l}#{_c.rs}"
179
+ o.puts "#{ind}#{_c.dg}+--- #{opts[:title]}#{_c.rs}" if headers && nid == '0'
180
+ o.puts "#{ind}#{_c.dg}| #{nid} #{h}#{c}#{l}#{_c.rs}"
177
181
  if tree[1].is_a?(Array)
178
182
  tree[1].each_with_index { |ct, i| print_tree(ct, "#{nid}_#{i}", opts) }
179
183
  end
180
- puts "#{ind}#{_c.dg}.#{_c.rs}" if headers && nid == '0'
184
+ o.puts "#{ind}#{_c.dg}.#{_c.rs}" if headers && nid == '0'
185
+
186
+ o.is_a?(StringIO) ? o.string : nil
181
187
  end
182
188
 
183
189
  def self.print_flat_tree(tree, nid, opts)
@@ -232,7 +238,7 @@ module Flor
232
238
 
233
239
  s << _c.rs
234
240
 
235
- puts s.string if is_root
241
+ opts[:out].puts(s.string) if is_root
236
242
  end
237
243
 
238
244
  def self.ret_to_s(executor, m)
@@ -306,31 +312,33 @@ module Flor
306
312
  sio.string
307
313
  end
308
314
 
309
- def self.detail_msg(executor, m, opts={})
315
+ def self.print_detail_msg(executor, m, opts={})
310
316
 
311
317
  return if m['_detail_msg_flag']
312
318
  m['_detail_msg_flag'] = true if opts[:flag]
313
319
 
320
+ o = (opts[:out] ||= $stdout)
314
321
  _c = colours(opts)
315
322
 
316
323
  nid = m['nid']
317
324
  n = executor.execution['nodes'][nid]
318
325
  node = n ? Flor::Node.new(executor, n, m) : nil
319
326
 
320
- puts "#{_c.dg}<Flor.detail_msg>#{_c.rs}"
321
- print "#{_c.yl}"
322
- Kernel::pp(m)
323
- puts "#{_c.dg}payload:#{_c.yl}"
324
- Kernel::pp(m['payload'])
325
- puts "#{_c.dg}tree:"
326
- print_tree(node.lookup_tree(nid), nid) if node
327
- puts "#{_c.dg}node:#{_c.yl}"
328
- Kernel::pp(n) if n
329
- puts "#{_c.dg}nodes:"
330
- puts nods_to_s(executor, m, opts)
327
+ o.puts "#{_c.dg}<Flor.print_detail_msg>#{_c.rs}#{_c.yl}"
328
+ o.puts(Flor.to_pretty_s(m))
329
+ o.puts "#{_c.dg}payload:#{_c.yl}"
330
+ o.puts(Flor.to_pretty_s(m['payload'], 0))
331
+ o.puts "#{_c.dg}tree:"
332
+ print_tree(node.lookup_tree(nid), nid, out: o) if node # FIXME
333
+ o.puts "#{_c.dg}node:#{_c.yl}"
334
+ o.puts(Flor.to_pretty_s(n)) if n
335
+ o.puts "#{_c.dg}nodes:"
336
+ o.puts nods_to_s(executor, m, opts)
331
337
  z = executor.execution['nodes'].size
332
- puts "#{_c.yl}#{z} node#{z == 1 ? '' : 's'}."
333
- puts "#{_c.dg}</Flor.detail_msg>#{_c.rs}"
338
+ o.puts "#{_c.yl}#{z} node#{z == 1 ? '' : 's'}."
339
+ o.puts "#{_c.dg}</Flor.print_detail_msg>#{_c.rs}"
340
+
341
+ o.is_a?(StringIO) ? o.string : nil
334
342
  end
335
343
  end
336
344