2024-01-13 23:27:46 -06:00
|
|
|
// This is a simple example
|
|
|
|
package main
|
|
|
|
|
2024-01-18 00:58:14 -06:00
|
|
|
import (
|
2024-01-13 23:27:46 -06:00
|
|
|
"io/ioutil"
|
2024-01-30 13:55:23 -06:00
|
|
|
"os/user"
|
2024-01-13 23:27:46 -06:00
|
|
|
"strings"
|
2024-01-30 13:55:23 -06:00
|
|
|
|
2024-01-30 13:57:17 -06:00
|
|
|
"go.wit.com/gui"
|
2024-01-30 13:55:23 -06:00
|
|
|
"go.wit.com/lib/gadgets"
|
|
|
|
"go.wit.com/lib/gui/repostatus"
|
|
|
|
"go.wit.com/log"
|
2024-01-13 23:27:46 -06:00
|
|
|
)
|
|
|
|
|
2024-01-18 05:03:04 -06:00
|
|
|
func (r *repo) String() string {
|
|
|
|
return r.status.String()
|
|
|
|
}
|
|
|
|
|
2024-01-13 23:27:46 -06:00
|
|
|
func (r *repo) getPath() string {
|
|
|
|
return r.path
|
|
|
|
}
|
|
|
|
|
|
|
|
func RemoveFirstElement(slice []string) (string, []string) {
|
|
|
|
if len(slice) == 0 {
|
|
|
|
return "", slice // Return the original slice if it's empty
|
|
|
|
}
|
|
|
|
return slice[0], slice[1:] // Return the slice without the first element
|
|
|
|
}
|
|
|
|
|
|
|
|
// returns path, master branch name, devel branch name, user branch name
|
|
|
|
func splitLine(line string) (string, string, string, string) {
|
|
|
|
var path, master, devel, user string
|
|
|
|
parts := strings.Split(line, " ")
|
|
|
|
path, parts = RemoveFirstElement(parts)
|
|
|
|
master, parts = RemoveFirstElement(parts)
|
|
|
|
devel, parts = RemoveFirstElement(parts)
|
|
|
|
user, parts = RemoveFirstElement(parts)
|
|
|
|
// path, master, devel, user := strings.Split(line, " ")
|
|
|
|
return path, master, devel, user
|
|
|
|
}
|
|
|
|
|
|
|
|
func myrepolist() []string {
|
|
|
|
content, _ := ioutil.ReadFile("/home/jcarr/.config/myrepolist")
|
|
|
|
out := string(content)
|
|
|
|
out = strings.TrimSpace(out)
|
|
|
|
lines := strings.Split(out, "\n")
|
|
|
|
return lines
|
|
|
|
}
|
2024-01-19 18:37:27 -06:00
|
|
|
|
|
|
|
func (r *repo) Hide() {
|
|
|
|
r.pLabel.Hide()
|
|
|
|
r.lastTag.Hide()
|
|
|
|
r.vLabel.Hide()
|
2024-02-02 17:08:59 -06:00
|
|
|
r.targetVersion.Hide()
|
2024-01-19 18:37:27 -06:00
|
|
|
|
|
|
|
r.dirtyLabel.Hide()
|
2024-01-25 02:37:04 -06:00
|
|
|
r.goSumStatus.Hide()
|
2024-01-23 11:22:33 -06:00
|
|
|
r.statusButton.Hide()
|
2024-01-19 18:37:27 -06:00
|
|
|
r.hidden = true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *repo) Show() {
|
|
|
|
r.pLabel.Show()
|
|
|
|
r.lastTag.Show()
|
|
|
|
r.vLabel.Show()
|
2024-02-02 17:08:59 -06:00
|
|
|
r.targetVersion.Show()
|
2024-01-19 18:37:27 -06:00
|
|
|
|
|
|
|
r.dirtyLabel.Show()
|
2024-01-25 02:37:04 -06:00
|
|
|
r.goSumStatus.Show()
|
2024-01-23 11:22:33 -06:00
|
|
|
r.statusButton.Show()
|
2024-01-19 18:37:27 -06:00
|
|
|
r.hidden = false
|
|
|
|
}
|
2024-01-30 13:55:23 -06:00
|
|
|
|
|
|
|
// This creates a window
|
|
|
|
func repoworld() {
|
|
|
|
reposwin = gadgets.NewBasicWindow(me.myGui, "All git repositories in ~/go/src/")
|
|
|
|
reposwin.Make()
|
|
|
|
reposwin.Custom = func() {
|
|
|
|
log.Warn("GOT HERE: main() gadgets.NewBasicWindow() close")
|
|
|
|
log.Warn("Should I do something special here?")
|
|
|
|
}
|
2024-02-11 18:58:52 -06:00
|
|
|
reposbox = reposwin.Box().NewBox("bw vbox", false)
|
2024-01-30 13:55:23 -06:00
|
|
|
|
|
|
|
reposgroup = reposbox.NewGroup("go repositories (read from ~/.config/myrepolist)")
|
2024-02-02 00:02:53 -06:00
|
|
|
reposgrid = reposgroup.NewGrid("test", 7, 1)
|
2024-01-30 13:55:23 -06:00
|
|
|
|
|
|
|
reposgrid.NewLabel("") // path goes here
|
|
|
|
|
2024-02-02 00:02:53 -06:00
|
|
|
reposgrid.NewLabel("last tag")
|
|
|
|
reposgrid.NewLabel("Current Ver")
|
|
|
|
reposgrid.NewLabel("Target Ver")
|
2024-01-30 13:55:23 -06:00
|
|
|
|
|
|
|
reposgrid.NewLabel("Status")
|
|
|
|
reposgrid.NewLabel("go.sum")
|
|
|
|
|
|
|
|
reposgrid.NewLabel("Show()")
|
|
|
|
|
|
|
|
repos := myrepolist()
|
|
|
|
for _, line := range repos {
|
|
|
|
log.Verbose("repo =", line)
|
|
|
|
path, mbranch, dbranch, ubranch := splitLine(line)
|
|
|
|
if mbranch == "" {
|
|
|
|
mbranch = "master"
|
|
|
|
}
|
|
|
|
if dbranch == "" {
|
|
|
|
dbranch = "devel"
|
|
|
|
}
|
|
|
|
usr, _ := user.Current()
|
|
|
|
if ubranch == "" {
|
|
|
|
ubranch = usr.Username
|
|
|
|
}
|
|
|
|
addRepo(reposgrid, path, mbranch, dbranch, ubranch)
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, path := range repostatus.ListGitDirectories() {
|
|
|
|
// log.Info("addRepo()", i, path)
|
|
|
|
tmp := strings.TrimPrefix(path, "/home/jcarr/go/src/")
|
|
|
|
log.Info("addRepo()", i, tmp)
|
|
|
|
addRepo(reposgrid, tmp, "master", "master", "master")
|
|
|
|
}
|
|
|
|
}
|
2024-01-30 13:57:17 -06:00
|
|
|
|
|
|
|
func addRepo(grid *gui.Node, path string, master string, devel string, user string) {
|
|
|
|
_, ok := me.allrepos[path]
|
|
|
|
if ok {
|
|
|
|
log.Info("addRepo() already had path", path)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
newRepo := new(repo)
|
|
|
|
|
|
|
|
path = strings.Trim(path, "/") // trim any extranous '/' chars put in the config file by the user
|
|
|
|
if path == "" {
|
|
|
|
log.Warn("addRepo() got empty path", path, master, devel, user)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if repostatus.VerifyLocalGoRepo(path) {
|
|
|
|
log.Verbose("newRepo actually exists", newRepo.getPath())
|
|
|
|
} else {
|
|
|
|
log.Warn("repostatus.VerifyLocalGoRepo() failed for for", path, master, devel, user)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
newRepo.path = path
|
2024-02-02 00:02:53 -06:00
|
|
|
newRepo.pLabel = grid.NewLabel(path)
|
2024-01-30 13:57:17 -06:00
|
|
|
|
2024-02-02 00:02:53 -06:00
|
|
|
newRepo.lastTag = grid.NewLabel("")
|
|
|
|
newRepo.vLabel = grid.NewLabel("")
|
|
|
|
newRepo.targetVersion = grid.NewLabel("")
|
2024-01-30 13:57:17 -06:00
|
|
|
|
|
|
|
newRepo.dirtyLabel = grid.NewLabel("")
|
|
|
|
newRepo.goSumStatus = grid.NewLabel("?")
|
|
|
|
|
|
|
|
newRepo.statusButton = grid.NewButton("Configure", func() {
|
|
|
|
if newRepo.status == nil {
|
|
|
|
log.Warn("status window doesn't exist")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
log.Warn("status window exists. trying TestDraw() here")
|
|
|
|
newRepo.status.Toggle()
|
2024-01-30 16:48:40 -06:00
|
|
|
setCurrentRepo(newRepo, "manually chosen", "notsure")
|
2024-01-30 13:57:17 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
newRepo.status = repostatus.NewRepoStatusWindow(newRepo.path)
|
|
|
|
newRepo.hidden = false
|
|
|
|
newRepo.status.SetMainWorkingName(master)
|
|
|
|
newRepo.status.SetDevelWorkingName(devel)
|
|
|
|
newRepo.status.SetUserWorkingName(user)
|
|
|
|
me.allrepos[path] = newRepo
|
|
|
|
}
|