flor 0.14.0 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +9 -0
  3. data/CREDITS.md +21 -0
  4. data/LICENSE.txt +4 -1
  5. data/Makefile +4 -0
  6. data/README.md +8 -0
  7. data/flor.gemspec +10 -10
  8. data/lib/flor.rb +2 -2
  9. data/lib/flor/changes.rb +3 -3
  10. data/lib/flor/colours.rb +14 -8
  11. data/lib/flor/conf.rb +63 -58
  12. data/lib/flor/core.rb +4 -4
  13. data/lib/flor/core/executor.rb +65 -29
  14. data/lib/flor/core/node.rb +37 -20
  15. data/lib/flor/core/procedure.rb +182 -40
  16. data/lib/flor/core/texecutor.rb +125 -52
  17. data/lib/flor/djan.rb +111 -82
  18. data/lib/flor/dollar.rb +31 -30
  19. data/lib/flor/flor.rb +314 -237
  20. data/lib/flor/id.rb +7 -2
  21. data/lib/flor/log.rb +250 -245
  22. data/lib/flor/parser.rb +72 -38
  23. data/lib/flor/pcore/_arr.rb +10 -10
  24. data/lib/flor/pcore/_att.rb +49 -14
  25. data/lib/flor/pcore/_coll.rb +18 -0
  26. data/lib/flor/pcore/_obj.rb +23 -7
  27. data/lib/flor/pcore/_pat_.rb +1 -1
  28. data/lib/flor/pcore/_pat_guard.rb +8 -0
  29. data/lib/flor/pcore/_pat_obj.rb +3 -3
  30. data/lib/flor/pcore/_pat_or.rb +4 -0
  31. data/lib/flor/pcore/_pat_regex.rb +24 -0
  32. data/lib/flor/pcore/_skip.rb +4 -0
  33. data/lib/flor/pcore/_val.rb +0 -1
  34. data/lib/flor/pcore/all.rb +111 -0
  35. data/lib/flor/pcore/any.rb +83 -0
  36. data/lib/flor/pcore/arith.rb +35 -6
  37. data/lib/flor/pcore/break.rb +39 -1
  38. data/lib/flor/pcore/case.rb +82 -4
  39. data/lib/flor/pcore/cmp.rb +7 -7
  40. data/lib/flor/pcore/collect.rb +50 -0
  41. data/lib/flor/pcore/cond.rb +17 -3
  42. data/lib/flor/pcore/cursor.rb +8 -2
  43. data/lib/flor/pcore/detect.rb +45 -0
  44. data/lib/flor/pcore/each.rb +52 -0
  45. data/lib/flor/pcore/empty.rb +60 -0
  46. data/lib/flor/pcore/filter.rb +94 -0
  47. data/lib/flor/pcore/find.rb +67 -0
  48. data/lib/flor/pcore/for_each.rb +65 -0
  49. data/lib/flor/pcore/includes.rb +32 -0
  50. data/lib/flor/pcore/inject.rb +55 -0
  51. data/lib/flor/pcore/iterator.rb +151 -0
  52. data/lib/flor/pcore/keys.rb +60 -0
  53. data/lib/flor/pcore/length.rb +34 -7
  54. data/lib/flor/pcore/logo.rb +18 -0
  55. data/lib/flor/pcore/loop.rb +4 -0
  56. data/lib/flor/pcore/map.rb +77 -46
  57. data/lib/flor/pcore/match.rb +8 -2
  58. data/lib/flor/pcore/matchr.rb +4 -5
  59. data/lib/flor/pcore/move.rb +3 -3
  60. data/lib/flor/pcore/noeval.rb +13 -0
  61. data/lib/flor/pcore/not.rb +16 -0
  62. data/lib/flor/pcore/on.rb +172 -0
  63. data/lib/flor/pcore/on_cancel.rb +54 -0
  64. data/lib/flor/pcore/on_error.rb +68 -0
  65. data/lib/flor/pcore/rand.rb +2 -2
  66. data/lib/flor/pcore/range.rb +2 -1
  67. data/lib/flor/pcore/reduce.rb +124 -0
  68. data/lib/flor/pcore/reverse.rb +46 -0
  69. data/lib/flor/pcore/select.rb +72 -0
  70. data/lib/flor/pcore/set.rb +8 -0
  71. data/lib/flor/pcore/stall.rb +10 -0
  72. data/lib/flor/pcore/to_array.rb +61 -0
  73. data/lib/flor/pcore/until.rb +34 -0
  74. data/lib/flor/punit/cancel.rb +30 -5
  75. data/lib/flor/punit/ccollect.rb +11 -0
  76. data/lib/flor/punit/cmap.rb +10 -5
  77. data/lib/flor/punit/concurrence.rb +42 -51
  78. data/lib/flor/punit/cron.rb +33 -0
  79. data/lib/flor/punit/do_trap.rb +42 -0
  80. data/lib/flor/punit/every.rb +48 -13
  81. data/lib/flor/punit/graft.rb +3 -3
  82. data/lib/flor/punit/on_timeout.rb +38 -0
  83. data/lib/flor/punit/schedule.rb +69 -6
  84. data/lib/flor/punit/signal.rb +54 -0
  85. data/lib/flor/punit/sleep.rb +1 -1
  86. data/lib/flor/punit/task.rb +4 -1
  87. data/lib/flor/punit/trap.rb +188 -13
  88. data/lib/flor/tools/shell.rb +408 -62
  89. data/lib/flor/tools/shell_out.rb +31 -0
  90. data/lib/flor/unit.rb +1 -1
  91. data/lib/flor/unit/caller.rb +177 -0
  92. data/lib/flor/unit/executor.rb +1 -0
  93. data/lib/flor/unit/ganger.rb +15 -21
  94. data/lib/flor/unit/hook.rb +1 -1
  95. data/lib/flor/unit/hooker.rb +22 -10
  96. data/lib/flor/unit/loader.rb +22 -22
  97. data/lib/flor/unit/logger.rb +63 -36
  98. data/lib/flor/unit/models.rb +6 -1
  99. data/lib/flor/unit/models/execution.rb +12 -1
  100. data/lib/flor/unit/models/message.rb +7 -0
  101. data/lib/flor/unit/models/trap.rb +31 -17
  102. data/lib/flor/unit/scheduler.rb +18 -10
  103. data/lib/flor/unit/storage.rb +83 -23
  104. data/lib/flor/unit/waiter.rb +1 -2
  105. metadata +96 -52
  106. data/lib/flor/deep.rb +0 -144
  107. data/lib/flor/punit/on.rb +0 -57
  108. data/lib/flor/unit/runner.rb +0 -84
  109. data/match.md +0 -22
