From 1d352604b9a88e59284d9b1d6a46019c31816247 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 5 Dec 2024 14:17:50 -0600 Subject: still invalid repos getting in the repos.pb --- Makefile | 23 +++------ cobol.go | 161 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ doCobol.go | 162 ---------------------------------------------------------- doCommon.go | 25 +++++++++ doDebugger.go | 31 ----------- doGitPull.go | 7 --- doScan.go | 5 -- findConfig.go | 46 +++-------------- findRepos.go | 91 +++++++++++++++++++++++++-------- main.go | 8 +++ 10 files changed, 279 insertions(+), 280 deletions(-) create mode 100644 cobol.go delete mode 100644 doCobol.go create mode 100644 doCommon.go delete mode 100644 doDebugger.go delete mode 100644 doGitPull.go delete mode 100644 doScan.go diff --git a/Makefile b/Makefile index d12558b..ab957ed 100644 --- a/Makefile +++ b/Makefile @@ -12,11 +12,12 @@ verbose: GO111MODULE=off go build -v -x \ -ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}" -install: +install: goimports GO111MODULE=off go install \ -ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}" goimports: + reset goimports -w *.go @# // to globally reset paths: @# // gofmt -w -r '"go.wit.com/gui/gadgets" -> "go.wit.com/lib/gadgets"' *.go @@ -24,37 +25,25 @@ goimports: gocui: install forge --gui gocui -check-git-clean: - @git diff-index --quiet HEAD -- || (echo "Git repository is dirty, please commit your changes first"; exit 1) - -redomod: - rm -f go.* - GO111MODULE= go mod init - GO111MODULE= go mod tidy - redomod-all: forge --do-RedoGoMod redomod-erase: forge --do-RedoGoMod --do-erase -list: install - reset - forge --do-list - private: install reset forge --find-private -list-fix: install +fix: install reset - forge --do-list --do-fix + forge --fix -list-readonly: install +readonly: install reset forge --do-list --find-readonly -list-config: install +config: install forge --config scan: install diff --git a/cobol.go b/cobol.go new file mode 100644 index 0000000..0812370 --- /dev/null +++ b/cobol.go @@ -0,0 +1,161 @@ +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) { + if repo.ReadOnly { + } else { + log.Info("readonly flag on repo is wrong", repo.GoPath) + } + } + + 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/doCobol.go b/doCobol.go deleted file mode 100644 index 678d17a..0000000 --- a/doCobol.go +++ /dev/null @@ -1,162 +0,0 @@ -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/doCommon.go b/doCommon.go new file mode 100644 index 0000000..db5a0a0 --- /dev/null +++ b/doCommon.go @@ -0,0 +1,25 @@ +package main + +import "go.wit.com/log" + +func doScan() { + me.forge.ScanGoSrc() +} + +func doGitPull() { + me.found.RillGitPull() +} + +func doFix() { + all := me.found.SortByGoPath() + for all.Scan() { + repo := all.Next() + if !repo.IsValid() { + log.Printf("%10s %-50s", "old?\n", repo.GetGoPath()) + continue + } + log.Printf("running on: %-50s\n", repo.GetGoPath()) + cmd := []string{"ls"} + repo.Run(cmd) + } +} diff --git a/doDebugger.go b/doDebugger.go deleted file mode 100644 index b2fa5dc..0000000 --- a/doDebugger.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/doGitPull.go b/doGitPull.go deleted file mode 100644 index cca3b19..0000000 --- a/doGitPull.go +++ /dev/null @@ -1,7 +0,0 @@ -package main - -// An app to submit patches for the 30 GO GUI repos - -func doGitPull() { - me.found.RillGitPull() -} diff --git a/doScan.go b/doScan.go deleted file mode 100644 index 562304f..0000000 --- a/doScan.go +++ /dev/null @@ -1,5 +0,0 @@ -package main - -func doScan() { - me.forge.ScanGoSrc() -} diff --git a/findConfig.go b/findConfig.go index 34c8f18..efe6ee2 100644 --- a/findConfig.go +++ b/findConfig.go @@ -2,52 +2,22 @@ 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 { + var done bool = false if argv.FindMine { findConfigMine() - return false + done = true } if argv.FindAll { findConfigAll() - return false + done = true } - - return true + if !done { + findConfigAll() + done = true + } + return done } // finds config repos that are writable diff --git a/findRepos.go b/findRepos.go index 1463d09..18ddd03 100644 --- a/findRepos.go +++ b/findRepos.go @@ -4,37 +4,88 @@ import ( "go.wit.com/log" ) -func findRepos() { +func findRepos() bool { + var done bool = false 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() - } + findAll() + done = true } if argv.FindPrivate { findPrivate() + done = true } if argv.FindMine { findMine() + done = true } if argv.FindFavorites { findFavorites() + done = true + } + + // this is the 'default' behavior when no command line arguments are given + // if no argv was set, select repos marked as 'mine' + if !done { + findMine() + done = true + } + return done +} + +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 favorites %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) + } + } +} + +func 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() } } diff --git a/main.go b/main.go index 7650b76..622ddfe 100644 --- a/main.go +++ b/main.go @@ -46,16 +46,24 @@ func main() { doRedoGoMod() done = true } + if argv.DoGitPull { doGitPull() done = true } + if argv.DoList { // print out the repos doCobol() done = true } + if argv.Fix { + // print out the repos + doFix() + done = true + } + // do the gui at the very end if argv.DoGui { doGui() -- cgit v1.2.3