guireleaser/main.go

310 lines
8.6 KiB
Go
Raw Normal View History

// This is a simple example
package main
import (
"os"
"os/user"
"embed"
"go.wit.com/log"
"go.wit.com/gui/gui"
"go.wit.com/gui/gadgets"
"go.wit.com/gui/lib/repostatus"
)
//go:embed resources/*
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)
}
// just returns if something exists at the path name (file, directory, whatever)
func doesExist(path string) bool {
if _, err := os.Stat(path); err != nil {
if os.IsNotExist(err) {
return false
}
}
return true
}
func globalBuildOptions(box *gui.Node) {
var setCurrentBranch *gui.Node
group1 := box.NewGroup("Global Build Options")
groupvbox := group1.NewBox("bw vbox", false)
grouphbox := groupvbox.NewBox("bw hbox", true)
guiBranch := gadgets.NewBasicCombobox(grouphbox, "Select GUI branch")
guiBranch.Add("guimaster")
guiBranch.Add("guidevel")
guiBranch.Add("jcarr")
guiBranch.Custom = func () {
tmp := "set all current branchs to " + guiBranch.Get()
setCurrentBranch.Set(tmp)
}
setCurrentBranch = groupvbox.NewButton("set current branch to", func () {
for _, repo := range allrepos {
repo.status.Update()
}
})
groupvbox.NewButton("go get everything in configfile", func () {
var newCmds [][]string
// usr, _ := user.Current()
newCmds = append(newCmds, []string{"cd", "go/src/gui/app/myrepos"})
repos := myrepolist()
for _, line := range repos {
log.Warn("repo =", line)
path, _, _, _ := splitLine(line)
if doesExist("/home/jcarr/go/src/" + path) {
continue
}
newCmds = append(newCmds, []string{"go", "get", "-v", path})
}
script = newCmds
doit.Enable()
setGitCommands()
})
groupvbox.NewButton("status.Update() all", func () {
for _, repo := range allrepos {
repo.status.Update()
}
})
groupvbox.NewButton("rescan all", func () {
for _, repo := range allrepos {
repo.newScan()
}
})
}
// This creates a window
func repoworld() {
reposwin = gadgets.NewBasicWindow(myGui, "autotypist for GO & git. it types faster than you can.")
reposwin.Make()
reposwin.StandardExit()
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)
globalBuildOptions(box2)
// gofmt -w -r "go.wit.com/gui -> go.wit.com/gui/gui" .
group2 := box2.NewGroup("Global Reset Options")
buildOptions := group2.NewGrid("buildOptions",2, 1)
buildOptions.NewLabel("delete 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("delete 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
}
}
newCmds = append(newCmds, []string{"cd", "."})
newCmds = append(newCmds, []string{"rm", "-rf", "go/src/"})
newCmds = append(newCmds, []string{"chmod", "700", "-R", "go/pkg/"})
newCmds = append(newCmds, []string{"rm", "-rf", "go/pkg/"})
if dirty {
newCmds = append(newCmds, []string{"can't do this with dirty repos"})
doit.Disable()
} else {
doit.Enable()
}
script = newCmds
setGitCommands()
})
buildOptions.NewLabel("rebuild autotypist")
buildOptions.NewButton("go get", func () {
var newCmds [][]string
newCmds = append(newCmds, []string{"cd", "."})
newCmds = append(newCmds, []string{"mkdir", "-p", "go/src/go.wit.com/apps/"})
newCmds = append(newCmds, []string{"cd", "go/src/go.wit.com/apps/"})
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", "go.wit.com/gui/toolkits"})
newCmds = append(newCmds, []string{"cd", "go/src/go.wit.com/gui/toolkits/andlabs"})
newCmds = append(newCmds, []string{"go", "get", "-v", "-u", "."})
newCmds = append(newCmds, []string{"cd", "go/src/go.wit.com/gui/toolkits/gocui"})
newCmds = append(newCmds, []string{"go", "get", "-v", "-u", "."})
newCmds = append(newCmds, []string{"cd", "go/src/go.wit.com/gui/toolkits"})
newCmds = append(newCmds, []string{"make"})
newCmds = append(newCmds, []string{"cd", "go/src/go.wit.com/apps/myrepos"})
newCmds = append(newCmds, []string{"make"})
script = newCmds
setGitCommands()
doit.Enable()
})
buildOptions.NewSeparator("endStatusScans")
buildOptions.NewSeparator("endStatusScans")
buildOptions.NewLabel("cmd")
cmds = buildOptions.NewLabel("ls")
buildOptions.NewLabel("--dry-run")
dryrun = buildOptions.NewButton("show commands", func () {
if goMake("--dry-run") {
log.Warn("EVERYTHING MIGHT HAVE WORKED")
} else {
log.Warn("EVERYTHING WILL NOT WORK")
dryrun.Disable()
}
})
buildOptions.NewLabel("Doit")
doit = buildOptions.NewButton("run commands", func () {
doit.Disable()
log.Warn("should run the commands here")
// true here means dryrun == true. it's confusingly named
if goMake("--doit") {
log.Warn("EVERYTHING WORKED")
} else {
log.Warn("EVERYTHING DID NOT WORK")
}
})
reposwin.Draw()
}