@@ -35,9 +35,14 @@ module Flor
35
35
  child_id(nid) + 1
36
36
  end
37
37
 
38
- def self.sub_nid(nid, subid)
38
+ def self.sub_nid(nid, subid=nil)
39
39
 
40
- "#{nid.split('-').first}-#{subid}"
40
+ if subid
41
+ "#{nid.split('-').first}-#{subid}"
42
+ else
43
+ ss = nid.split('-')
44
+ ss.length > 1 ? ss.last.to_i : 0
45
+ end
41
46
  end
42
47
 
43
48
  # Remove the sub_nid if any.
@@ -1,321 +1,326 @@
1
1
 
2
2
  module Flor
3
+ class << self
3
4
 
4
- def self.log_message(executor, m, opts={})
5
+ # Turns a flor message into a one line string.
6
+ # Used when logging messages.
7
+ #
8
+ def message_to_one_line_s(executor, m, opts={})
5
9
 
6
- return if m['point'] == 'end'
10
+ _c = colours(opts)
7
11
 
8
- _c = colours(opts)
12
+ nid = m['nid']
13
+ nd = executor.node(nid)
9
14
 
10
- nid = m['nid']
11
- nd = executor.node(nid)
15
+ a = [ ' ' ]
12
16
 
13
- a = [ ' ' ]
14
-
15
- n =
16
- Time.now.utc
17
- tm =
18
- if opts[:date]
19
- n.strftime('%Y%m%d.%H:%M:%S') + sprintf('.%06d', n.usec)[0, 4]
20
- else
17
+ n = Time.now.utc
18
+ a <<
19
+ opts[:date] ?
20
+ n.strftime('%Y%m%d.%H:%M:%S') + sprintf('.%06d', n.usec)[0, 4] :
21
21
  n.strftime('%H:%M:%S') + sprintf('.%06d', n.usec)[0, 4]
