/
consolepersist.go
87 lines (76 loc) · 2.13 KB
/
consolepersist.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package main
import (
"fmt"
"github.com/ops-class/test161"
"strings"
)
// A PersistenceManager that "persists" to the console
type ConsolePersistence struct {
width int
}
func (c *ConsolePersistence) Close() {
}
const lineFmt = "[%-*v]\t%.6f\t%s"
func (c *ConsolePersistence) Notify(entity interface{}, msg, what int) error {
if msg == test161.MSG_PERSIST_UPDATE && what == test161.MSG_FIELD_OUTPUT {
switch entity.(type) {
case *test161.Command:
{
cmd := entity.(*test161.Command)
line := cmd.Output[len(cmd.Output)-1]
// Learn the width on the fly (submissions)
if c.width < len(cmd.Test.DependencyID) {
c.width = len(cmd.Test.DependencyID)
}
output := fmt.Sprintf(lineFmt, c.width, cmd.Test.DependencyID, line.SimTime, line.Line)
fmt.Println(output)
}
case *test161.BuildCommand:
{
cmd := entity.(*test161.BuildCommand)
for _, line := range cmd.Output {
output := fmt.Sprintf("%.6f\t%s", line.SimTime, line.Line)
fmt.Println(output)
}
}
}
} else if msg == test161.MSG_PERSIST_UPDATE && what == test161.MSG_FIELD_STATUSES {
switch entity.(type) {
case *test161.Test:
{
test := entity.(*test161.Test)
index := len(test.Status) - 1
if index > 0 {
status := test.Status[index]
str := fmt.Sprintf(lineFmt, c.width, test.DependencyID, test.SimTime, status.Status)
if status.Message != "" {
str += fmt.Sprintf(": %s", status.Message)
}
fmt.Println(str)
}
}
}
} else if msg == test161.MSG_PERSIST_UPDATE && what == test161.MSG_FIELD_STATUS {
switch entity.(type) {
case *test161.Test:
{
test := entity.(*test161.Test)
if test.Result == test161.TEST_RESULT_RUNNING {
lines := strings.Split(strings.TrimSpace(test.ConfString), "\n")
for _, line := range lines {
output := fmt.Sprintf(lineFmt, c.width, test.DependencyID, 0.0, line)
fmt.Println(output)
}
}
}
}
}
return nil
}
func (d *ConsolePersistence) Retrieve(what int, who map[string]interface{},
filter map[string]interface{}, res interface{}) error {
return nil
}
func (d *ConsolePersistence) CanRetrieve() bool {
return false
}