flor 1.3.1 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4d69af5b3896b5a00daa44d3fc0c60e08d9ee893916e5aeff81869cc35b2967e
4
- data.tar.gz: 6a780ea13692c00c23826462de49ad87f32e036103200d530fd247b4208fb682
3
+ metadata.gz: 298a6b2c9d3752b561ee8933ae00ed7a3f63682fb758dbe899097c6f7f56c00d
4
+ data.tar.gz: 3e2602737b9de7a452549d0f8ed34752618b1322a5508d178abe6559d549c045
5
5
  SHA512:
6
- metadata.gz: a39bbe96e2d6f5d48502c3c364b3fab6411098ab569aa3fec5ec8a3ae47e0c15bec321c312b6b70c9ef9f2cf49e5feced6e672fa3dbb0edd5f2772fea7007138
7
- data.tar.gz: c46e23499dffdf92acd34ac2961b91d3cbeeafdd98b40e30fdb0de8110293eecc8fc0fa1e5e0cb842a769f4e9b85ecebb032b6686b2e547d716aeca2b6862d37
6
+ metadata.gz: 28ae10c78676391537dde7cd7e0082338650c6aeba60fbcffa2ca5a4cb2dd2f168d7ff61019472c5f6f3d2216cabfe6e9bccb7cdae4856b513e0663f4d4ec362
7
+ data.tar.gz: 6379738cddfc5b74d37a30fa23260924649866b49dc670f37a0540a47a5079062288851ce07306350e227d73d0fd873f2199c3ea01b3399bce61572b8cebe497
data/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
  # CHANGELOG.md
3
3
 
4
4
 
5
+ ## flor 1.4.0 released 2021-11-10
6
+
7
+ * Add :tree to Execution#to_h
8
+ * Scaffold bin/flotojson
9
+
10
+
5
11
  ## flor 1.3.1 released 2021-04-19
6
12
 
7
13
  * Fix flor_pointers var deletion mechanism (type = ' var ')
@@ -149,7 +149,7 @@ class Flor::Node
149
149
  tree = lookup_tree(Flor.parent_nid(nid))
150
150
  return tree[1][cid] if tree
151
151
 
152
- #tree = lookup_tree(Flor.parent_nid(nid, true))
152
+ #tree = lookup_tree(Flor.parent_nid(nid, remove_subnid=true))
153
153
  #return tree[1][cid] if tree
154
154
  #
155
155
  # might become necessary at some point
data/lib/flor/parser.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Flor
3
4
 
4
5
  def self.parse(input, fname=nil, opts={})
@@ -727,3 +728,4 @@ fail "don't know how to invert #{operation.inspect}" # FIXME
727
728
  sio.string
728
729
  end
729
730
  end
731
+
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ # flotojson.rb
4
+
5
+ require 'flor'
6
+
7
+ FLAGS_WITH_VALUE = []
8
+
9
+ flags = {}
10
+ files = []
11
+
12
+ if (ARGV & [ '-h', '--help']).any?
13
+ puts
14
+ puts "bin/flotojson [flags] filename"
15
+ puts
16
+ puts " turns a flor .flo process definition to its tree representation"
17
+ puts
18
+ puts " flags:"
19
+ puts " --pp pretty prints instead of dumping as JSON"
20
+ puts
21
+ exit 0
22
+ end
23
+
24
+ args = ARGV.dup
25
+
26
+ loop do
27
+
28
+ a = args.shift; break unless a
29
+
30
+ if a.size > 1 && a[0, 1] == '-'
31
+ flags[a] = FLAGS_WITH_VALUE.include?(a) ? a.shift : true
32
+ else
33
+ files << a
34
+ end
35
+ end
36
+
37
+ #STDERR.puts flags.inspect
38
+ #STDERR.puts files.inspect
39
+
40
+ # t =
41
+ # tree.is_a?(String) ?
42
+ # Flor.parse(tree, opts[:fname] || opts[:path], opts) :
43
+ # tree
44
+ #
45
+ # unless t
46
+ #
47
+ # #h = opts.merge(prune: false, rewrite: false, debug: 0)
48
+ # #Raabro.pp(Flor.parse(tree, h[:fname], h))
49
+ # # TODO re-parse and indicate what went wrong...
50
+ #
51
+ # fail ArgumentError.new(
52
+ # "flow parsing failed: " + tree.inspect[0, 35] + '...')
53
+ # end
54
+
55
+ fname = files.first
56
+ content = File.read(fname)
57
+ tree = Flor.parse(content, fname, {})
58
+
59
+ if flags['--pp']
60
+ pp tree
61
+ else
62
+ puts JSON.dump(tree)
63
+ end
64
+
@@ -20,7 +20,29 @@ module Flor
20
20
  #end