22
- end
23
- a << tm
24
- a << ' '
25
- a << _c.dg
22
+ a << ' ' << _c.dg
26
23
 
27
- if ex = (m['exid'] || '').split('.').last
28
- a << ex[-4..-1]
29
- a << ' '
30
- end
24
+ if ex = (m['exid'] || '').split('.').last
25
+ a << ex[-4..-1] << ' '
26
+ end
31
27
 
32
- a << "#{nd ? _c.dg : _c.dim + _c.dg}#{nid}#{_c.rs}#{_c.dg} " if nid
28
+ a << "#{nd ? _c.dg : _c.dim + _c.dg}#{nid}#{_c.rs}#{_c.dg} " if nid
33
29
 
34
- pt = m['point'][0, 3]
35
- _pt =
36
- case pt
30
+ pt = m['point'][0, 3]
31
+ _pt =
32
+ case pt
37
33
  when 'tri', 'sig' then _c.gr
38
34
  when 'cea', 'ter' then _c.lg
39
35
  when 'can' then _c.ma
40
36
  else _c.bl
37
+ end
38
+ a << "#{_pt}#{pt}#{_c.dg}"
39
+
40
+ fla = m['flavour']
41
+ a << " #{_c.lg}#{fla}#{_c.dg}" if fla
42
+
43
+ st = nd && nd['status'].last
44
+ a << " #{_c.dim}#{_c.lg}#{st['status']}:#{st['flavour']}#{_c.rs}#{_c.dg}" \
45
+ if st && st['status']
46
+
47
+ t = m['tree']
48
+ rw = (t && m['rewritten']) ? 'rw->' : ''
49
+ nt = t || Node.new(executor, nd, m).lookup_tree(nid)
50
+ a <<
51
+ if t
52
+ " [#{rw}#{_c.yl}#{Flor.to_d(t[0], compact: true)}#{_c.dg} L#{t[2]}]"
53
+ elsif nt
54
+ " [#{_c.dg}#{Flor.to_d(nt[0], compact: true)}#{_c.dg} L#{nt[2]}]"
55
+ else
56
+ ''
57
+ end
58
+
59
+ a << m['on_error'] ? " #{_c.rd}on_error" : ''
60
+
61
+ tmi = m['timer_id']
62
+ tmi = tmi ? " #{_c.dg}tmi:#{tmi}" : ''
63
+ a << tmi
64
+ #
65
+ tri = m['trap_id']
66
+ tri = tri ? " #{_c.dg}tri:#{tri}" : ''
67
+ a << tri
68
+
69
+ cn = t ? " #{_c.dg}#{Flor.to_d(t[1], compact: true, inner: true)}" : ''
70
+ cn = Flor.truncate_string(cn, 49, "#{_c.dg}...#{_c.rs}")
71
+ a << cn
72
+
73
+ hp = nd && nd['heap']
74
+ hp = hp && (hp != (t || [])[0]) ? " #{_c.dg}hp:#{nd['heap']}" : ''
75
+ a << hp
76
+
77
+ msr = " #{_c.dg}m#{m['m']}s#{m['sm'] || '_'}"
78
+ msr << "r#{m['er']}>#{m['pr']}" if m['er'] && m['er'] > -1
79
+ a << msr
80
+
81
+ a << (m['from'] ? " from #{m['from']}" : '')
82
+
83
+ if cs = m['cause']
84
+ a << " <" << cs
85
+ .collect { |c|
86
+ [ c['cause'][0, 2], c['nid'], "m#{c['m']}", c['type'] ]
87
+ .compact.join(':') }
88
+ .join('<')
41
89
  end
