From e240e4149f92ada886884f542522d9b739df450d Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Mon, 15 Jan 2024 08:11:08 -0600 Subject: [PATCH] remove perfect branches works Signed-off-by: Jeff Carr --- .gitignore | 1 + Makefile | 8 +++- main.go | 118 +++++++++++++++++++++++++++++++++++++++++------------ myrepolist | 15 +++++++ scan.go | 41 ++++++++++++------- structs.go | 9 ++-- unix.go | 40 ++++++++++++++++++ 7 files changed, 185 insertions(+), 47 deletions(-) create mode 100644 myrepolist create mode 100644 unix.go diff --git a/.gitignore b/.gitignore index 81830db..5a44dfc 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ !Makefile !*.go !go.* +!myrepolist diff --git a/Makefile b/Makefile index 074dad4..6d0f60e 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,11 @@ all: echo "build it!" - go build -v -x - ./myrepos + -mkdir -p plugins/ + -cp myrepolist plugins/ + -cp ~/go/src/go.wit.com/gui/toolkits/*.so plugins/ + go install -v -x + # go build -v -x + myrepos # ./myrepos >/tmp/myrepos.stderr 2>&1 redomod: diff --git a/main.go b/main.go index 0178810..6a12e11 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "os/user" + "embed" "go.wit.com/log" @@ -11,11 +12,15 @@ import ( "go.wit.com/gui/gadgets/repostatus" ) +//go:embed plugins/* +var resToolkit embed.FS + func main() { - myGui = gui.New().Default() + myGui = gui.New() + myGui.InitEmbed(resToolkit) + myGui.Default() repoworld() - gui.Watchdog() } @@ -30,19 +35,19 @@ func addRepo(grid *gui.Node, path string, master string, devel string, user stri } newRepo.path = path - newRepo.pLabel = grid.NewLabel(path) - newRepo.bLabel = grid.NewLabel("") - newRepo.lastLabel = grid.NewLabel("") - newRepo.vLabel = grid.NewLabel("") + newRepo.pLabel = grid.NewLabel(path).SetProgName("path") + newRepo.lastTag = grid.NewLabel("").SetProgName("lastTag") + newRepo.vLabel = grid.NewLabel("").SetProgName("current") - newRepo.masterName = grid.NewLabel("") - newRepo.masterVersion = grid.NewLabel("") - newRepo.develName = grid.NewLabel("") - newRepo.develVersion = grid.NewLabel("") - newRepo.userName = grid.NewLabel("") - newRepo.userVersion = grid.NewLabel("") + 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() }) @@ -63,6 +68,7 @@ func addRepo(grid *gui.Node, path string, master string, devel string, user stri 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") @@ -92,13 +98,11 @@ func repoworld() { reposbox = reposwin.Box().NewBox("bw vbox", false) reposgroup = reposbox.NewGroup("go repositories (read from ~/.config/myrepolist)") - reposgrid = reposgroup.NewGrid("test", 15, 1) + reposgrid = reposgroup.NewGrid("test", 11, 1) reposgrid.NewLabel("") - reposgrid.NewLabel("branch") - reposgrid.NewLabel("last tag") - reposgrid.NewLabel("Current Version") - // reposgrid.NewLabel("tags") + reposgrid.NewLabel("last tag").SetProgName("last tag") + reposgrid.NewLabel("Current Version").SetProgName("Current Version") reposgrid.NewLabel("master") reposgrid.NewLabel("version") reposgrid.NewLabel("devel") @@ -106,9 +110,6 @@ func repoworld() { reposgrid.NewLabel("user") reposgrid.NewLabel("version") reposgrid.NewLabel("Status") - reposgrid.NewLabel("rescan") - reposgrid.NewLabel("Update()") - reposgrid.NewLabel("Hide()") reposgrid.NewLabel("Show()") repos := myrepolist() @@ -123,24 +124,87 @@ func repoworld() { } box2 := reposwin.Box().NewBox("bw vbox", false) - box2.NewButton("reposgrid.Margin()", func () { - log.Warn("reposgrid.Margin() RUN NOW") - reposgrid.Margin() - log.Warn("reposgrid.Pad() RUN NOW") - reposgrid.Pad() + + 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() }) - box2.NewButton("status.Update() all", func () { + 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("repo pkg's") + buildOptions.NewButton("rm ~/go/pkg/", func () { + log.Warn("delete every repo here but skip dirty ones") + cmds.Set("rm -rf ~/go/pkg/") + }) + + buildOptions.NewButton("status.Update() all", func () { for _, repo := range allrepos { repo.status.Update() } }) - box2.NewButton("rescan all", func () { + buildOptions.NewButton("rescan all", func () { for _, repo := range allrepos { repo.newScan() } }) + buildOptions.NewLabel("cmd") + cmds = buildOptions.NewLabel("ls") + + 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() } diff --git a/myrepolist b/myrepolist new file mode 100644 index 0000000..28853ee --- /dev/null +++ b/myrepolist @@ -0,0 +1,15 @@ +go.wit.com/log + +go.wit.com/gui/widget +go.wit.com/gui/gui +go.wit.com/gui/toolkits +go.wit.com/gui/debugger + +go.wit.com/gui/gadgets +go.wit.com/gui/gadgets/repostatus +go.wit.com/gui/digitalocean +go.wit.com/gui/cloudflare + +go.wit.com/apps/control-panel-dns main +go.wit.com/apps/control-panel-vpn +go.wit.com/apps/autotypist diff --git a/scan.go b/scan.go index d35dee4..b10af4f 100644 --- a/scan.go +++ b/scan.go @@ -36,26 +36,37 @@ func (r *repo) newScan() bool { cbname := r.status.GetCurrentBranchName() cbversion := r.status.GetCurrentBranchVersion() - ltversion := r.status.GetLastTagVersion() - r.lastLabel.Set(cbname + "\n" + cbversion) - r.vLabel.Set(cbname + "\n" + ltversion) + lasttag := r.status.GetLastTagVersion() + r.lastTag.Set(lasttag) + r.vLabel.Set(cbname + " " + cbversion) - if r.status.CheckDirty() { - log.Warn("CheckDirty() true") - r.dirtyLabel.Set("dirty") + status := r.getStatus() + if status == "dirty" { + r.dirtyLabel.Set(status) return false } - log.Warn("CheckDirty() no") - r.dirtyLabel.Set("not dirty") + if status == "merge" { + r.dirtyLabel.Set(status) + return false + } + if status == "PERFECT" { + r.dirtyLabel.Set(status) + return true + } + r.dirtyLabel.Set("unknown " + status) + return false +} + +func (r *repo) getStatus() string { + if r.status.CheckDirty() { + log.Warn("CheckDirty() true") + return "dirty" + } if r.status.CheckBranches() { log.Warn("Branches are Perfect") - r.dirtyLabel.SetText("PERFECT") - return true - } else { - log.Warn("Branches are not Perfect") - r.dirtyLabel.SetText("merge") + return "PERFECT" } - - return false + log.Warn("Branches are not Perfect") + return "merge" } diff --git a/structs.go b/structs.go index 9d02c2b..39990c8 100644 --- a/structs.go +++ b/structs.go @@ -13,6 +13,9 @@ var reposwin *gadgets.BasicWindow var reposbox *gui.Node var reposgrid *gui.Node var reposgroup *gui.Node +var cmds *gui.Node +var script [][]string +var doit *gui.Node var allrepos []*repo @@ -20,11 +23,11 @@ type repo struct { path string lasttagrev string lasttag string - tags []string + // tags []string pLabel *gui.Node // path label - bLabel *gui.Node // branch label - lastLabel *gui.Node // last tagged version label + // bLabel *gui.Node // branch label + lastTag *gui.Node // last tagged version label vLabel *gui.Node // version label // tagsDrop *gui.Node // list of all tags dirtyLabel *gui.Node // git state (dirty or not?) diff --git a/unix.go b/unix.go new file mode 100644 index 0000000..adb0b95 --- /dev/null +++ b/unix.go @@ -0,0 +1,40 @@ +package main + +import ( + "strings" + "go.wit.com/log" + + "go.wit.com/gui/gadgets/repostatus" +) + +var repopath string = "/home/jcarr/" + +func runCommands() bool { + for _, line := range script { + s := strings.Join(line, " ") + log.Warn("NEED TO RUN:", s) + err, b, output := repostatus.RunCmd(repopath, line) + if err != nil { + log.Warn("ABEND EXECUTION") + log.Warn("error =", err) + log.Warn("output =", output) + return false + } + log.Warn("Returned with b =", b) + log.Warn("output was =", output) + log.Warn("RUN DONE") + } + return true +} + +func setGitCommands() { + var tmp []string + // convert to displayable to the user text + for _, line := range script { + s := strings.Join(line, " ") + log.Warn("s =", s) + tmp = append(tmp, s) + } + cmds.Set(strings.Join(tmp, "\n")) +} +