summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-01-13 21:39:44 -0600
committerJeff Carr <[email protected]>2024-01-13 21:39:44 -0600
commitb700881b43b0c64b1d0faf25b0747a5c7294fce3 (patch)
tree56efa418f30db99c00d69d26615b3cf8b1e7a8af
parente26413e6365ec71509a3b514470e38445f4e1a1e (diff)
everything successfully in repostatus package
code now uses 'hidden' widgets add go.* remvoe old code status is maybe done skips non-existent repos Signed-off-by: Jeff Carr <[email protected]> Signed-off-by: Jeff Carr <[email protected]>
-rw-r--r--.gitignore1
-rw-r--r--git.go143
-rw-r--r--go.mod18
-rw-r--r--go.sum27
-rw-r--r--main.go123
-rw-r--r--unix.go96
6 files changed, 159 insertions, 249 deletions
diff --git a/.gitignore b/.gitignore
index 3aa4127..81830db 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,4 @@
!.gitignore
!Makefile
!*.go
+!go.*
diff --git a/git.go b/git.go
deleted file mode 100644
index 1c57f46..0000000
--- a/git.go
+++ /dev/null
@@ -1,143 +0,0 @@
-// This is a simple example
-package main
-
-import (
- "strings"
-
- "go.wit.com/log"
-
-// "go.wit.com/gui/gui"
-// "go.wit.com/gui/gadgets"
-// "go.wit.com/apps/control-panel-dns/smartwindow"
-)
-
-func (r *repo) checkoutBranch(branch string) {
- if r.checkDirty() {
- return
- }
- out := run(r.path, "git", "checkout " + branch)
- log.Warn(r.path, "git checkout " + branch, "returned", out)
-
- realname := r.getCurrentBranchName()
- realversion := r.getCurrentBranchVersion()
- log.Warn(r.path, "realname =", realname, "realversion =", realversion)
- if realname == "jcarr" {
- r.jcarrVersion.Set(realversion)
- }
- if realname == "devel" {
- r.develVersion.Set(realversion)
- }
- if realname == "master" {
- r.masterVersion.Set(realversion)
- }
-}
-
-func (r *repo) getBranch() {
- out := run(r.path, "git", "branch --show-current")
- r.bLabel.SetText(out)
-}
-
-func (r *repo) checkDirty() bool {
- if r.path == "" {
- log.Warn("disable spaceholders")
- r.cButton.Disable()
- r.pButton.Disable()
- return false
- }
- out := run(r.path, "git", "diff-index HEAD")
- if out == "" {
- r.dirtyLabel.SetText("")
- r.pButton.SetText("scan")
- return false
- } else {
- r.dirtyLabel.SetText("dirty")
- r.pButton.SetText("scan")
- return true
- }
-
-}
-
-func (r *repo) getLastTagVersion() string {
- out := run(r.path, "git", "rev-list --tags --max-count=1")
- out = strings.TrimSpace(out)
- r.lasttagrev = out
-
- lastreal := "describe --tags " + out
- // out = run(r.path, "git", "describe --tags c871d5ecf051a7dc4e3a77157cdbc0a457eb9ae1")
- out = run(r.path, "git", lastreal)
- r.lasttag = out
- r.lastLabel.SetText(out)
-
- return out
-}
-
-func (r *repo) getCurrentBranchName() string {
- out := run(r.path, "git", "branch --show-current")
- r.bLabel.SetText(out)
- return out
-}
-
-func (r *repo) getCurrentBranchVersion() string {
- out := run(r.path, "git", "describe --tags")
- log.Warn("getCurrentBranchVersion", out)
- r.vLabel.SetText(out)
- return out
-}
-
-func (r *repo) populateTags() {
- r.tags = listFiles(fullpath(r.path + "/.git/refs/tags"))
- for _, tag := range r.tags {
- r.tagsDrop.AddText(tag)
- }
- // r.tagsDrop.SetText(r.lasttag)
-}
-
-func (r *repo) scan() {
-
- r.getLastTagVersion()
- r.getCurrentBranchName()
- r.getCurrentBranchVersion()
- r.populateTags()
- if r.checkDirty() {
- return
- }
- r.checkoutBranch("master")
- r.checkoutBranch("devel")
- r.checkoutBranch("jcarr")
-
- lasttag := r.lastLabel.GetText()
- master := r.masterVersion.GetText()
- devel := r.develVersion.GetText()
- jcarr := r.jcarrVersion.GetText()
-
- log.Warn("")
- log.Warn("lasttag =", lasttag)
- log.Warn("master =", master)
- log.Warn("devel =", devel)
- log.Warn("jcarr =", jcarr)
-
- r.dirtyLabel.SetText("garbage")
-
- if devel != master {
- log.Warn("devel version != master version", devel, "vs", master)
- r.dirtyLabel.SetText("merge")
- return
- }
- if lasttag != master {
- log.Warn("last tag rev != master version", lasttag, "vs", master)
- r.dirtyLabel.SetText("merge")
- return
- }
- if lasttag == jcarr {
- log.Warn("last tag rev == jcarr version", lasttag, "vs", jcarr)
- r.dirtyLabel.SetText("GOOD")
- return
- }
-}
-
-func checkrepos() {
- for i, r := range allrepos {
- log.Warn("scannning", i, r.path)
- r.scan()
- }
-}
diff --git a/go.mod b/go.mod
new file mode 100644
index 0000000..8e4ba8b
--- /dev/null
+++ b/go.mod
@@ -0,0 +1,18 @@
+module go.wit.com/apps/myrepos
+
+go 1.21.4
+
+require (
+ go.wit.com/apps/control-panel-dns v0.12.1
+ go.wit.com/gui/gadgets v0.10.3
+ go.wit.com/gui/gadgets/repostatus v0.0.0-20240110012216-abd9781d8a60
+ go.wit.com/gui/gui v0.12.4
+ go.wit.com/log v0.5.1
+)
+
+require (
+ github.com/alexflint/go-scalar v1.2.0 // indirect
+ go.wit.com/dev/alexflint/go-arg v1.4.4 // indirect
+ go.wit.com/gui/widget v0.0.0-20240105185907-84aafa536a93 // indirect
+ go.wit.com/spew v0.0.0-20240101141411-c7b8e91573c9 // indirect
+)
diff --git a/go.sum b/go.sum
new file mode 100644
index 0000000..b0e6f9b
--- /dev/null
+++ b/go.sum
@@ -0,0 +1,27 @@
+github.com/alexflint/go-scalar v1.2.0 h1:WR7JPKkeNpnYIOfHRa7ivM21aWAdHD0gEWHCx+WQBRw=
+github.com/alexflint/go-scalar v1.2.0/go.mod h1:LoFvNMqS1CPrMVltza4LvnGKhaSpc3oyLEBUZVhhS2o=
+github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
+github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
+github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
+github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
+github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
+github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
+go.wit.com/apps/control-panel-dns v0.12.1 h1:FBaNeSPIoyBXWir4ggxFiaBpHtGnbOj+GGHbK3Rpbo0=
+go.wit.com/apps/control-panel-dns v0.12.1/go.mod h1:y+DRqorB3K/xAiDSil5cCVUalsJzMdUQuK9HambO0fQ=
+go.wit.com/dev/alexflint/go-arg v1.4.4 h1:n7sDAPpaxzZ/nGKyVRj1Y/V0H18frfqSwI8yFe/9BGc=
+go.wit.com/dev/alexflint/go-arg v1.4.4/go.mod h1:td08jpeZ4vQ/Bu870In78YE2QRrNXhxvY1A34hC7qFo=
+go.wit.com/gui/gadgets v0.10.3 h1:sL1GULM8Aedch3kSBdm4XuYMz/TfJ+pPeha/927/pGU=
+go.wit.com/gui/gadgets v0.10.3/go.mod h1:9bgxU4rUi4NQaZCgvuLvo6BwHsCx35kNyDalztYNT3A=
+go.wit.com/gui/gadgets/repostatus v0.0.0-20240110012216-abd9781d8a60 h1:7Oppvb22yhrNbYJlUJzOeTDrb3Edll4d4xfprmFe8qw=
+go.wit.com/gui/gadgets/repostatus v0.0.0-20240110012216-abd9781d8a60/go.mod h1:XMqxjysTEnVeFfDbeWsA5BEDde1KfU9+Yx7YnWSqRRk=
+go.wit.com/gui/gui v0.12.4 h1:99fXbCk5r/5Fg11O7Rsq6mUGltK3v8yfX2f06eaYIkU=
+go.wit.com/gui/gui v0.12.4/go.mod h1:WrAJB4kIR/U0z/PzrkYYQG6QeuXDLcpgiH5vXnz5I1s=
+go.wit.com/gui/widget v0.0.0-20240105185907-84aafa536a93 h1:zCzaHvXJJ/rWXmDc/v79VvM6W2lxxzJGfnW2lHCv3Ho=
+go.wit.com/gui/widget v0.0.0-20240105185907-84aafa536a93/go.mod h1:A6/FaiFQtAHTjgo7c4FrokXe6bXX1Cowo35b2Lgi31E=
+go.wit.com/log v0.5.1 h1:D1Gdpo+EIOZDnBmW2SJCmqSD30ZWTGZ++NXyXeyMd2Y=
+go.wit.com/log v0.5.1/go.mod h1:0oxmE+WavwUZspnVAcOuIjS3vx7qVOFXj3vmUqKlzTE=
+go.wit.com/spew v0.0.0-20240101141411-c7b8e91573c9 h1:UEX2EzLQPzLTfy/kUFQD7OXtvKn8wk/+jpDOkbl4ff4=
+go.wit.com/spew v0.0.0-20240101141411-c7b8e91573c9/go.mod h1:qBpgJXThMMT15vym7/E4Ur9y8oOo2nP7t2RP52QHUNw=
+gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
+gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
diff --git a/main.go b/main.go
index 9062c52..57b2f55 100644
--- a/main.go
+++ b/main.go
@@ -27,7 +27,7 @@ type repo struct {
bLabel *gui.Node // branch label
lastLabel *gui.Node // last tagged version label
vLabel *gui.Node // version label
- tagsDrop *gui.Node // list of all tags
+ // tagsDrop *gui.Node // list of all tags
dirtyLabel *gui.Node // git state (dirty or not?)
masterVersion *gui.Node // the master branch version
@@ -44,25 +44,44 @@ func main() {
myGui = gui.New().Default()
repoworld()
- checkrepos()
+
+ /*
+ for i, r := range allrepos {
+ log.Warn("scannning", i, r.path)
+ r.scan()
+ }
+ */
+
gui.Watchdog()
}
-func addRepo(grid *gui.Node, path string) *repo {
+func (r *repo) getPath() string {
+ return r.path
+}
+
+func addRepo(grid *gui.Node, path 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)
newRepo.bLabel = grid.NewLabel("")
newRepo.lastLabel = grid.NewLabel("")
newRepo.vLabel = grid.NewLabel("")
- newRepo.tagsDrop = grid.NewDropdown("tags")
+ // newRepo.tagsDrop = grid.NewDropdown("tags")
newRepo.masterVersion = grid.NewLabel("")
newRepo.develVersion = grid.NewLabel("")
newRepo.jcarrVersion = grid.NewLabel("")
newRepo.dirtyLabel = grid.NewLabel("")
+ /*
newRepo.cButton = grid.NewButton("status", func () {
log.Println("repo status for", newRepo.path)
newRepo.scan()
@@ -76,16 +95,49 @@ func addRepo(grid *gui.Node, path string) *repo {
}
newRepo.status.Toggle()
})
+ */
newRepo.pButton = grid.NewButton("rescan", func () {
- newRepo.scan()
+ newRepo.newScan()
+ })
+
+ /*
+ grid.NewButton("SierpiƄski", func () {
+ if newRepo.status != nil {
+ log.Warn("status window already exists")
+ }
+ newRepo.status = repostatus.New(myGui, newRepo.path)
+ newRepo.status.Horizontal()
+ newRepo.status.Make()
+ newRepo.status.Make2()
+ })
+ */
+ grid.NewButton("Toggle()", func () {
+ if newRepo.status == nil {
+ log.Warn("status window doesn't exist")
+ return
+ }
+ log.Warn("status window exists. trying Update() here")
+ newRepo.status.Toggle()
+ })
+ grid.NewButton("TestDraw()", func () {
+ if newRepo.status == nil {
+ log.Warn("status window doesn't exist")
+ return
+ }
+ log.Warn("status window exists. trying TestDraw() here")
+ newRepo.status.TestDraw()
})
if path == "" {
newRepo.cButton.Hide()
newRepo.pButton.Hide()
- return newRepo
}
+ newRepo.status = repostatus.New(myGui, newRepo.path)
+ newRepo.status.Horizontal()
+ newRepo.status.Make()
+ newRepo.status.Make2()
+ newRepo.status.Update()
+ newRepo.newScan()
allrepos = append(allrepos, newRepo)
- return newRepo
}
// This creates a window
@@ -100,14 +152,15 @@ func repoworld() {
grid.NewLabel("")
grid.NewLabel("branch")
grid.NewLabel("last tag")
- grid.NewLabel("Version")
- grid.NewLabel("tags")
+ grid.NewLabel("Current Version")
+ // grid.NewLabel("tags")
grid.NewLabel("master")
grid.NewLabel("devel")
grid.NewLabel("jcarr")
grid.NewLabel("Status")
grid.NewLabel("commit")
- grid.NewLabel("push to")
+ grid.NewLabel("Toggle()")
+ grid.NewLabel("Draw()")
repos := myrepolist()
for _, repo := range repos {
@@ -146,3 +199,53 @@ func myrepolist() []string {
lines := strings.Split(out, "\n")
return lines
}
+
+func (r *repo) newScan() bool {
+ if r.status == nil {
+ log.Warn("repo.status = nil. not initialized for some reason")
+ return false
+ }
+ // r.scan()
+ if repostatus.VerifyLocalGoRepo(r.getPath()) {
+ log.Warn("repo actually exists", r.getPath())
+ } else {
+ log.Warn("repo does not exist", r.getPath())
+ return false
+ }
+ mn := r.status.GetMasterName()
+ mv := r.status.GetMasterVersion()
+ r.masterVersion.Set(mn + " " + mv)
+
+ dn := r.status.GetDevelName()
+ dv := r.status.GetDevelVersion()
+ r.develVersion.Set(dn + " " + dv)
+
+ un := r.status.GetUserName()
+ uv := r.status.GetUserVersion()
+ r.jcarrVersion.Set(un + " " + uv)
+
+ cbname := r.status.GetCurrentBranchName()
+ cbversion := r.status.GetCurrentBranchVersion()
+ ltversion := r.status.GetLastTagVersion()
+ r.lastLabel.Set(cbname + " " + cbversion)
+ r.vLabel.Set(cbname + " " + ltversion)
+
+ if r.status.CheckDirty() {
+ log.Warn("CheckDirty() true")
+ r.dirtyLabel.Set("dirty")
+ return false
+ }
+ log.Warn("CheckDirty() no")
+ r.dirtyLabel.Set("not dirty")
+
+ if r.status.CheckBranches() {
+ log.Warn("Branches are Perfect")
+ r.dirtyLabel.SetText("PEFECT")
+ return true
+ } else {
+ log.Warn("Branches are not Perfect")
+ r.dirtyLabel.SetText("merge")
+ }
+
+ return false
+}
diff --git a/unix.go b/unix.go
deleted file mode 100644
index 7c9f8db..0000000
--- a/unix.go
+++ /dev/null
@@ -1,96 +0,0 @@
-// This is a simple example
-package main
-
-import (
- "os"
- "os/exec"
- "strings"
-
- "go.wit.com/log"
-
-// "go.wit.com/gui/gui"
-// "go.wit.com/gui/gadgets"
-// "go.wit.com/apps/control-panel-dns/smartwindow"
-)
-
-func fullpath(repo string) string {
- return "/home/jcarr/go/src/" + repo
-}
-
-func run(path string, thing string, cmdline string) string {
- parts := strings.Split(cmdline, " ")
- // Create the command
- cmd := exec.Command(thing, parts...)
-
- // Set the working directory
- cmd.Dir = fullpath(path)
-
- // Execute the command
- output, err := cmd.CombinedOutput()
- if err != nil {
- log.Error(err, "cmd error'd out", parts)
- return ""
- }
-
- tmp := string(output)
-
- tmp = strings.TrimSpace(tmp)
-
- // Print the output
- log.Info("run()", path, thing, cmdline, "=", tmp)
- return tmp
-}
-
-func listFiles(directory string) []string {
- var files []string
- fileInfo, err := os.ReadDir(directory)
- if err != nil {
- log.Error(err)
- return nil
- }
-
- for _, file := range fileInfo {
- if !file.IsDir() {
- files = append(files, file.Name())
- }
- }
-
- return files
-}
-
-func runCmd(path string, cmdline string) (bool, string) {
- parts := strings.Split(cmdline, " ")
- if len(parts) == 0 {
- log.Warn("command line was empty")
- return false, ""
- }
- if parts[0] == "" {
- log.Warn("command line was empty")
- return false, ""
- }
- thing := parts[0]
- parts = parts[1:]
-
- log.Warn("path =", path, "thing =", thing, "cmdline =", parts)
- return false, ""
- // Create the command
- cmd := exec.Command(thing, parts...)
-
- // Set the working directory
- cmd.Dir = fullpath(path)
-
- // Execute the command
- output, err := cmd.CombinedOutput()
- if err != nil {
- log.Error(err)
- log.Warn("output was", output)
- log.Warn("cmd exited with error", err)
- return false, string(output)
- }
-
- tmp := string(output)
- tmp = strings.TrimSpace(tmp)
-
- // Print the output
- return true, tmp
-}