forked from 99designs/smartling
/
status.go
98 lines (81 loc) · 2.12 KB
/
status.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
88
89
90
91
92
93
94
95
96
97
98
package main
import (
"fmt"
"os"
"sync"
"text/tabwriter"
"github.com/99designs/smartling"
)
func MustStatus(remotefile, locale string) smartling.FileStatus {
fs, err := client.Status(remotefile, locale)
logAndQuitIfError(err)
return fs
}
type ProjectStatus map[string]map[string]smartling.FileStatus
func (statuses ProjectStatus) Add(remotefile, locale string, fs smartling.FileStatus) {
_, ok := statuses[remotefile]
if !ok {
mm := make(map[string]smartling.FileStatus)
statuses[remotefile] = mm
}
statuses[remotefile][locale] = fs
}
func (statuses ProjectStatus) AwaitingAuthorizationCount() int {
c := 0
for _, s := range statuses {
for _, status := range s {
c += status.AwaitingAuthorizationStringCount()
break
}
}
return c
}
func (statuses ProjectStatus) TotalStringsCount() int {
c := 0
for _, s := range statuses {
for _, status := range s {
c += status.StringCount
break
}
}
return c
}
func GetProjectStatus(prefix string, locales []string) ProjectStatus {
var wg sync.WaitGroup
statuses := ProjectStatus{}
for _, projectFilepath := range ProjectConfig.Files() {
remoteFilePath := findIdenticalRemoteFileOrPush(projectFilepath, prefix)
for _, l := range locales {
wg.Add(1)
go func(remotefile, locale string) {
defer wg.Done()
statuses.Add(remotefile, locale, MustStatus(remotefile, locale))
}(remoteFilePath, l)
}
}
wg.Wait()
return statuses
}
func PrintProjectStatusTable(statuses ProjectStatus, locales []string) {
// Format in columns
w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', 0)
fmt.Fprint(w, "Awaiting\t In Progress -> Completed\n")
fmt.Fprint(w, " Auth\t\n")
for _, locale := range locales {
fmt.Fprint(w, "\t ", locale)
}
fmt.Fprint(w, "\n")
for projectFilepath, _ := range statuses {
aa := false
for _, locale := range locales {
status := statuses[projectFilepath][locale]
if !aa {
fmt.Fprintf(w, "%7d", status.AwaitingAuthorizationStringCount())
aa = true
}
fmt.Fprintf(w, "\t%3d->%-3d", status.InProgressStringCount(), status.CompletedStringCount)
}
fmt.Fprint(w, "\t", projectFilepath, "\n")
}
w.Flush()
}