42
- a << "#{_pt}#{pt}#{_c.dg}"
43
-
44
- fla = m['flavour']
45
- a << " #{_c.lg}#{fla}#{_c.dg}" if fla
46
-
47
- st = nd && nd['status'].last
48
- a << " #{_c.dim}#{_c.lg}#{st['status']}:#{st['flavour']}#{_c.rs}#{_c.dg}" \
49
- if st && st['status']
50
-
51
- t =
52
- m['tree']
53
- rw =
54
- (t && m['rewritten']) ? 'rw->' : ''
55
- nt =
56
- t || Node.new(executor, nd, m).lookup_tree(nid)
57
- t0 =
58
- if t
59
- " [#{rw}#{_c.yl}#{Flor.to_d(t[0], compact: true)}#{_c.dg} L#{t[2]}]"
60
- elsif nt
61
- " [#{_c.dg}#{Flor.to_d(nt[0], compact: true)}#{_c.dg} L#{nt[2]}]"
62
- else
63
- ''
64
- end
65
- a << t0
66
-
67
- oe = m['on_error'] ? " #{_c.rd}on_error" : ''
68
- a << oe
69
-
70
- tmi = m['timer_id']
71
- tmi = tmi ? " #{_c.dg}tmi:#{tmi}" : ''
72
- a << tmi
73
- #
74
- tri = m['trap_id']
75
- tri = tri ? " #{_c.dg}tri:#{tri}" : ''
76
- a << tri
77
-
78
- cn = t ? " #{_c.dg}#{Flor.to_d(t[1], compact: true, inner: true)}" : ''
79
- cn = Flor.truncate_string(cn, 49, "#{_c.dg}...#{_c.rs}")
80
- a << cn
81
-
82
- hp = nd && nd['heap']
83
- hp = hp && (hp != (t || [])[0]) ? " #{_c.dg}hp:#{nd['heap']}" : ''
84
- a << hp
85
-
86
- msr = " #{_c.dg}m#{m['m']}s#{m['sm'] || '_'}"
87
- msr << "r#{m['er']}>#{m['pr']}" if m['er'] && m['er'] > -1
88
- a << msr
89
-
90
- fr = m['from'] ? " from #{m['from']}" : ''
91
- a << fr
92
-
93
- rt = ret_to_s(executor, m, _c)
94
- rt = rt.length > 0 ? " #{_c.lg}f.ret #{rt}" : ''
95
- a << rt
96
-
97
- ta =
98
- m['point'] == 'entered' || m['point'] == 'left' ?
99
- " #{_c.dg}tags:#{_c.gr}#{m['tags'].join(',')}" :
100
- nil
101
- a << ta
102
-
103
- vs =
104
- (nd && nd['vars']) ?
105
- " #{_c.dg}vars:#{_c.gr}#{nd['vars'].keys.join("#{_c.dg},#{_c.gr}")}" :
106
- ''
107
- a << vs
108
-
109
- %w[ fpoint dbg ].each do |k|
110
- a << " #{_c.dg}#{k}:#{m[k]}" if m.has_key?(k)
111
- end
112
90
 
113
- a << _c.rs
91
+ rt = ret_to_s(executor, m, _c)
92
+ rt = rt.length > 0 ? " #{_c.lg}f.ret #{rt}" : ''
93
+ a << rt
114
94
 
115
- (opts[:out] || $stdout).puts a.join
116
- end
95
+ a << (
96
+ (m['point'] == 'entered' || m['point'] == 'left') ?
97
+ " #{_c.dg}tags:#{_c.gr}#{m['tags'].join(',')}" :
98
+ nil)
117
99
 
118
- def self.print_src(src, opts={}, log_opts={})
100
+ a << (
101
+ (nd && nd['vars']) ?
102
+ " #{_c.dg}vars:#{_c.gr}#{nd['vars'].keys.join("#{_c.dg},#{_c.gr}")}" :
103
+ '')
119
104
 
120
- o = (log_opts[:out] ||= $stdout)
121
- _c = colours(log_opts)
122
-
123
- o.puts "#{_c.dg}+---#{_c.rs}"
105
+ %w[ fpoint dbg ].each do |k|
106
+ a << " #{_c.dg}#{k}:#{m[k]}" if m.has_key?(k)
107
+ end
124
108
 
125
- o.puts "#{_c.dg}| #{opts.inspect}#{_c.rs}" if opts.any?
109
+ a << _c.rs
126
110
 
