submit-patchset/main.go

233 lines
6.4 KiB
Go

// This is a simple example
package main
import (
"os/user"
"embed"
"go.wit.com/log"
"go.wit.com/gui/gui"
"go.wit.com/gui/gadgets"
"go.wit.com/gui/tools/repostatus"
)
//go:embed plugins/*
var resToolkit embed.FS
func main() {
myGui = gui.New()
myGui.InitEmbed(resToolkit)
myGui.Default()
repoworld()
gui.Watchdog()
}
func addRepo(grid *gui.Node, path string, master string, devel string, user string) {
newRepo := new(repo)
if repostatus.VerifyLocalGoRepo(path) {
log.Warn("newRepo actually exists", newRepo.getPath())
} else {
log.Warn("newRepo does not exist", newRepo.getPath())
return
}
newRepo.path = path
newRepo.pLabel = grid.NewLabel(path).SetProgName("path")
newRepo.lastTag = grid.NewLabel("").SetProgName("lastTag")
newRepo.vLabel = grid.NewLabel("").SetProgName("current")
newRepo.masterName = grid.NewLabel("").SetProgName("masterName")
newRepo.masterVersion = grid.NewLabel("").SetProgName("masterVersion")
newRepo.develName = grid.NewLabel("").SetProgName("develName")
newRepo.develVersion = grid.NewLabel("").SetProgName("develVersion")
newRepo.userName = grid.NewLabel("").SetProgName("userName")
newRepo.userVersion = grid.NewLabel("").SetProgName("userVersion")
newRepo.dirtyLabel = grid.NewLabel("")
/*
newRepo.pButton = grid.NewButton("rescan", func () {
newRepo.newScan()
})
grid.NewButton("Update()", func () {
if newRepo.status == nil {
log.Warn("status window doesn't exist")
return
}
log.Warn("status window exists. trying Update() here")
newRepo.status.Update()
})
grid.NewButton("Hide()", func () {
if newRepo.status == nil {
log.Warn("status window doesn't exist")
return
}
log.Warn("status window exists. trying Hide() here")
newRepo.status.Hide()
})
*/
grid.NewButton("Show()", func () {
if newRepo.status == nil {
log.Warn("status window doesn't exist")
return
}
log.Warn("status window exists. trying TestDraw() here")
newRepo.status.Show()
newRepo.status.Update()
})
if path == "" {
newRepo.cButton.Hide()
newRepo.pButton.Hide()
}
newRepo.status = repostatus.New(myGui, newRepo.path)
newRepo.status.SetMasterName(master)
newRepo.status.SetDevelName(devel)
newRepo.status.SetUserName(user)
newRepo.status.Update()
newRepo.newScan()
allrepos = append(allrepos, newRepo)
}
// This creates a window
func repoworld() {
reposwin = gadgets.NewBasicWindow(myGui, "autotypist for GO & git. it types faster than you can.")
reposwin.Make()
reposbox = reposwin.Box().NewBox("bw vbox", false)
reposgroup = reposbox.NewGroup("go repositories (read from ~/.config/myrepolist)")
reposgrid = reposgroup.NewGrid("test", 11, 1)
reposgrid.NewLabel("")
reposgrid.NewLabel("last tag").SetProgName("last tag")
reposgrid.NewLabel("Current Version").SetProgName("Current Version")
reposgrid.NewLabel("master")
reposgrid.NewLabel("version")
reposgrid.NewLabel("devel")
reposgrid.NewLabel("version")
reposgrid.NewLabel("user")
reposgrid.NewLabel("version")
reposgrid.NewLabel("Status")
reposgrid.NewLabel("Show()")
repos := myrepolist()
for _, line := range repos {
log.Warn("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)
}
box2 := reposwin.Box().NewBox("bw vbox", false)
buildOptions := box2.NewGrid("buildOptions",2, 1)
title := gadgets.NewOneLiner(buildOptions, "Branch and build")
title.Set("options")
guiBranch := gadgets.NewBasicCombobox(buildOptions, "Select GUI branch")
guiBranch.Add("guimaster")
guiBranch.Add("guidevel")
guiBranch.Add("jcarr")
buildOptions.NewLabel("only PERFECT")
buildOptions.NewButton("Find", func () {
log.Warn("delete every repo marked PERFECT")
var newCmds [][]string
for _, repo := range allrepos {
status := repo.getStatus()
if status == "PERFECT" {
var line []string
line = append(line, "rm", "-rf", "go/src/" + repo.path)
newCmds = append(newCmds, line)
}
}
script = newCmds
doit.Enable()
setGitCommands()
})
buildOptions.NewLabel("start over")
buildOptions.NewButton("rm src & pkgs", func () {
var newCmds [][]string
var dirty bool = false
for _, repo := range allrepos {
status := repo.getStatus()
if status == "dirty" {
dirty = true
break
}
}
line := []string{"rm", "-rf", "go/src/"}
newCmds = append(newCmds, line)
newCmds = append(newCmds, []string{"rm", "-rf", "go/pkg/"})
if dirty {
line := []string{"can't do this with dirty repos"}
newCmds = append(newCmds, line)
doit.Disable()
} else {
doit.Enable()
}
script = newCmds
setGitCommands()
})
buildOptions.NewLabel("get autotypist")
buildOptions.NewButton("go get", func () {
var newCmds [][]string
newCmds = append(newCmds, []string{"mkdir", "-p", "go/src/go.wit.com/apps"})
newCmds = append(newCmds, []string{"cd", "go/src/go.wit.com/apps/myrepos"})
newCmds = append(newCmds, []string{"go", "get", "-v", "-u", "go.wit.com/apps/myrepos"})
newCmds = append(newCmds, []string{"cd", "go/src/go.wit.com/apps/myrepos"})
newCmds = append(newCmds, []string{"go", "get", "-v", "-u", "."})
newCmds = append(newCmds, []string{"go", "get", "-v", "-u", "go.wit.com/gui/toolkits"})
newCmds = append(newCmds, []string{"cd", "go/src/go.wit.com/gui/toolkits"})
newCmds = append(newCmds, []string{"go", "get", "-v", "-u", "."})
newCmds = append(newCmds, []string{"go", "make"})
newCmds = append(newCmds, []string{"cd", "go/src/go.wit.com/apps/myrepos"})
newCmds = append(newCmds, []string{"go", "make"})
script = newCmds
setGitCommands()
doit.Enable()
})
buildOptions.NewButton("status.Update() all", func () {
for _, repo := range allrepos {
repo.status.Update()
}
})
buildOptions.NewButton("rescan all", func () {
for _, repo := range allrepos {
repo.newScan()
}
})
buildOptions.NewLabel("cmd")
cmds = buildOptions.NewLabel("ls")
buildOptions.NewLabel("--dry-run")
dryrun = buildOptions.NewButton("show commands", func () {
if dryRunCommands() {
log.Warn("EVERYTHING MIGHT HAVE WORKED")
} else {
log.Warn("EVERYTHING DID NOT WORK")
}
})
buildOptions.NewLabel("Doit")
doit = buildOptions.NewButton("run commands", func () {
doit.Disable()
log.Warn("should run the commands here")
if runCommands() {
log.Warn("EVERYTHING WORKED")
} else {
log.Warn("EVERYTHING DID NOT WORK")
}
})
reposwin.Draw()
}