startask 0.1.2 → 0.2.0
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
- checksums.yaml.gz.sig +0 -0
- data/lib/startask.rb +146 -19
- data.tar.gz.sig +0 -0
- metadata +2 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ad982911d12e9f54c2591e57aae3e8088282984540dff16709e41717cb251b7
|
4
|
+
data.tar.gz: e6cfffc5ef7f5ad1cbb9f4ebb7f75a9b36197236533d2f1221d123ce13f44388
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f731d444684c1029944c4695d802737985902420c49034ca89f2073ee9e6b397d98e04ab05cd390d06c922dba9a0bd8d47e6549651c878968eceed76589c8477
|
7
|
+
data.tar.gz: 7a5a2a533bc8d830838bac80542e9b61e52cc755ec280683374405064da0d6e8796b0fd7cdc1e5f484cb7df194028d32f57f6d797a3500d946ff5194741307f5
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/startask.rb
CHANGED
@@ -13,7 +13,8 @@ module RecordHelper
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def logit(label)
|
16
|
-
@log << [label, Time.now
|
16
|
+
@log << [label, Time.now]
|
17
|
+
#@log << [label, Time.now.strftime("%a, %d %b %Y, %H:%M%P")]
|
17
18
|
@log.last
|
18
19
|
end
|
19
20
|
|
@@ -22,11 +23,11 @@ end
|
|
22
23
|
class ActionItem
|
23
24
|
include RecordHelper
|
24
25
|
|
25
|
-
attr_reader
|
26
|
+
attr_reader :id
|
26
27
|
|
27
|
-
def initialize(s, callback=nil)
|
28
|
+
def initialize(s, callback=nil, id: nil)
|
28
29
|
|
29
|
-
@id = generate_id()
|
30
|
+
@id = id || generate_id()
|
30
31
|
@title = s
|
31
32
|
@log = []
|
32
33
|
@callback = callback
|
@@ -38,6 +39,18 @@ class ActionItem
|
|
38
39
|
end
|
39
40
|
|
40
41
|
alias completed done
|
42
|
+
|
43
|
+
def find(id)
|
44
|
+
return self if id == @id
|
45
|
+
end
|
46
|
+
|
47
|
+
def log(detail: false)
|
48
|
+
detail ? @log.map {|x| [@id, x[-1], x[0], @title]} : @log
|
49
|
+
end
|
50
|
+
|
51
|
+
def logupdate(item)
|
52
|
+
@log << item
|
53
|
+
end
|
41
54
|
|
42
55
|
def to_s()
|
43
56
|
@title
|
@@ -86,8 +99,15 @@ class Actions
|
|
86
99
|
|
87
100
|
attr_accessor :status
|
88
101
|
|
89
|
-
def initialize(callback=nil)
|
102
|
+
def initialize(obj=nil, callback=nil)
|
103
|
+
|
104
|
+
@a = read obj if obj.is_a? Rexle::Recordset
|
90
105
|
@callback = callback
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
def find(id)
|
110
|
+
@a.find {|x| x.find id}
|
91
111
|
end
|
92
112
|
|
93
113
|
def import(a)
|
@@ -99,6 +119,10 @@ class Actions
|
|
99
119
|
return self
|
100
120
|
|
101
121
|
end
|
122
|
+
|
123
|
+
def log()
|
124
|
+
@a.flat_map {|x| x.log(detail: true)}
|
125
|
+
end
|
102
126
|
|
103
127
|
def [](i)
|
104
128
|
@a[i]
|
@@ -112,6 +136,23 @@ class Actions
|
|
112
136
|
|
113
137
|
Rexle::Element.new( :actions, value: @a.map(&:to_xml).join)
|
114
138
|
#@a.map(&:to_xml)
|
139
|
+
end
|
140
|
+
|
141
|
+
private
|
142
|
+
|
143
|
+
def read(node)
|
144
|
+
|
145
|
+
node.map do |e|
|
146
|
+
|
147
|
+
case e.name.to_sym
|
148
|
+
when :action
|
149
|
+
ActionItem.new(e.text, id: e.attributes[:id])
|
150
|
+
when :actions
|
151
|
+
Actions.new(e.xpath('*'), callback: @callback)
|
152
|
+
end
|
153
|
+
|
154
|
+
end
|
155
|
+
|
115
156
|
end
|
116
157
|
|
117
158
|
end
|
@@ -121,8 +162,8 @@ class ResultItem
|
|
121
162
|
|
122
163
|
attr_reader :id
|
123
164
|
|
124
|
-
def initialize(s, callback=nil)
|
125
|
-
@id = generate_id()
|
165
|
+
def initialize(s, callback=nil, id: nil)
|
166
|
+
@id = id || generate_id()
|
126
167
|
@evidence = s
|
127
168
|
@callback = callback
|
128
169
|
end
|
@@ -142,8 +183,13 @@ end
|
|
142
183
|
|
143
184
|
class Results
|
144
185
|
|
145
|
-
def initialize(
|
146
|
-
|
186
|
+
def initialize(obj=nil, callback: nil)
|
187
|
+
|
188
|
+
@a = read obj if obj.is_a? Rexle::Recordset
|
189
|
+
@callback = callback
|
190
|
+
|
191
|
+
return self
|
192
|
+
|
147
193
|
end
|
148
194
|
|
149
195
|
def import(a)
|
@@ -173,13 +219,8 @@ class Results
|
|
173
219
|
|
174
220
|
def to_xml()
|
175
221
|
|
176
|
-
|
177
|
-
|
178
|
-
else
|
179
|
-
Rexle::Element.new( :results, value: @a.map(&:to_xml).join)
|
180
|
-
end
|
181
|
-
|
182
|
-
#@a.map(&:to_xml)
|
222
|
+
Rexle::Element.new( :results, value: @a.map(&:to_xml).join)
|
223
|
+
|
183
224
|
end
|
184
225
|
|
185
226
|
def print_row(id, indent: 0)
|
@@ -193,6 +234,23 @@ class Results
|
|
193
234
|
end.join("\n")
|
194
235
|
end
|
195
236
|
|
237
|
+
private
|
238
|
+
|
239
|
+
def read(node)
|
240
|
+
|
241
|
+
node.map do |e|
|
242
|
+
|
243
|
+
case e.name.to_sym
|
244
|
+
when :result
|
245
|
+
ResultItem.new(e.text, id: e.attributes[:id])
|
246
|
+
when :results
|
247
|
+
Results.new(e.xpath('*'), callback: @callback)
|
248
|
+
end
|
249
|
+
|
250
|
+
end
|
251
|
+
|
252
|
+
end
|
253
|
+
|
196
254
|
end
|
197
255
|
|
198
256
|
# task dictionary
|
@@ -213,7 +271,7 @@ end
|
|
213
271
|
class StarTask
|
214
272
|
include RecordHelper
|
215
273
|
|
216
|
-
attr_reader :situation, :task, :actions, :
|
274
|
+
attr_reader :situation, :task, :actions, :results, :id
|
217
275
|
|
218
276
|
def initialize(src=nil, debug: false)
|
219
277
|
|
@@ -221,7 +279,8 @@ class StarTask
|
|
221
279
|
@id = generate_id()
|
222
280
|
@log = []
|
223
281
|
@status = ''
|
224
|
-
|
282
|
+
read src if src
|
283
|
+
|
225
284
|
end
|
226
285
|
|
227
286
|
def done()
|
@@ -229,6 +288,16 @@ class StarTask
|
|
229
288
|
end
|
230
289
|
|
231
290
|
alias completed done
|
291
|
+
|
292
|
+
def find(id)
|
293
|
+
|
294
|
+
if @id == id then
|
295
|
+
return self
|
296
|
+
else
|
297
|
+
@actions.find id
|
298
|
+
end
|
299
|
+
|
300
|
+
end
|
232
301
|
|
233
302
|
def import(raws)
|
234
303
|
|
@@ -269,6 +338,15 @@ class StarTask
|
|
269
338
|
@results = Results.new(self).import(kvx.result[:items])
|
270
339
|
|
271
340
|
end
|
341
|
+
|
342
|
+
def log(detail: false)
|
343
|
+
#todo
|
344
|
+
detail ? @log.map {|x| [@id, x[-1], x[0]]} : @log
|
345
|
+
end
|
346
|
+
|
347
|
+
def logupdate(item)
|
348
|
+
@log << item
|
349
|
+
end
|
272
350
|
|
273
351
|
# adds a status message to the log
|
274
352
|
#
|
@@ -293,11 +371,28 @@ class StarTask
|
|
293
371
|
situation = Rexle::Element.new( :situation, value: @situation)
|
294
372
|
task = Rexle::Element.new( :task, value: @task)
|
295
373
|
|
296
|
-
doc = Rexle.new(
|
374
|
+
doc = Rexle.new()
|
375
|
+
doc.add Rexle::Element.new(:star)
|
376
|
+
doc.root.attributes[:id] = @id
|
297
377
|
doc.root.add situation
|
298
378
|
doc.root.add task
|
299
379
|
doc.root.add @actions.to_xml
|
300
380
|
doc.root.add @results.to_xml
|
381
|
+
|
382
|
+
logx = log(detail: true) + @actions.log
|
383
|
+
|
384
|
+
lognode = Rexle::Element.new(:log)
|
385
|
+
|
386
|
+
logx.sort_by {|x| x[1]}.reverse.each do |x|
|
387
|
+
|
388
|
+
attr = {id: x[0], timestamp: x[1]}
|
389
|
+
val = "[%s]" % x[2]
|
390
|
+
val += ' ' + x[3] if x[3]
|
391
|
+
|
392
|
+
lognode.add Rexle::Element.new( :li, attributes: attr, value: val)
|
393
|
+
end
|
394
|
+
|
395
|
+
doc.root.add lognode
|
301
396
|
doc.root.xml pretty: true
|
302
397
|
|
303
398
|
end
|
@@ -310,5 +405,37 @@ class StarTask
|
|
310
405
|
@status = r
|
311
406
|
|
312
407
|
end
|
408
|
+
|
409
|
+
def read(obj)
|
410
|
+
|
411
|
+
s, _ = RXFHelper.read obj
|
412
|
+
doc = Rexle.new(s)
|
413
|
+
@id = doc.root.attributes[:id]
|
414
|
+
@situation = doc.root.element('situation').text
|
415
|
+
@task = doc.root.element('task').text
|
416
|
+
actions = doc.root.xpath('actions/*')
|
417
|
+
@actions = Actions.new actions
|
418
|
+
results = doc.root.xpath('results/*')
|
419
|
+
@results = Results.new results
|
420
|
+
|
421
|
+
log = doc.root.xpath('log/*')
|
422
|
+
|
423
|
+
log.reverse.each do |x|
|
424
|
+
|
425
|
+
id = x.attributes[:id]
|
426
|
+
found = find id
|
427
|
+
|
428
|
+
if found then
|
429
|
+
d = Time.parse(x.attributes[:timestamp])
|
430
|
+
puts 'x.text: ' + x.text.inspect if @debug
|
431
|
+
status = x.text[/^\[([^\]]+)/,1]
|
432
|
+
found.logupdate([status.to_sym, d])
|
433
|
+
end
|
434
|
+
|
435
|
+
|
436
|
+
end
|
437
|
+
|
438
|
+
doc.xml pretty: true
|
439
|
+
end
|
313
440
|
|
314
441
|
end
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: startask
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -36,7 +36,7 @@ cert_chain:
|
|
36
36
|
BWN+6F7HF8UfTUHWCQqk9FoCAYtbfQWLUqZwWN+dLzn1CPK0yoPjuSR59/HShliV
|
37
37
|
IUEz9QfhClpwEVu+leXBe7RwfxADwAWYEfI=
|
38
38
|
-----END CERTIFICATE-----
|
39
|
-
date: 2022-
|
39
|
+
date: 2022-10-01 00:00:00.000000000 Z
|
40
40
|
dependencies:
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rxfhelper
|
metadata.gz.sig
CHANGED
Binary file
|