127
- if src.is_a?(String)
128
- src.split("\n")
129
- .select { |l| l.strip.length > 0 && l.match(/\A\s*[^#]/) }
130
- .each { |l| o.puts "#{_c.dg}| #{_c.yl}#{l}#{_c.rs}" }
131
- else
132
- Flor.to_pretty_s(src).split("\n")
133
- .each { |l| o.puts "#{_c.dg}| #{_c.yl}#{l}#{_c.rs}" }
134
- end
111
+ a.join
112
+ end # message_to_one_line_s
135
113
 
136
- o.puts "#{_c.dg}.#{_c.rs}"
114
+ def src_to_s(src, launch_opts, opts={})
137
115
 
138
- o.is_a?(StringIO) ? o.string : nil
139
- end
116
+ o = StringIO.new
117
+ _c = colours(opts)
140
118
 
141
- def self.print_tree(tree, nid='0', opts={})
119
+ o.puts "#{_c.dg}+---#{_c.rs}"
142
120
 
143
- t0, t1, t2 = (tree || [])
121
+ if launch_opts.any?
122
+ o.puts "#{_c.dg}| #{Flor.to_d(launch_opts, compact: true)}#{_c.rs}"
123
+ o.puts "#{_c.dg}|#{_c.rs}"
124
+ end
144
125
 
145
- o = (opts[:out] ||= $stdout)
146
- _c = colours(opts)
126
+ lines =
127
+ (src.is_a?(String) ? src : Flor.to_pretty_s(src))
128
+ .split("\n")
129
+ min = lines
130
+ .select { |l| l.strip.length > 0 }
131
+ .collect { |l| l.match(/\A(\s*)/)[1].length }
132
+ .min
133
+ lines
134
+ .each_with_index { |l, i|
135
+ o.puts "#{_c.dg}|#{"%4d" % (i + 1)} #{_c.yl}#{l[min..-1]}#{_c.rs}" }
147
136
 
148
- ind = ' ' * (opts[:ind] || 0)
137
+ o.puts "#{_c.dg}.#{_c.rs}"
149
138
 
150
- headers = opts[:headers]; headers = true if headers.nil?
151
- headers = true if opts[:title]
139
+ o.string
140
+ end # src_to_s
152
141
 
153
- h = "#{_c.yl}#{Flor.to_d(t0, compact: true)}"
154
- c = t1.is_a?(Array) ? '' : " #{_c.yl}#{t1}"
155
- l = " #{_c.dg}L#{t2}"
142
+ def tree_to_s(tree, nid='0', opts={})
156
143
 
157
- o.puts "#{ind}#{_c.dg}+--- #{opts[:title]}#{_c.rs}" if headers && nid == '0'
158
- o.puts "#{ind}#{_c.dg}| #{nid} #{h}#{c}#{l}#{_c.rs}"
159
- if t1.is_a?(Array)
160
- t1.each_with_index { |ct, i| print_tree(ct, Flor.child_nid(nid, i), opts) }
161
- end
162
- o.puts "#{ind}#{_c.dg}.#{_c.rs}" if headers && nid == '0'
144
+ t0, t1, t2 = (tree || [])
163
145
 
164
- o.is_a?(StringIO) ? o.string : nil
165
- end
146
+ o = StringIO.new
147
+ _c = colours(opts)
166
148
 
167
- def self.print_flat_tree(tree, nid, opts)
149
+ ind = ' ' * (opts[:ind] || 0)
168
150
 
169
- _c = colours(opts)
151
+ headers = opts[:headers]; headers = true if headers.nil?
152
+ headers = true if opts[:title]
170
153
 
171
- s = opts[:s]
154
+ h = "#{_c.yl}#{Flor.to_d(t0, opts.merge(compact: true))}"
155
+ c = t1.is_a?(Array) ? '' : " #{_c.yl}#{t1}"
156
+ l = " #{_c.dg}L#{t2}"
172
157
 
173
- s << ' ' << nid << ' ' << _c.yl << tree[0] << _c.dg
158
+ o.puts "#{ind}#{_c.dg}+--- #{opts[:title]}#{_c.rs}" if headers && nid == '0'
159
+ o.puts "#{ind}#{_c.dg}| #{nid} #{h}#{c}#{l}#{_c.rs}"
160
+ t1.each_with_index { |ct, i|
161
+ o.puts tree_to_s(ct, Flor.child_nid(nid, i), opts) } if t1.is_a?(Array)
162
+ o.puts "#{ind}#{_c.dg}.#{_c.rs}" if headers && nid == '0'
174
163
 
175
- if tree[1].is_a?(Array)
176
- tree[1].each_with_index do |t, i|
177
- print_flat_tree(t, "#{nid}_#{i}", opts)
178
- end
179
- else
180
- s << ' ' << tree[1]
164
+ o.string
181
165
  end
182
- end
183
-
184
- def self.print_compact_tree(tree, nid='0', opts={})
185
166
 
186
- _c = colours(opts)
167
+ def to_flat_tree_s(tree, nid, opts)
187
168
 
188
- is_root = opts[:s].nil?
189
- ind = ' ' * (opts[:ind] || 0)
169
+ o = StringIO.new
170
+ _c = colours(opts)
190
171
 
191
- atts, natts =
192
- tree[1].is_a?(Array) ?
193
- tree[1].partition { |t| Flor.is_att_tree?(t) } :
194
- [ [], [] ]
172
+ o << ' ' << nid << ' ' << _c.yl << tree[0] << _c.dg
195
173
 
196
- s = (opts[:s] ||= StringIO.new)
174
+ if tree[1].is_a?(Array)
175
+ tree[1].each_with_index do |t, i|
176
+ o << to_flat_tree_s(t, "#{nid}_#{i}", opts)
177
+ end
178
+ else
179
+ o << ' ' << tree[1]
180
+ end
197
181
 
198
- if t = opts.delete(:title)
199
- s << ind << _c.dg << '+--- ' << t << "\n"
182
+ o.string
200
183
  end
201
184
 
202
- s << ind << _c.dg << '| ' << nid << ' '
203
- s << _c.yl << Flor.to_d(tree[0], compact: true) << _c.dg << ' L' << tree[2]
185
+ def to_compact_tree_s(tree, nid='0', opts={})
204
186
 
205
- atts.each_with_index do |ct, i|
206
- print_flat_tree(ct, "_#{i}", opts)
207
- end
187
+ o = StringIO.new
188
+ _c = colours(opts)
208
189
 
209
- natts.each_with_index do |ct, i|
210
- i = atts.size + i
211
- s << "\n"
212
- print_compact_tree(ct, "#{nid}_#{i}", opts)
213
- end
190
+ #is_root = opts[:s].nil?
191
+ ind = ' ' * (opts[:ind] || 0)
214
192
 
215
- s << "\n" << ind << _c.dg << '\---' if is_root && opts[:close]
193
+ atts, natts =
194
+ tree[1].is_a?(Array) ?
195
+ tree[1].partition { |t| Flor.is_att_tree?(t) } :
196
+ [ [], [] ]
216
197
 
217
- s << _c.rs
198
+ if t = opts.delete(:title)
199
+ o << ind << _c.dg << '+--- ' << t << "\n"
200
+ end
218
201
 
219
- opts[:out].puts(s.string) if is_root
220
- end
202
+ o <<
203
+ ind << _c.dg << '| ' << nid << ' ' <<
204
+ _c.yl << Flor.to_d(tree[0], opts.merge(compact: true)) <<
205
+ _c.dg << ' L' << tree[2]
221
206
 
222
- def self.ret_to_s(executor, m, c)
207
+ atts.each_with_index do |ct, i|
208
+ o << to_flat_tree_s(ct, "_#{i}", opts)
209
+ end
223
210
 
224
- ret = (m['payload'] || {})['ret']
225
- s = Flor.to_d(ret, compact: true)
226
- Flor.truncate_string(s, 35, Proc.new { |x| "#{c.dg}... (L#{x})#{c.rs}" })
227
- end
211
+ natts.each_with_index do |ct, i|
212
+ i = atts.size + i
213
+ o << "\n" << to_compact_tree_s(ct, "#{nid}_#{i}", opts)
214
+ end
228
215
 
229
- def self.nod_to_s(executor, n, opts, here=false)
216
+ #o << "\n" << ind << _c.dg << '\---' if is_root && opts[:close]
217
+ o << "\n" << ind << _c.dg << '\---' if opts[:close]
230
218
 
231
- _c = colours(opts)
219
+ o << _c.rs
232
220
 
233
- t = n['tree'] || Node.new(executor, n, nil).lookup_tree(n['nid'])
234
- t = Flor.to_d(t, compact: true) if t
235
- t = Flor.truncate_string(t, 42);
221
+ #opts[:out].puts(s.string) if is_root
236
222
 
237
- h = {}
238
- %w[ parent cnid noreply dbg ].each do |k|
239
- h[k] = n[k] if n.has_key?(k)
223
+ o.string
240
224
  end
241
225
 
242
- dbg = n['dbg'] ? "dbg:#{n['dbg']}" : nil
243
- nr = n.has_key?('noreply') ? "nr:#{n['noreply']}" : nil
244
- h = h.collect { |k, v| "#{k}:#{v}" }.join(' ')
226
+ def ret_to_s(executor, m, c)
245
227
 
246
- vs = n['vars']
247
- vs = 'vars:' + vs.keys.join(',') if vs
248
- ts = n['tags']
249
- ts = 'tags:' + ts.join(',') if ts
228
+ ret = (m['payload'] || {})['ret']
229
+ s = Flor.to_d(ret, compact: true)
230
+ Flor.truncate_string(s, 35, Proc.new { |x| "#{c.dg}... (L#{x})#{c.rs}" })
231
+ end
250
232
 
251
- flr = n['failure'] ? "#{_c.rd}flre" : ''
233
+ def nod_to_s(executor, n, opts, here=false)
252
234
 
253
- here = here ? "#{_c.dg}<---msg['nid']" : nil
235
+ _c = colours(opts)
254
236
 
255
- [ _c.yl + n['nid'], t, h, ts, vs, flr, here ].compact.join(' ')
256
- end
237
+ t = n['tree'] || Node.new(executor, n, nil).lookup_tree(n['nid'])
238
+ t = Flor.to_d(t, compact: true) if t
239
+ t = Flor.truncate_string(t, 42);
257
240
 
258
- def self.ncns_to_s(executor, ncn, msg, opts, sio, ind, seen)
241
+ h = {}
242
+ %w[ parent cnid noreply dbg ].each do |k|
243
+ h[k] = n[k] if n.has_key?(k)
244
+ end
259
245
 
260
- n, cn = ncn
261
- nid = n['nid']
246
+ dbg = n['dbg'] ? "dbg:#{n['dbg']}" : nil
247
+ nr = n.has_key?('noreply') ? "nr:#{n['noreply']}" : nil
248
+ h = h.collect { |k, v| "#{k}:#{v}" }.join(' ')
262
249
 
263
- return if seen.include?(nid)
264
- seen << nid
250
+ vs = n['vars']
251
+ vs = 'vars:' + vs.keys.join(',') if vs
252
+ ts = n['tags']
253
+ ts = 'tags:' + ts.join(',') if ts
265
254
 
266
- sio.print(ind)
267
- sio.print(nod_to_s(executor, n, opts, nid == msg['nid']))
268
- sio.print("\n")
269
- cn.each { |c| ncns_to_s(executor, c, msg, opts, sio, ind + ' ', seen) }
270
- end
255
+ flr = n['failure'] ? "#{_c.rd}flre" : ''
271
256
 
272
- def self.nods_to_s(executor, msg, opts)
257
+ here = here ? "#{_c.dg}<---msg['nid']" : nil
273
258
 
274
- nodes = executor.execution['nodes'].values
259
+ [ _c.yl + n['nid'], t, h, ts, vs, flr, here ].compact.join(' ')
260
+ end
275
261
 
276
- nodes = nodes.inject({}) { |h, n| h[n['nid']] = [ n, [] ]; h }
277
- nodes.values.each { |ncn|
278
- pa = ncn.first['parent']; next unless pa
279
- pan, pacn = nodes[pa]
280
- pacn << ncn if pacn
281
- }
262
+ def ncns_to_s(executor, ncn, msg, opts, sio, ind, seen)
282
263
 
283
- sio = StringIO.new
284
- seen = []
285
- nodes.values.each do |ncn|
286
- ncns_to_s(executor, ncn, msg, opts, sio, ' ', seen)
264
+ n, cn = ncn
265
+ nid = n['nid']
266
+
267
+ return if seen.include?(nid)
268
+ seen << nid
269
+
270
+ sio.print(ind)
271
+ sio.print(nod_to_s(executor, n, opts, nid == msg['nid']))
272
+ sio.print("\n")
273
+ cn.each { |c| ncns_to_s(executor, c, msg, opts, sio, ind + ' ', seen) }
287
274
  end
288
275
 
289
- sio.string
290
- end
276
+ def nods_to_s(executor, msg, opts)
277
+
278
+ nodes = executor.execution['nodes'].values
279
+
280
+ nodes = nodes.inject({}) { |h, n| h[n['nid']] = [ n, [] ]; h }
281
+ nodes.values.each { |ncn|
282
+ pa = ncn.first['parent']; next unless pa
283
+ pan, pacn = nodes[pa]
284
+ pacn << ncn if pacn
285
+ }
291
286
 
292
- def self.print_detail_msg(executor, m, opts={})
293
-
294
- return if m['_detail_msg_flag']
295
- m['_detail_msg_flag'] = true if opts[:flag]
296
-
297
- o = (opts[:out] ||= $stdout)
298
- _c = colours(opts)
299
-
300
- nid = m['nid']
301
- n = executor.execution['nodes'][nid]
302
- node = n ? Flor::Node.new(executor, n, m) : nil
303
-
304
- o.puts "#{_c.dg}<Flor.print_detail_msg>#{_c.rs}#{_c.yl}"
305
- o.puts(Flor.to_pretty_s(m))
306
- o.puts "#{_c.dg}payload:#{_c.yl}"
307
- o.puts(Flor.to_pretty_s(m['payload'], 0))
308
- o.puts "#{_c.dg}tree:"
309
- print_tree(node.lookup_tree(nid), nid, out: o) if node
310
- o.puts "#{_c.dg}node:#{_c.yl}"
311
- o.puts(Flor.to_pretty_s(n)) if n
312
- o.puts "#{_c.dg}nodes:"
313
- o.puts nods_to_s(executor, m, opts)
314
- z = executor.execution['nodes'].size
315
- o.puts "#{_c.yl}#{z} node#{z == 1 ? '' : 's'}."
316
- o.puts "#{_c.dg}</Flor.print_detail_msg>#{_c.rs}"
317
-
318
- o.is_a?(StringIO) ? o.string : nil
287
+ sio = StringIO.new
288
+ seen = []
289
+ nodes.values.each do |ncn|
290
+ ncns_to_s(executor, ncn, msg, opts, sio, ' ', seen)
291
+ end
292
+
293
+ sio.string
294
+ end
295
+
296
+ def msg_to_detail_s(executor, m, opts={})
297
+
298
+ return if m['_detail_msg_flag']
299
+ m['_detail_msg_flag'] = true if opts[:flag]
300
+
301
+ o = StringIO.new
302
+ _c = colours(opts)
303
+
304
+ nid = m['nid']
305
+ n = executor.execution['nodes'][nid]
306
+ node = n ? Flor::Node.new(executor, n, m) : nil
307
+
308
+ o.puts "#{_c.dg}<Flor.msg_to_detail_s>#{_c.rs}#{_c.yl}"
309
+ o.puts Flor.to_pretty_s(m)
310
+ o.puts "#{_c.dg}payload:#{_c.yl}"
311
+ o.puts Flor.to_pretty_s(m['payload'], 0)
312
+ o.puts "#{_c.dg}tree:"
313
+ o.puts(tree_to_s(node.lookup_tree(nid), nid, out: o)) if node
314
+ o.puts "#{_c.dg}node:#{_c.yl}"
315
+ o.puts(Flor.to_pretty_s(n)) if n
316
+ o.puts "#{_c.dg}nodes:"
317
+ o.puts nods_to_s(executor, m, opts)
318
+ z = executor.execution['nodes'].size
319
+ o.puts "#{_c.yl}#{z} node#{z == 1 ? '' : 's'}."
320
+ o.puts "#{_c.dg}</Flor.msg_to_detail_s>#{_c.rs}"
321
+
322
+ o.string
323
+ end
319
324
  end
320
325
  end
321
326