2019-05-14 17:49:55 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/csv"
|
|
|
|
"encoding/json"
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"sort"
|
|
|
|
"strconv"
|
|
|
|
|
2020-08-08 19:02:18 +02:00
|
|
|
"github.com/rclone/rclone/cmd/test/info/internal"
|
2019-05-14 17:49:55 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
fOut := flag.String("o", "out.csv", "Output file")
|
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
args := flag.Args()
|
|
|
|
remotes := make([]internal.InfoReport, 0, len(args))
|
|
|
|
for _, fn := range args {
|
|
|
|
f, err := os.Open(fn)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Unable to open %q: %s", fn, err)
|
|
|
|
}
|
|
|
|
var remote internal.InfoReport
|
|
|
|
dec := json.NewDecoder(f)
|
|
|
|
err = dec.Decode(&remote)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Unable to decode %q: %s", fn, err)
|
|
|
|
}
|
|
|
|
if remote.ControlCharacters == nil {
|
|
|
|
log.Printf("Skipping remote %s: no ControlCharacters", remote.Remote)
|
|
|
|
} else {
|
|
|
|
remotes = append(remotes, remote)
|
|
|
|
}
|
|
|
|
if err := f.Close(); err != nil {
|
|
|
|
log.Fatalf("Closing %q failed: %s", fn, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
charsMap := make(map[string]string)
|
|
|
|
var remoteNames []string
|
|
|
|
for _, r := range remotes {
|
|
|
|
remoteNames = append(remoteNames, r.Remote)
|
|
|
|
for k, v := range *r.ControlCharacters {
|
|
|
|
v.Text = k
|
|
|
|
quoted := strconv.Quote(k)
|
|
|
|
charsMap[k] = quoted[1 : len(quoted)-1]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sort.Strings(remoteNames)
|
|
|
|
|
|
|
|
chars := make([]string, 0, len(charsMap))
|
|
|
|
for k := range charsMap {
|
|
|
|
chars = append(chars, k)
|
|
|
|
}
|
|
|
|
sort.Strings(chars)
|
|
|
|
|
|
|
|
// char remote output
|
|
|
|
recordsMap := make(map[string]map[string][]string)
|
|
|
|
// remote output
|
|
|
|
hRemoteMap := make(map[string][]string)
|
|
|
|
hOperation := []string{"Write", "Write", "Write", "Get", "Get", "Get", "List", "List", "List"}
|
|
|
|
hPosition := []string{"L", "M", "R", "L", "M", "R", "L", "M", "R"}
|
|
|
|
|
|
|
|
// remote
|
|
|
|
// write get list
|
|
|
|
// left middle right left middle right left middle right
|
|
|
|
|
|
|
|
for _, r := range remotes {
|
|
|
|
hRemoteMap[r.Remote] = []string{r.Remote, "", "", "", "", "", "", "", ""}
|
|
|
|
for k, v := range *r.ControlCharacters {
|
|
|
|
cMap, ok := recordsMap[k]
|
|
|
|
if !ok {
|
|
|
|
cMap = make(map[string][]string, 1)
|
|
|
|
recordsMap[k] = cMap
|
|
|
|
}
|
|
|
|
|
|
|
|
cMap[r.Remote] = []string{
|
|
|
|
sok(v.WriteError[internal.PositionLeft]), sok(v.WriteError[internal.PositionMiddle]), sok(v.WriteError[internal.PositionRight]),
|
|
|
|
sok(v.GetError[internal.PositionLeft]), sok(v.GetError[internal.PositionMiddle]), sok(v.GetError[internal.PositionRight]),
|
|
|
|
pok(v.InList[internal.PositionLeft]), pok(v.InList[internal.PositionMiddle]), pok(v.InList[internal.PositionRight]),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
records := [][]string{
|
2020-06-18 19:45:39 +02:00
|
|
|
{"", ""},
|
|
|
|
{"", ""},
|
|
|
|
{"Bytes", "Char"},
|
2019-05-14 17:49:55 +02:00
|
|
|
}
|
|
|
|
for _, r := range remoteNames {
|
|
|
|
records[0] = append(records[0], hRemoteMap[r]...)
|
|
|
|
records[1] = append(records[1], hOperation...)
|
|
|
|
records[2] = append(records[2], hPosition...)
|
|
|
|
}
|
|
|
|
for _, c := range chars {
|
|
|
|
k := charsMap[c]
|
|
|
|
row := []string{fmt.Sprintf("%X", c), k}
|
|
|
|
for _, r := range remoteNames {
|
2019-09-23 13:52:59 +02:00
|
|
|
if m, ok := recordsMap[c][r]; ok {
|
2019-05-14 17:49:55 +02:00
|
|
|
row = append(row, m...)
|
|
|
|
} else {
|
|
|
|
row = append(row, "", "", "", "", "", "", "", "", "")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
records = append(records, row)
|
|
|
|
}
|
|
|
|
|
|
|
|
var writer io.Writer
|
|
|
|
if *fOut == "-" {
|
|
|
|
writer = os.Stdout
|
|
|
|
} else {
|
|
|
|
f, err := os.Create(*fOut)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Unable to create %q: %s", *fOut, err)
|
|
|
|
}
|
|
|
|
defer func() {
|
|
|
|
if err := f.Close(); err != nil {
|
|
|
|
log.Fatalln("Error writing csv:", err)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
writer = f
|
|
|
|
}
|
|
|
|
|
|
|
|
w := csv.NewWriter(writer)
|
|
|
|
err := w.WriteAll(records)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalln("Error writing csv:", err)
|
|
|
|
} else if err := w.Error(); err != nil {
|
|
|
|
log.Fatalln("Error writing csv:", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func sok(s string) string {
|
|
|
|
if s != "" {
|
|
|
|
return "ERR"
|
|
|
|
}
|
|
|
|
return "OK"
|
|
|
|
}
|
|
|
|
|
|
|
|
func pok(p internal.Presence) string {
|
|
|
|
switch p {
|
|
|
|
case internal.Absent:
|
|
|
|
return "MIS"
|
|
|
|
case internal.Present:
|
|
|
|
return "OK"
|
|
|
|
case internal.Renamed:
|
|
|
|
return "REN"
|
|
|
|
case internal.Multiple:
|
|
|
|
return "MUL"
|
|
|
|
default:
|
|
|
|
return "ERR"
|
|
|
|
}
|
|
|
|
}
|