From 816760d1372d6d1922a9916f3150e49f3fd562cd Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 5 Dec 2024 12:29:47 -0600 Subject: developing on this now --- Makefile | 22 ++--- argv.go | 47 +++++----- debugger.go | 31 ------- delete.go | 41 --------- doCobol.go | 162 +++++++++++++++++++++++++++++++++ doDebugger.go | 31 +++++++ doDelete.go | 41 +++++++++ doGitPull.go | 7 ++ doGui.go | 40 +++++++++ doRedoGoMod.go | 35 ++++++++ doScan.go | 5 ++ findConfig.go | 85 ++++++++++++++++++ findRepos.go | 40 +++++++++ list.go | 180 ------------------------------------- main.go | 96 ++++++++------------ repoview.go | 4 +- scan.go | 9 -- structs.go | 10 ++- subitPatches.go | 240 +++++++++++++++++++++++++++++++++++++++++++++++++ submitPatches.go | 267 ------------------------------------------------------- 20 files changed, 767 insertions(+), 626 deletions(-) delete mode 100644 debugger.go delete mode 100644 delete.go create mode 100644 doCobol.go create mode 100644 doDebugger.go create mode 100644 doDelete.go create mode 100644 doGitPull.go create mode 100644 doGui.go create mode 100644 doRedoGoMod.go create mode 100644 doScan.go create mode 100644 findConfig.go create mode 100644 findRepos.go delete mode 100644 list.go delete mode 100644 scan.go create mode 100644 subitPatches.go delete mode 100644 submitPatches.go diff --git a/Makefile b/Makefile index c22d05e..d12558b 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ VERSION = $(shell git describe --tags) BUILDTIME = $(shell date +%Y.%m.%d) all: goimports vet install - forge -h + forge vet: @GO111MODULE=off go vet @@ -33,34 +33,34 @@ redomod: GO111MODULE= go mod tidy redomod-all: - forge --RedoGoMod + forge --do-RedoGoMod redomod-erase: - forge --RedoGoMod --erase + forge --do-RedoGoMod --do-erase list: install reset - forge --list + forge --do-list -list-private: install +private: install reset - forge --list --private + forge --find-private list-fix: install reset - forge --list --fix + forge --do-list --do-fix list-readonly: install reset - forge --list --readonly + forge --do-list --find-readonly list-config: install - forge --list-conf + forge --config scan: install reset - forge --scan + forge --do-scan mine: install - forge --mine + forge --find-mine diff --git a/argv.go b/argv.go index 809b7d8..ff8a1f0 100644 --- a/argv.go +++ b/argv.go @@ -7,22 +7,24 @@ package main var argv args type args struct { - List bool `arg:"--list" help:"list found repos"` - ListConf bool `arg:"--list-conf" help:"list your .config/forge/ configuration"` - Scan bool `arg:"--scan" help:"rescan your repos"` - ReadOnly bool `arg:"--readonly" help:"include read-only repos"` - Mine bool `arg:"--mine" help:"download private and writeable repos"` - Favorites bool `arg:"--favorites" help:"download repos marked as favorites"` - GitPull bool `arg:"--git-pull" help:"run 'git pull' on all your repos"` - Build bool `arg:"--build" default:"true" help:"also try to build it"` - Install bool `arg:"--install" help:"try to install every binary package"` - RedoGoMod bool `arg:"--RedoGoMod" help:"remake all the go.sum and go.mod files"` - DryRun bool `arg:"--dry-run" help:"show what would be run"` - Fix bool `arg:"--fix" help:"fix config, save config & exit"` - Clone bool `arg:"--clone" help:"go-clone things you are missing"` - Force bool `arg:"--force" help:"force redo go-clone"` - Erase bool `arg:"--erase" help:"erase"` - Private bool `arg:"--private" help:"list private repos in .config/forge/"` + Config bool `arg:"--config" help:"work from your .config/forge/ configuration"` + FindAll bool `arg:"--find-all" help:"select every repo"` + FindReadOnly bool `arg:"--find-readonly" help:"include read-only repos"` + FindMine bool `arg:"--find-mine" help:"download private and writeable repos"` + FindFavorites bool `arg:"--find-favorites" help:"download repos marked as favorites"` + FindPrivate bool `arg:"--find-private" help:"list private repos in .config/forge/"` + DoList bool `arg:"--do-list" help:"list found repos"` + DoScan bool `arg:"--do-scan" help:"rescan your repos"` + DoClone bool `arg:"--do-clone" help:"go-clone things you are missing"` + DoForce bool `arg:"--do-force" help:"force redo go-clone"` + DoGitPull bool `arg:"--do-git-pull" help:"run 'git pull' on all your repos"` + DoBuild bool `arg:"--do-build" default:"true" help:"also try to build it"` + DoInstall bool `arg:"--do-install" help:"try to install every binary package"` + DoRedoGoMod bool `arg:"--do-RedoGoMod" help:"remake all the go.sum and go.mod files"` + DoErase bool `arg:"--do-EraseGoMod" help:"erase the go.mod and go.sum files"` + DoGui bool `arg:"--do-gui" help:"test the gui"` + DryRun bool `arg:"--dry-run" help:"show what would be run"` + Fix bool `arg:"--fix" help:"fix config, save config & exit"` } func (args) Version() string { @@ -33,14 +35,13 @@ func (a args) Description() string { return ` forge -- in the spirit of things like sourceforge -Repository configuration is stored in .config/forge/forge.text - Examples: - forge --list # list found repos - forge --mine # download your private and writable repos - forge --favorites # clone repos you marked as favorites + forge --config # shows your forge config (~/.config/forge/) + forge --mine # find your private and writable repos + forge --favorites # find configured as favorites + forge --git-pull # run 'git pull' in every repo - forge --build # build every binary package - forge --install # install every binary package + forge --build --dry-run # build every binary package (but just show what would run) + forge --mine --clone # clone every package you have in your config file ` } diff --git a/debugger.go b/debugger.go deleted file mode 100644 index b2fa5dc..0000000 --- a/debugger.go +++ /dev/null @@ -1,31 +0,0 @@ -package main - -/* - this parses the command line arguements - - this enables command line options from other packages like 'gui' and 'log' -*/ - -import ( - "go.wit.com/lib/debugger" - "go.wit.com/lib/gui/logsettings" - "go.wit.com/log" -) - -func init() { - if debugger.ArgDebug() { - log.Info("cmd line --debugger == true") - go func() { - log.Sleep(2) - debugger.DebugWindow() - }() - } - if debugger.ArgLogger() { - log.Info("cmd line --loggger == true") - go func() { - log.Sleep(4) - logsettings.LogWindow() - logsettings.LogWindow() - }() - } -} diff --git a/delete.go b/delete.go deleted file mode 100644 index b0ab05e..0000000 --- a/delete.go +++ /dev/null @@ -1,41 +0,0 @@ -package main - -import ( - "go.wit.com/lib/protobuf/gitpb" - "go.wit.com/log" -) - -func Delete(repo *gitpb.Repo, s map[string]string) bool { - if repo.Published == nil { - log.Info("published is nil", repo.Published) - } else { - log.Info("published len", repo.Published.Len()) - } - - // add a new one here - newr := gitpb.Repo{ - FullPath: repo.FullPath, - GoPath: repo.GoPath, - URL: repo.URL, - Tags: repo.Tags, - LastPull: repo.LastPull, - MasterBranchName: repo.MasterBranchName, - DevelBranchName: repo.DevelBranchName, - UserBranchName: repo.UserBranchName, - GoLibrary: repo.GoLibrary, - GoBinary: repo.GoBinary, - GoPrimitive: repo.GoPrimitive, - GoPlugin: repo.GoPlugin, - GoDeps: repo.GoDeps, - LastGoDep: repo.LastGoDep, - Dirty: repo.Dirty, - Published: repo.Published, - TargetVersion: repo.TargetVersion, - ReadOnly: repo.ReadOnly, - GoProtobuf: repo.GoProtobuf, - } - if argv.Fix { - me.forge.Repos.AppendUniqueGoPath(&newr) - } - return true -} diff --git a/doCobol.go b/doCobol.go new file mode 100644 index 0000000..678d17a --- /dev/null +++ b/doCobol.go @@ -0,0 +1,162 @@ +package main + +import ( + "fmt" + "os" + + "go.wit.com/lib/protobuf/gitpb" + "go.wit.com/log" +) + +// ah yes, COBOL. what a throwback. for those that know +// then you know exactly what is in this file. For those that don't, here it is: + +// All this does is output human readable text formatted to be viewable on +// a console with a fixed with font. AKA: a typerwriter. Which is exactly +// what COBOL did in the 1970's (60s? notsure) And the 80s. + +// So, you want to dump out stuff on the console. Let's see. Something like + +/* + forge --favorites + + go.wit.com/apps/myapp v0.2.0 (installed) + go.wit.com/lib/somethingfun v0.0.7 (not downloaded) +*/ + +// anyway, you get the idea. This is also called COBOL because it does on +// thing and truncates every line output to the columns you see with stty -a +// my monitor is huge, so it's not going to work at 80x24. 160x48 is better +// actually, I'd predict some of these will probably end up 240 wide +// long live good eyesight and 4K monitors! + +func doCobol() { + log.DaemonMode(true) + + log.Info(standardStart5("gopath", "cur name", "master", "user", "repo type")) + repos := me.found.SortByGoPath() + for repos.Scan() { + repo := repos.Next() + verifyPrint(repo) + } +} + +func standardStart5(arg1, arg2, arg3, arg4, arg5 string) string { + len1 := 40 + len2 := 12 + len3 := 12 + len4 := 16 + len5 := 8 + var s string + if len(arg1) > len1 { + arg1 = arg1[:len1] + } + s = "%-" + fmt.Sprintf("%d", len1) + "s " + if len(arg2) > len2 { + arg2 = arg2[:len2] + } + s += "%-" + fmt.Sprintf("%d", len2) + "s " + if len(arg3) > len3 { + arg3 = arg3[:len3] + } + s += "%-" + fmt.Sprintf("%d", len3) + "s " + if len(arg4) > len4 { + arg4 = arg4[:len4] + } + s += "%-" + fmt.Sprintf("%d", len4) + "s " + if len(arg5) > len5 { + arg5 = arg5[:len5] + } + s += "%-" + fmt.Sprintf("%d", len5) + "s" + return fmt.Sprintf(s, arg1, arg2, arg3, arg4, arg5) +} + +func verifyPrint(repo *gitpb.Repo) { + var end string + if repo.CheckDirty() { + end += "(dirty) " + } + s := make(map[string]string) + if !verify(repo, s) { + log.Info("going to delete", repo.GoPath) + if argv.Fix { + me.forge.Repos.DeleteByGoPath(repo.GetGoPath()) + me.forge.Repos.ConfigSave() + } else { + log.Info("need argv --real to delete", repo.GoPath) + os.Exit(0) + } + } + if me.forge.Config.IsReadOnly(repo.GoPath) && !argv.FindReadOnly { + if repo.ReadOnly { + return + } + log.Info("readonly flag on repo is wrong", repo.GoPath) + return + } + + var mhort string = s["mver"] + var uhort string = s["uver"] + var cname string = s["cname"] + + // start := fmt.Sprintf("%-40s %-12s %-12s %-12s %-8s", s["gopath"], cname, mhort, uhort, s["rtype"]) + start := standardStart5(s["gopath"], cname, mhort, uhort, s["rtype"]) + + if me.forge.Config.IsReadOnly(repo.GoPath) { + end += "(readonly) " + } + + log.Info(start, end) +} + +func verify(repo *gitpb.Repo, s map[string]string) bool { + if !repo.IsValid() { + return false + } + s["gopath"] = repo.GetGoPath() + s["rtype"] = repo.RepoType() + + s["mname"] = repo.GetMasterBranchName() + if s["mname"] == "" { + log.Info("verify() no master branch name", repo.GoPath) + s["mver"] = repo.GetMasterVersion() + return false + } + // only verify the master branch name with read-only repos + if me.forge.Config.IsReadOnly(repo.GoPath) { + s["mver"] = repo.GetMasterVersion() + return true + } + + s["dname"] = repo.GetDevelBranchName() + if s["dname"] == "" { + log.Info("verify() no devel branch name", repo.GoPath) + return false + } + s["uname"] = repo.GetUserBranchName() + if s["uname"] == "" { + log.Info("verify() no user branch name", repo.GoPath) + return false + } + s["cname"] = repo.GetCurrentBranchName() + + s["mver"] = repo.GetMasterVersion() + if s["mver"] == "" { + log.Info("verify() no master branch name", repo.GoPath, repo.GetMasterBranchName()) + return false + } + s["dver"] = repo.GetDevelVersion() + if s["dver"] == "" { + log.Info("verify() no devel branch name", repo.GoPath, repo.GetDevelBranchName()) + return false + } + s["uver"] = repo.GetUserVersion() + if s["uver"] == "" { + log.Info("verify() no user branch name", repo.GoPath, repo.GetUserBranchName()) + return false + } + s["cver"] = repo.GetCurrentBranchVersion() + s["url"] = repo.URL + + return true +} diff --git a/doDebugger.go b/doDebugger.go new file mode 100644 index 0000000..b2fa5dc --- /dev/null +++ b/doDebugger.go @@ -0,0 +1,31 @@ +package main + +/* + this parses the command line arguements + + this enables command line options from other packages like 'gui' and 'log' +*/ + +import ( + "go.wit.com/lib/debugger" + "go.wit.com/lib/gui/logsettings" + "go.wit.com/log" +) + +func init() { + if debugger.ArgDebug() { + log.Info("cmd line --debugger == true") + go func() { + log.Sleep(2) + debugger.DebugWindow() + }() + } + if debugger.ArgLogger() { + log.Info("cmd line --loggger == true") + go func() { + log.Sleep(4) + logsettings.LogWindow() + logsettings.LogWindow() + }() + } +} diff --git a/doDelete.go b/doDelete.go new file mode 100644 index 0000000..b0ab05e --- /dev/null +++ b/doDelete.go @@ -0,0 +1,41 @@ +package main + +import ( + "go.wit.com/lib/protobuf/gitpb" + "go.wit.com/log" +) + +func Delete(repo *gitpb.Repo, s map[string]string) bool { + if repo.Published == nil { + log.Info("published is nil", repo.Published) + } else { + log.Info("published len", repo.Published.Len()) + } + + // add a new one here + newr := gitpb.Repo{ + FullPath: repo.FullPath, + GoPath: repo.GoPath, + URL: repo.URL, + Tags: repo.Tags, + LastPull: repo.LastPull, + MasterBranchName: repo.MasterBranchName, + DevelBranchName: repo.DevelBranchName, + UserBranchName: repo.UserBranchName, + GoLibrary: repo.GoLibrary, + GoBinary: repo.GoBinary, + GoPrimitive: repo.GoPrimitive, + GoPlugin: repo.GoPlugin, + GoDeps: repo.GoDeps, + LastGoDep: repo.LastGoDep, + Dirty: repo.Dirty, + Published: repo.Published, + TargetVersion: repo.TargetVersion, + ReadOnly: repo.ReadOnly, + GoProtobuf: repo.GoProtobuf, + } + if argv.Fix { + me.forge.Repos.AppendUniqueGoPath(&newr) + } + return true +} diff --git a/doGitPull.go b/doGitPull.go new file mode 100644 index 0000000..cca3b19 --- /dev/null +++ b/doGitPull.go @@ -0,0 +1,7 @@ +package main + +// An app to submit patches for the 30 GO GUI repos + +func doGitPull() { + me.found.RillGitPull() +} diff --git a/doGui.go b/doGui.go new file mode 100644 index 0000000..b412df5 --- /dev/null +++ b/doGui.go @@ -0,0 +1,40 @@ +package main + +// An app to submit patches for the 30 GO GUI repos + +import ( + "go.wit.com/gui" + "go.wit.com/lib/gadgets" + "go.wit.com/log" +) + +func doGui() { + me.myGui = gui.New() + me.myGui.Default() + + me.mainWindow = gadgets.RawBasicWindow("submit & test patchsets") + me.mainWindow.Make() + me.mainWindow.Show() + me.mainbox = me.mainWindow.Box() + + // disable the interface while everything is scanned + me.Disable() + + vbox2 := me.mainbox.NewVerticalBox("BOX2") + globalBuildOptions(vbox2) + me.summary = submitPatchesBox(vbox2) + + me.repos = makeRepoView() + + // processing is done. update the repo summary box + me.summary.Update() + + me.Enable() + + // intermittently scans the status indefinitly + me.repos.View.Watchdog(func() { + log.Info("In main()") + // processing is done. update the repo summary box + me.summary.Update() + }) +} diff --git a/doRedoGoMod.go b/doRedoGoMod.go new file mode 100644 index 0000000..6e9f979 --- /dev/null +++ b/doRedoGoMod.go @@ -0,0 +1,35 @@ +package main + +// An app to submit patches for the 30 GO GUI repos + +import ( + "os" + + "go.wit.com/log" +) + +func doRedoGoMod() { + me.forge.RillRedoGoMod() + os.Exit(0) + repos := me.forge.Repos.SortByGoPath() + for repos.Scan() { + repo := repos.Next() + if !repo.IsValid() { + log.Printf("%10s %-50s", "old?", repo.GetGoPath()) + continue + } + log.Printf("running on: %-50s", repo.GetGoPath()) + repo.RedoGoMod() + } +} + +func doEraseGoMod() { + /* + var cmds [][]string + cmds = append(cmds, []string{"rm", "-f", "go.mod", "go.sum"}) + errs := me.forge.RillCmds(me.packs, cmds) + foreach x, y := range errs { + log.Info("EraseGoMod() error", x.GoPath, y) + } + */ +} diff --git a/doScan.go b/doScan.go new file mode 100644 index 0000000..562304f --- /dev/null +++ b/doScan.go @@ -0,0 +1,5 @@ +package main + +func doScan() { + me.forge.ScanGoSrc() +} diff --git a/findConfig.go b/findConfig.go new file mode 100644 index 0000000..34c8f18 --- /dev/null +++ b/findConfig.go @@ -0,0 +1,85 @@ +package main + +import "go.wit.com/log" + +func findPrivate() { + repos := me.forge.Repos.SortByGoPath() + for repos.Scan() { + repo := repos.Next() + if me.forge.Config.IsPrivate(repo.GoPath) { + me.found.AppendUniqueGoPath(repo) + } + } +} + +// finds repos that are writable +func findMine() { + log.Printf("get mine %s\n", me.forge.GetGoSrc()) + repos := me.forge.Repos.SortByGoPath() + for repos.Scan() { + repo := repos.Next() + if me.forge.Config.IsWritable(repo.GoPath) { + me.found.AppendUniqueGoPath(repo) + } + } +} + +// finds repos that are writable +func findFavorites() { + log.Printf("get mine %s\n", me.forge.GetGoSrc()) + repos := me.forge.Repos.SortByGoPath() + for repos.Scan() { + repo := repos.Next() + if me.forge.Config.IsFavorite(repo.GoPath) { + me.found.AppendUniqueGoPath(repo) + } + } +} + +// retuns true if nothing was done +func findConfig() bool { + if argv.FindMine { + findConfigMine() + return false + } + if argv.FindAll { + findConfigAll() + return false + } + + return true +} + +// finds config repos that are writable +func findConfigMine() { + loop := me.forge.Config.SortByGoPath() + for loop.Scan() { + r := loop.Next() + gopath := r.GoPath + if r.GetDirectory() { + continue + } + if me.forge.Config.IsWritable(gopath) { + log.Info("mine:", gopath) + me.foundPaths = append(me.foundPaths, gopath) + continue + } + } +} + +// get everything in your config +func findConfigAll() { + loop := me.forge.Config.SortByGoPath() + for loop.Scan() { + r := loop.Next() + gopath := r.GoPath + if r.GetDirectory() { + continue + } + if me.forge.Config.IsWritable(gopath) { + log.Info("mine:", gopath) + me.foundPaths = append(me.foundPaths, gopath) + continue + } + } +} diff --git a/findRepos.go b/findRepos.go new file mode 100644 index 0000000..1463d09 --- /dev/null +++ b/findRepos.go @@ -0,0 +1,40 @@ +package main + +import ( + "go.wit.com/log" +) + +func findRepos() { + if argv.FindAll { + var configsave bool + repos := me.forge.Repos.SortByGoPath() + for repos.Scan() { + repo := repos.Next() + if me.forge.Config.IsReadOnly(repo.GoPath) && !argv.FindReadOnly { + if repo.ReadOnly { + continue + } + log.Info("todo: ConfigSave() readonly flag on repo is wrong", repo.GoPath) + repo.ReadOnly = true + configsave = true + continue + } + me.found.AppendUniqueGoPath(repo) + } + if configsave { + log.Info("should ConfigSave here") + me.forge.Repos.ConfigSave() + } + } + + if argv.FindPrivate { + findPrivate() + } + + if argv.FindMine { + findMine() + } + if argv.FindFavorites { + findFavorites() + } +} diff --git a/list.go b/list.go deleted file mode 100644 index 3110d5a..0000000 --- a/list.go +++ /dev/null @@ -1,180 +0,0 @@ -package main - -import ( - "fmt" - "os" - - "go.wit.com/lib/protobuf/gitpb" - "go.wit.com/log" -) - -func list() { - log.DaemonMode(true) - if argv.Private { - // GetPrivate() - return - } - - if argv.Mine { - log.Printf("get mine %s\n", me.forge.GetGoSrc()) - repos := me.forge.Repos.SortByGoPath() - for repos.Scan() { - repo := repos.Next() - if me.forge.Config.IsWritable(repo.GoPath) { - verifyPrint(repo) - } - } - os.Exit(0) - } - - if argv.Favorites { - log.Printf("get favorites\n") - os.Exit(0) - } - - if argv.List { - var configsave bool - repos := me.forge.Repos.SortByGoPath() - for repos.Scan() { - repo := repos.Next() - if me.forge.Config.IsReadOnly(repo.GoPath) && !argv.ReadOnly { - if repo.ReadOnly { - continue - } - log.Info("todo: ConfigSave() readonly flag on repo is wrong", repo.GoPath) - repo.ReadOnly = true - configsave = true - continue - } - verifyPrint(repo) - } - if configsave { - log.Info("should ConfigSave here") - me.forge.Repos.ConfigSave() - } - os.Exit(0) - } -} - -func verifyPrint(repo *gitpb.Repo) { - var end string - if repo.CheckDirty() { - end += "(dirty) " - } - s := make(map[string]string) - if !verify(repo, s) { - log.Info("going to delete", repo.GoPath) - if argv.Fix { - me.forge.Repos.DeleteByGoPath(repo.GetGoPath()) - me.forge.Repos.ConfigSave() - } else { - log.Info("need argv --real to delete", repo.GoPath) - os.Exit(0) - } - } - if me.forge.Config.IsReadOnly(repo.GoPath) && !argv.ReadOnly { - if repo.ReadOnly { - return - } - log.Info("readonly flag on repo is wrong", repo.GoPath) - return - } - slen := 12 - var chort string = s["cver"] - var mhort string = s["mver"] - var uhort string = s["uver"] - if len(s["cver"]) > slen { - chort = s["cver"][:slen] - } - if len(s["mver"]) > slen { - mhort = s["mver"][:slen] - } - if len(s["uver"]) > slen { - uhort = s["uver"][:slen] - } - start := fmt.Sprintf("%-40s %-12s %-12s %-12s %-8s", s["gopath"], chort, mhort, uhort, s["rtype"]) - - if me.forge.Config.IsReadOnly(repo.GoPath) { - end += "(readonly) " - } - - log.Info(start, end) -} - -func verify(repo *gitpb.Repo, s map[string]string) bool { - if !repo.IsValid() { - return false - } - s["gopath"] = repo.GetGoPath() - s["rtype"] = repo.RepoType() - - s["mname"] = repo.GetMasterBranchName() - if s["mname"] == "" { - log.Info("verify() no master branch name", repo.GoPath) - s["mver"] = repo.GetMasterVersion() - return false - } - // only verify the master branch name with read-only repos - if me.forge.Config.IsReadOnly(repo.GoPath) { - s["mver"] = repo.GetMasterVersion() - return true - } - - s["dname"] = repo.GetDevelBranchName() - if s["dname"] == "" { - log.Info("verify() no devel branch name", repo.GoPath) - return false - } - s["uname"] = repo.GetUserBranchName() - if s["uname"] == "" { - log.Info("verify() no user branch name", repo.GoPath) - return false - } - s["cname"] = repo.GetCurrentBranchName() - - s["mver"] = repo.GetMasterVersion() - if s["mver"] == "" { - log.Info("verify() no master branch name", repo.GoPath, repo.GetMasterBranchName()) - return false - } - s["dver"] = repo.GetDevelVersion() - if s["dver"] == "" { - log.Info("verify() no devel branch name", repo.GoPath, repo.GetDevelBranchName()) - return false - } - s["uver"] = repo.GetUserVersion() - if s["uver"] == "" { - log.Info("verify() no user branch name", repo.GoPath, repo.GetUserBranchName()) - return false - } - s["cver"] = repo.GetCurrentBranchVersion() - s["url"] = repo.URL - - return true -} - -func listPrivate() { - repos := me.forge.Repos.SortByGoPath() - for repos.Scan() { - repo := repos.Next() - if me.forge.Config.IsPrivate(repo.GoPath) { - verifyPrint(repo) - } - } - configs := me.forge.Config.SortByGoPath() - for configs.Scan() { - thing := configs.Next() - if thing.Directory { - continue - } - if thing.Private { - found := me.forge.Repos.FindByGoPath(thing.GoPath) - if found == nil { - log.Info("have not downloaded private:", thing.GoPath) - } else { - log.Info("already downloaded private:", thing.GoPath) - } - } - } - os.Exit(0) -} diff --git a/main.go b/main.go index 0c16e11..7650b76 100644 --- a/main.go +++ b/main.go @@ -6,11 +6,9 @@ import ( "os" "go.wit.com/dev/alexflint/arg" - "go.wit.com/lib/gadgets" "go.wit.com/lib/protobuf/forgepb" + "go.wit.com/lib/protobuf/gitpb" "go.wit.com/log" - - "go.wit.com/gui" ) // sent via -ldflags @@ -23,66 +21,48 @@ func main() { // load the ~/.config/forge/ config me.forge = forgepb.Init() - os.Setenv("REPO_WORK_PATH", me.forge.GetGoSrc()) - - // show your forge config settings - if argv.ListConf { - me.forge.ConfigPrintTable() - os.Exit(0) - } - - // processes any --list like options - // may exit - list() - scan() + me.found = new(gitpb.Repos) - if argv.RedoGoMod { - me.forge.RillRedoGoMod() - os.Exit(0) - repos := me.forge.Repos.SortByGoPath() - for repos.Scan() { - repo := repos.Next() - if !repo.IsValid() { - log.Printf("%10s %-50s", "old?", repo.GetGoPath()) - continue - } - log.Printf("running on: %-50s", repo.GetGoPath()) - if argv.Erase { - repo.EraseGoMod() - } else { - repo.RedoGoMod() - } + // first find the repos or gopaths to operate on + if argv.Config { + if findConfig() { + me.forge.ConfigPrintTable() + os.Exit(0) } + } else { + findRepos() } - me.pp.WriteHelp(os.Stdout) - os.Exit(0) - - me.myGui = gui.New() - me.myGui.Default() - - me.mainWindow = gadgets.RawBasicWindow("submit & test patchsets") - me.mainWindow.Make() - me.mainWindow.Show() - me.mainbox = me.mainWindow.Box() - - // disable the interface while everything is scanned - me.Disable() - vbox2 := me.mainbox.NewVerticalBox("BOX2") - globalBuildOptions(vbox2) - me.summary = submitPatchesBox(vbox2) + log.Info("found", me.found.Len(), "repos. found", len(me.foundPaths), "paths from .config/forge") - me.repos = makeRepoView() - - // processing is done. update the repo summary box - me.summary.Update() + // now, do something to all of them (or just print out a table of them) + var done bool = false + if argv.DoScan { + doScan() + done = true + } - me.Enable() + if argv.DoRedoGoMod { + doRedoGoMod() + done = true + } + if argv.DoGitPull { + doGitPull() + done = true + } + if argv.DoList { + // print out the repos + doCobol() + done = true + } - // intermittently scans the status indefinitly - me.repos.View.Watchdog(func() { - log.Info("In main()") - // processing is done. update the repo summary box - me.summary.Update() - }) + // do the gui at the very end + if argv.DoGui { + doGui() + os.Exit(0) + } + if !done { + // if nothing was selected, print out a table of them on STDOUT + doCobol() + } } diff --git a/repoview.go b/repoview.go index 45e3fa2..736ba15 100644 --- a/repoview.go +++ b/repoview.go @@ -154,7 +154,7 @@ func (r *repoWindow) mergeAllDevelToMain() bool { log.Info("skipping dirty", repo.Name(), repo.State()) continue } - log.Info("found", repo.Name(), repo.State()) + log.Info("repo:", repo.Name(), repo.State()) repo.NewScan() if repo.Status.MergeDevelToMaster() { log.Warn("THINGS SEEM OK fullAutomation() returned true.") @@ -186,7 +186,7 @@ func (r *repoWindow) mergeAllUserToDevel() bool { log.Info("skipping dirty", repo.Name(), repo.State()) continue } - log.Info("found", repo.Name(), repo.State()) + log.Info("repo:", repo.Name(), repo.State()) repo.NewScan() if repo.Status.MergeUserToDevel() { log.Warn("THINGS SEEM OK fullAutomation() returned true.") diff --git a/scan.go b/scan.go deleted file mode 100644 index cb1dcd0..0000000 --- a/scan.go +++ /dev/null @@ -1,9 +0,0 @@ -package main - -func scan() { - if !argv.Scan { - return - } - me.forge.ScanGoSrc() - list() -} diff --git a/structs.go b/structs.go index 6d2cccc..a0c3a0d 100644 --- a/structs.go +++ b/structs.go @@ -20,10 +20,12 @@ func (b *mainType) Enable() { // this app's variables type mainType struct { - pp *arg.Parser - forge *forgepb.Forge - myGui *gui.Node - packs []*gitpb.Repo + pp *arg.Parser // for parsing the command line args. Yay to alexf lint! + forge *forgepb.Forge // for holding the forge protobuf files + myGui *gui.Node // the gui toolkit handle + found *gitpb.Repos // stores the list of repos to process things on + foundPaths []string // stores gopaths to act on (when doing go-clone) + configSave bool // if the config file should be saved after finishing // our view of the repositories repos *repoWindow diff --git a/subitPatches.go b/subitPatches.go new file mode 100644 index 0000000..dead524 --- /dev/null +++ b/subitPatches.go @@ -0,0 +1,240 @@ +package main + +import ( + "path/filepath" + "strconv" + + "go.wit.com/gui" + "go.wit.com/lib/gadgets" + "go.wit.com/lib/gui/repolist" + "go.wit.com/lib/gui/shell" + "go.wit.com/log" +) + +/* +type patch struct { + ref string + giturl string + comment string + rs *repostatus.RepoStatus +} +*/ + +type patchSummary struct { + grid *gui.Node + updateB *gui.Node + docsB *gui.Node + gitPushB *gui.Node + gitPullB *gui.Node + checkB *gui.Node + + // stats + totalOL *gadgets.OneLiner + totalGoOL *gadgets.OneLiner + dirtyOL *gadgets.OneLiner + readonlyOL *gadgets.OneLiner + totalPatchesOL *gadgets.OneLiner + totalUserRepos *gui.Node + totalDevelRepos *gui.Node + totalMasterRepos *gui.Node + totalUserPatches *gui.Node + totalDevelPatches *gui.Node + totalMasterPatches *gui.Node + + // patch set generation + unknownOL *gadgets.BasicEntry + unknownSubmitB *gui.Node + reason *gadgets.BasicEntry + submitB *gui.Node + allp []*repolist.Patch +} + +func submitPatchesBox(box *gui.Node) *patchSummary { + s := new(patchSummary) + group1 := box.NewGroup("Submit Patches Summary") + s.grid = group1.RawGrid() + + s.grid.NewButton("Update Patch Counts", func() { + var repocount, patchcount int + // broken after move to forge protobuf + loop := me.forge.Repos.SortByGoPath() + for loop.Scan() { + repo := loop.Next() + if repo.GetReadOnly() { + continue + } + i, _ := repo.GetMasterPatches() + patchcount += i + if i > 0 { + repocount += 1 + } + } + s.totalMasterPatches.SetText(strconv.Itoa(patchcount) + " patches") + s.totalMasterRepos.SetText(strconv.Itoa(repocount) + " go repos") + + repocount = 0 + patchcount = 0 + // broken after move to forge protobuf + loop = me.forge.Repos.SortByGoPath() + for loop.Scan() { + repo := loop.Next() + if repo.GetReadOnly() { + continue + } + i, _ := repo.GetUserPatches() + patchcount += i + if i > 0 { + repocount += 1 + } + } + s.totalUserPatches.SetText(strconv.Itoa(patchcount) + " patches") + s.totalUserRepos.SetText(strconv.Itoa(repocount) + " go repos") + }) + + /* this used to be the way and should probably be revisited + s.grid.NewButton("Make Patches", func() { + for i, p := range s.allp { + log.Info(i, p.Ref, p.RS.String()) + } + }) + */ + + s.grid.NextRow() + + s.totalOL = gadgets.NewOneLiner(s.grid, "Total") + s.grid.NextRow() + + s.totalGoOL = gadgets.NewOneLiner(s.grid, "Total GO") + s.grid.NextRow() + + s.dirtyOL = gadgets.NewOneLiner(s.grid, "dirty") + s.grid.NextRow() + + s.readonlyOL = gadgets.NewOneLiner(s.grid, "read-only") + s.grid.NextRow() + + // s.grid = group1.RawGrid() + s.grid.NewLabel("") + s.grid.NewLabel("") + s.grid.NewLabel("user to devel") + s.grid.NewLabel("devel to master") + s.grid.NewLabel("master to last tag") + s.grid.NextRow() + + s.grid.NewLabel("total modified") + s.grid.NewLabel("") + s.totalUserRepos = s.grid.NewLabel("x go repos") + s.totalDevelRepos = s.grid.NewLabel("") + s.totalMasterRepos = s.grid.NewLabel("x go repos") + s.grid.NextRow() + + s.totalPatchesOL = gadgets.NewOneLiner(s.grid, "total commits") + s.totalUserPatches = s.grid.NewLabel("x patches") + s.totalDevelPatches = s.grid.NewLabel("") + s.totalMasterPatches = s.grid.NewLabel("x patches") + s.grid.NextRow() + + s.grid.NewLabel("") + s.grid.NewLabel("") + s.grid.NewButton("merge from user", func() { + log.Info("this should make a patchset of your patches") + }) + s.grid.NewButton("merge from devel", func() { + log.Info("this probably should not exist") + }) + s.grid.NextRow() + + group1 = box.NewGroup("Create GUI Patch Set") + s.grid = group1.RawGrid() + s.reason = gadgets.NewBasicEntry(s.grid, "patch name:") + s.reason.Custom = func() { + if s.reason.String() != "" { + s.submitB.Enable() + } else { + s.submitB.Disable() + } + } + s.submitB = s.grid.NewButton("Create Patch Set", func() { + dirname := "submit-patchset.quilt" + patchdir := filepath.Join(me.userHomePwd.String(), dirname) + if shell.Exists(patchdir) { + log.Info("patchset dir already exists", patchdir) + shell.PathRun(me.userHomePwd.String(), []string{"rm", "-rf", dirname}) + } + shell.Mkdir(patchdir) + if !shell.Exists(patchdir) { + log.Info("something went wrong making", patchdir) + return + } + me.repos.View.MakePatchset(patchdir) + }) + s.submitB = s.grid.NewButton("Submit quilt", func() { + log.Info("do a submit here") + }) + // disable these until there are not dirty repos + s.reason.Disable() + s.submitB.Disable() + s.grid.NextRow() + + s.unknownOL.Disable() + s.unknownSubmitB.Disable() + s.grid.NextRow() + + return s +} + +// does not run any commands +func (s *patchSummary) Update() { + var total, totalgo, dirty, readonly int + var userT, develT, masterT int + // var userP, develP, masterP int + // broken after move to forge protobuf + loop := me.forge.Repos.SortByGoPath() + for loop.Scan() { + repo := loop.Next() + total += 1 + if repo.IsDirty() { + dirty += 1 + } + if repo.GetReadOnly() { + readonly += 1 + // don't count these in any further stats + continue + } + // compute which GUI repos are out of sync with master + userV := repo.GetUserVersion() + develV := repo.GetDevelVersion() + masterV := repo.GetMasterVersion() + lastV := repo.GetLastTagVersion() + if userV != develV { + userT += 1 + } + if develV != masterV { + log.Info("develV != masterV", develV, masterV, repo.GetGoPath()) + develT += 1 + } + if masterV != lastV { + masterT += 1 + } + } + s.totalOL.SetText(strconv.Itoa(total) + " repos") + s.totalGoOL.SetText(strconv.Itoa(totalgo) + " repos") + s.dirtyOL.SetText(strconv.Itoa(dirty) + " repos") + s.readonlyOL.SetText(strconv.Itoa(readonly) + " repos") + + s.totalUserRepos.SetText(strconv.Itoa(userT) + " repos") + s.totalDevelRepos.SetText(strconv.Itoa(develT) + " repos") + s.totalMasterRepos.SetText(strconv.Itoa(masterT) + " repos") + + if dirty == 0 { + s.reason.Enable() + s.submitB.Enable() + s.unknownOL.Enable() + s.unknownSubmitB.Enable() + } else { + s.reason.Disable() + s.submitB.Enable() + s.unknownOL.Enable() + s.unknownSubmitB.Enable() + } +} diff --git a/submitPatches.go b/submitPatches.go deleted file mode 100644 index 30ba9b3..0000000 --- a/submitPatches.go +++ /dev/null @@ -1,267 +0,0 @@ -package main - -import ( - "path/filepath" - "strconv" - - "go.wit.com/gui" - "go.wit.com/lib/gadgets" - "go.wit.com/lib/gui/repolist" - "go.wit.com/lib/gui/shell" - "go.wit.com/log" -) - -/* -type patch struct { - ref string - giturl string - comment string - rs *repostatus.RepoStatus -} -*/ - -type patchSummary struct { - grid *gui.Node - updateB *gui.Node - docsB *gui.Node - gitPushB *gui.Node - gitPullB *gui.Node - checkB *gui.Node - - // stats - totalOL *gadgets.OneLiner - totalGoOL *gadgets.OneLiner - dirtyOL *gadgets.OneLiner - readonlyOL *gadgets.OneLiner - totalPatchesOL *gadgets.OneLiner - totalUserRepos *gui.Node - totalDevelRepos *gui.Node - totalMasterRepos *gui.Node - totalUserPatches *gui.Node - totalDevelPatches *gui.Node - totalMasterPatches *gui.Node - - // patch set generation - unknownOL *gadgets.BasicEntry - unknownSubmitB *gui.Node - reason *gadgets.BasicEntry - submitB *gui.Node - allp []*repolist.Patch -} - -func submitPatchesBox(box *gui.Node) *patchSummary { - s := new(patchSummary) - group1 := box.NewGroup("Submit Patches Summary") - s.grid = group1.RawGrid() - - s.grid.NewButton("Update Patch Counts", func() { - var repocount, patchcount int - // broken after move to forge protobuf - loop := me.forge.Repos.SortByGoPath() - for loop.Scan() { - repo := loop.Next() - if repo.GetReadOnly() { - continue - } - i, _ := repo.GetMasterPatches() - patchcount += i - if i > 0 { - repocount += 1 - } - } - s.totalMasterPatches.SetText(strconv.Itoa(patchcount) + " patches") - s.totalMasterRepos.SetText(strconv.Itoa(repocount) + " go repos") - - repocount = 0 - patchcount = 0 - // broken after move to forge protobuf - loop = me.forge.Repos.SortByGoPath() - for loop.Scan() { - repo := loop.Next() - if repo.GetReadOnly() { - continue - } - i, _ := repo.GetUserPatches() - patchcount += i - if i > 0 { - repocount += 1 - } - } - s.totalUserPatches.SetText(strconv.Itoa(patchcount) + " patches") - s.totalUserRepos.SetText(strconv.Itoa(repocount) + " go repos") - }) - - /* this used to be the way and should probably be revisited - s.grid.NewButton("Make Patches", func() { - for i, p := range s.allp { - log.Info(i, p.Ref, p.RS.String()) - } - }) - */ - - s.grid.NextRow() - - s.totalOL = gadgets.NewOneLiner(s.grid, "Total") - s.grid.NextRow() - - s.totalGoOL = gadgets.NewOneLiner(s.grid, "Total GO") - s.grid.NextRow() - - s.dirtyOL = gadgets.NewOneLiner(s.grid, "dirty") - s.grid.NextRow() - - s.readonlyOL = gadgets.NewOneLiner(s.grid, "read-only") - s.grid.NextRow() - - // s.grid = group1.RawGrid() - s.grid.NewLabel("") - s.grid.NewLabel("") - s.grid.NewLabel("user to devel") - s.grid.NewLabel("devel to master") - s.grid.NewLabel("master to last tag") - s.grid.NextRow() - - s.grid.NewLabel("total modified") - s.grid.NewLabel("") - s.totalUserRepos = s.grid.NewLabel("x go repos") - s.totalDevelRepos = s.grid.NewLabel("") - s.totalMasterRepos = s.grid.NewLabel("x go repos") - s.grid.NextRow() - - s.totalPatchesOL = gadgets.NewOneLiner(s.grid, "total commits") - s.totalUserPatches = s.grid.NewLabel("x patches") - s.totalDevelPatches = s.grid.NewLabel("") - s.totalMasterPatches = s.grid.NewLabel("x patches") - s.grid.NextRow() - - s.grid.NewLabel("") - s.grid.NewLabel("") - s.grid.NewButton("merge from user", func() { - log.Info("this should make a patchset of your patches") - }) - s.grid.NewButton("merge from devel", func() { - log.Info("this probably should not exist") - }) - s.grid.NextRow() - - group1 = box.NewGroup("Create GUI Patch Set") - s.grid = group1.RawGrid() - s.reason = gadgets.NewBasicEntry(s.grid, "patch name:") - s.reason.Custom = func() { - if s.reason.String() != "" { - s.submitB.Enable() - } else { - s.submitB.Disable() - } - } - s.submitB = s.grid.NewButton("Create Patch Set", func() { - dirname := "submit-patchset.quilt" - patchdir := filepath.Join(me.userHomePwd.String(), dirname) - if shell.Exists(patchdir) { - log.Info("patchset dir already exists", patchdir) - shell.PathRun(me.userHomePwd.String(), []string{"rm", "-rf", dirname}) - } - shell.Mkdir(patchdir) - if !shell.Exists(patchdir) { - log.Info("something went wrong making", patchdir) - return - } - me.repos.View.MakePatchset(patchdir) - }) - s.submitB = s.grid.NewButton("Submit quilt", func() { - log.Info("do a submit here") - }) - // disable these until there are not dirty repos - s.reason.Disable() - s.submitB.Disable() - s.grid.NextRow() - - /* - // map a path to gitea - s.unknownOL = gadgets.NewBasicEntry(s.grid, "Unknown Repo:") - s.unknownSubmitB = s.grid.NewButton("map new repo path", func() { - log.Info("Submit repo:", s.unknownOL.String()) - repo := me.repos.View.FindRepo(s.unknownOL.String()) - if repo == nil { - log.Info("could not find repo:", s.unknownOL.String(), "in ~/go/src") - return - } - - localurl := repo.GetURL() - log.Info("found repo:", repo.GoPath(), "with giturl", localurl) - if localurl == "" { - log.Info("local repo check failed. repo") - } else { - log.Info("local repo has", localurl) - // check if go.wit.com works, if not, add it - // attempts to register the unknown repo - if gowit.Register(repo.GoPath(), localurl) { - // todo: check if this works - // s.unknownOL.Hide() - // s.unknownSubmitB.Hide() - } - } - }) - */ - s.unknownOL.Disable() - s.unknownSubmitB.Disable() - s.grid.NextRow() - - return s -} - -// does not run any commands -func (s *patchSummary) Update() { - var total, totalgo, dirty, readonly int - var userT, develT, masterT int - // var userP, develP, masterP int - // broken after move to forge protobuf - loop := me.forge.Repos.SortByGoPath() - for loop.Scan() { - repo := loop.Next() - total += 1 - if repo.IsDirty() { - dirty += 1 - } - if repo.GetReadOnly() { - readonly += 1 - // don't count these in any further stats - continue - } - // compute which GUI repos are out of sync with master - userV := repo.GetUserVersion() - develV := repo.GetDevelVersion() - masterV := repo.GetMasterVersion() - lastV := repo.GetLastTagVersion() - if userV != develV { - userT += 1 - } - if develV != masterV { - log.Info("develV != masterV", develV, masterV, repo.GetGoPath()) - develT += 1 - } - if masterV != lastV { - masterT += 1 - } - } - s.totalOL.SetText(strconv.Itoa(total) + " repos") - s.totalGoOL.SetText(strconv.Itoa(totalgo) + " repos") - s.dirtyOL.SetText(strconv.Itoa(dirty) + " repos") - s.readonlyOL.SetText(strconv.Itoa(readonly) + " repos") - - s.totalUserRepos.SetText(strconv.Itoa(userT) + " repos") - s.totalDevelRepos.SetText(strconv.Itoa(develT) + " repos") - s.totalMasterRepos.SetText(strconv.Itoa(masterT) + " repos") - - if dirty == 0 { - s.reason.Enable() - s.submitB.Enable() - s.unknownOL.Enable() - s.unknownSubmitB.Enable() - } else { - s.reason.Disable() - s.submitB.Enable() - s.unknownOL.Enable() - s.unknownSubmitB.Enable() - } -} -- cgit v1.2.3