autotypist/globalBuildOptions.go

121 lines
3.1 KiB
Go
Raw Normal View History

package main
import (
"os"
"os/user"
"path/filepath"
"go.wit.com/log"
"go.wit.com/gui"
"go.wit.com/lib/gadgets"
"go.wit.com/lib/gui/repostatus"
)
func doesExist(path string) bool {
if _, err := os.Stat(path); err != nil {
if os.IsNotExist(err) {
return false
}
}
return true
}
// only errors on bad errors
func quickCmd(fullpath string, cmd []string) bool {
var err error
var b bool
var output string
if me.autoWorkingPwd.String() != fullpath {
me.autoWorkingPwd.SetValue(fullpath)
}
if me.autoDryRun.Checked() {
log.Warn("RUN --dry-run", fullpath, cmd)
return false
} else {
log.Warn("RUN:", fullpath, cmd)
}
err, b, output = repostatus.RunCmd(fullpath, cmd)
if err != nil {
log.Warn("cmd =", cmd)
log.Warn("err =", err)
log.Warn("b =", b)
log.Warn("output =", string(output))
return false
} else if !b {
log.Warn("b =", b)
log.Warn("output =", string(output))
return true
}
log.Warn("output = ", string(output))
return true
}
func globalBuildOptions(vbox *gui.Node) {
group1 := vbox.NewGroup("Global Build Options")
grid := group1.NewGrid("buildOptions", 2, 1)
me.autoWorkingPwd = gadgets.NewOneLiner(grid, "working directory (pwd)")
me.userHomePwd = gadgets.NewOneLiner(grid, "user home")
me.goSrcPwd = gadgets.NewOneLiner(grid, "go src home")
usr, _ := user.Current()
homeDir, err := os.UserHomeDir()
if err != nil {
log.Warn("Error getting home directory:", err)
homeDir = "/home/autotypist"
}
me.userHomePwd.SetText(homeDir)
srcDir := filepath.Join(homeDir, "go/src")
me.goSrcPwd.SetText(srcDir)
me.mainBranch = gadgets.NewBasicCombobox(grid, "default main branch")
me.mainBranch.AddText("gitea server default")
me.mainBranch.Disable()
me.develBranch = gadgets.NewBasicCombobox(grid, "default devel branch")
me.develBranch.AddText("devel")
me.userBranch = gadgets.NewBasicCombobox(grid, "default user branch")
me.userBranch.AddText(usr.Username)
var newBranch *gui.Node
var setBranchB *gui.Node
// gadgets.OneLiner(grid, "default user branch")
// select the branch you want to test, build and develop against
// this lets you select your user branch, but, when you are happy
// you can merge everything into the devel branch and make sure it actually
// works. Then, when that is good, merge and version everything in master
setBranchB = grid.NewButton("set current branch to:", func() {
log.Warn("set current branch to:", newBranch.String())
/*
me.toMoveToBranch = guiBranch.String()
setCurrentBranch.SetLabel("set all branches to " + me.toMoveToBranch)
me.mainBranch.Disable()
*/
for _, repo := range me.allrepos {
if repo.status.CheckoutMaster() {
log.Warn("set master branch worked", repo.String)
repo.newScan()
} else {
log.Warn("set master branch failed", repo.String)
repo.newScan()
}
// return
}
})
newBranch = grid.NewCombobox()
newBranch.AddText("master")
newBranch.AddText("devel")
newBranch.AddText(usr.Username)
newBranch.SetText(usr.Username)
newBranch.Custom = func() {
setBranchB.SetLabel("set current branches to " + newBranch.String())
}
}