21
21
 
22
22
  def nodes; data['nodes']; end
23
+
23
24
  def zero_node; nodes['0']; end
25
+
26
+ # Returns the nids, the lower in the tree, the earlier in the returned
27
+ # array.
28
+ #
29
+ def sorted_nids
30
+
31
+ nodes.keys
32
+ .inject([]) { |a, nid|
33
+ l = nid.split('_').length
34
+ (a[l] ||= []) << nid
35
+ a }
36
+ .compact
37
+ .collect(&:sort)
38
+ .flatten(1)
39
+ end
40
+
41
+ def lowest_node
42
+
43
+ nodes[sorted_nids.first]
44
+ end
45
+
24
46
  def closing_messages; data['closing_messages']; end
25
47
 
26
48
  def execution(reload=false); self; end
@@ -47,14 +69,16 @@ module Flor
47
69
 
48
70
  def full_tree
49
71
 
50
- tree = nodes['0']['tree']
72
+ nids = sorted_nids
73
+ nid0 = nids.shift
51
74
 
52
- #nodes.each do |nid, n|
53
- # next if nid == '0'
54
- # t = n['tree']; next unless t
55
- #end
56
- #
57
- # FIXME
75
+ return nil unless nid0
76
+
77
+ tree = Flor.dup(nodes[nid0]['tree'])
78
+
79
+ nids.each { |nid|
80
+ next unless nid.split('_', 2).first == nid0
81
+ replace_sub_tree(tree, nid, nodes[nid]['tree']) }
58
82
 
59
83
  tree
60
84
  end
@@ -80,21 +104,22 @@ module Flor
80
104
  cs = m[:counts] = {}
81
105
  is = m[:nids] = { tasks: [], failures: [] }
82
106
 
83
- fs = 0
84
- ts = 0
107
+ cs[:failures] = 0
108
+ cs[:tasks] = 0
109
+ cs[:nodes] = nodes.count
110
+ #
85
111
  nodes.each do |k, v|
86
112
  if v['task']
87
- ts += 1
113
+ cs[:tasks] += 1
88
114
  is[:tasks] << k
89
115
  end
90
116
  if v['failure']
91
- fs += 1
117
+ cs[:failures] += 1
92
118
  is[:failures] << k
93
119
  end
94
120
  end
95
- cs[:nodes] = nodes.count
96
- cs[:failures] = fs
97
- cs[:tasks] = ts
121
+
122
+ h[:tree] = full_tree
98
123
 
99
124
  h
100
125
  end
@@ -149,6 +174,30 @@ module Flor
149
174
  lookup_node(query, opts)['nid']
150
175
  end
151
176
 
177
+ protected
178
+
179
+ def replace_sub_tree(tree, nid, t)
180
+
181
+ return unless t
182
+ return if nid.index('-') # stay vanilla
183
+
184
+ snid = nid.split('_').collect(&:to_i)[1..-1]
185
+ a = get_child_array(tree, snid)
186
+
187
+ return unless a # shouldn't we fail?
188
+
189
+ a[snid.first] = Flor.dup(t)
190
+ end
191
+
192
+ def get_child_array(tree, snid)
193
+
194
+ return nil if tree.nil?
195
+ return nil if snid.length < 1
196
+ return nil unless tree[1].is_a?(Array)
197
+ return tree[1] if snid.length == 1
198
+ n = snid.shift; get_child_array(tree[1][n], snid)
199
+ end
200
+
152
201
  class << self
153
202
 
154
203
  def by_status(s)
data/lib/flor.rb CHANGED
@@ -16,7 +16,7 @@ require 'dense'
16
16
 
17
17
  module Flor
18
18
 
19
- VERSION = '1.3.1'
19
+ VERSION = '1.4.0'
20
20
  end
21
21
 
22
22
  require 'flor/colours'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flor
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Mettraux
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-19 00:00:00.000000000 Z
11
+ date: 2021-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: munemo
@@ -249,6 +249,7 @@ files:
249
249
  - lib/flor/to_string.rb
250
250
  - lib/flor/tools/env.rb
251
251
  - lib/flor/tools/firb.rb
252
+ - lib/flor/tools/flotojson.rb
252
253
  - lib/flor/tools/shell.rb
253
254
  - lib/flor/tools/shell_out.rb
254
255
  - lib/flor/tt.rb