-
Notifications
You must be signed in to change notification settings - Fork 0
/
bench.go
92 lines (86 loc) · 2.1 KB
/
bench.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
package main
import (
"encoding/json"
"log"
"os/exec"
)
// Holds the Sites and Apps installed on
// the specific site
type Bench struct {
Sites []string
SAPS []Sites_and_Apps
Version []AppVersions
}
type Sites_and_Apps struct {
Site string
Apps []string
}
// getSites returns the sites in the bench
// returns the sites as a string slice
// as multitenant systems will be used
func getSites() []string {
cmd := exec.Command("bench", "--site", "all", "list-apps", "--format", "json")
cmd.Dir = benchDir
out, err := cmd.Output()
if err != nil {
log.Println("Error getting Sites", err)
}
var apps map[string][]interface{}
json.Unmarshal(out, &apps)
var sites []string
for k := range apps {
sites = append(sites, k)
}
return sites
}
// getApps returns the Apps installed on the site
// Will return as a slice of Apps struct
func getAll() Bench {
cmd := exec.Command("bench", "--site", "all", "list-apps", "--format", "json")
cmd.Dir = benchDir
out, err := cmd.Output()
if err != nil {
log.Println("Error getting All apps", err)
}
var apps map[string][]interface{}
json.Unmarshal(out, &apps)
var appstruct []Sites_and_Apps
var sites []string
for k, v := range apps {
sites = append(sites, k)
var appnames []string
for i := range v {
appnames = append(appnames, v[i].(string))
}
appstruct = append(appstruct, Sites_and_Apps{
Site: k,
Apps: appnames,
})
}
return Bench{
Sites: sites,
SAPS: appstruct,
Version: getAppVersions(),
}
}
// AppVersions hold the JSON struct
// for the Versions of Apps
type AppVersions struct {
Commit string `json:"commit"`
App string `json:"app"`
Branch string `json:"branch"`
Version string `json:"version"`
}
// getAppVersions returns the Versions of the apps
// the data is fetched from bench with commit, branch and version of the app
func getAppVersions() []AppVersions {
cmd := exec.Command("bench", "version", "--format", "json")
cmd.Dir = benchDir
out, err := cmd.Output()
if err != nil {
log.Println("Version retreival failed", err)
}
var appversions []AppVersions
json.Unmarshal(out, &appversions)
return appversions
}