summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-01-09 09:35:54 -0600
committerJeff Carr <[email protected]>2024-01-09 09:35:54 -0600
commit1f52d3083efb7768b8d7e21c7b9761c029b62584 (patch)
tree8ddf07f8a4e2442019b6850941467927483ddf39
parent3aced19260bfac158f78730b1259cba51b059321 (diff)
more stuff
Signed-off-by: Jeff Carr <[email protected]>
-rw-r--r--Makefile4
-rw-r--r--git.go92
-rw-r--r--main.go110
-rw-r--r--unix.go55
4 files changed, 167 insertions, 94 deletions
diff --git a/Makefile b/Makefile
index cea6c72..8bbd416 100644
--- a/Makefile
+++ b/Makefile
@@ -4,6 +4,6 @@ all:
redomod:
rm -f go.*
- go mod init
- go mod tidy
+ GO111MODULE= go mod init
+ GO111MODULE= go mod tidy
diff --git a/git.go b/git.go
new file mode 100644
index 0000000..bc7b283
--- /dev/null
+++ b/git.go
@@ -0,0 +1,92 @@
+// 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() {
+ out := run(r.path, "git", "checkout " + branch)
+ log.Warn(r.path, "git checkout " + branch, "returned", out)
+ }
+ r.getCurrentBranchName()
+ r.getCurrentBranchVersion()
+}
+
+func (r *repo) getBranch() {
+ out := run(r.path, "git", "branch --show-current")
+ r.bLabel.SetText(out)
+}
+
+func (r *repo) checkDirty() bool {
+ out := run(r.path, "git", "diff-index HEAD")
+ if out == "" {
+ r.sLabel.SetText("")
+ r.pButton.Disable()
+ return false
+ } else {
+ r.sLabel.SetText("dirty")
+ r.pButton.Enable()
+ 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 {
+ log.Info("r.path", r.path)
+ out := run(r.path, "git", "describe --tags")
+ 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.checkDirty()
+
+ r.populateTags()
+}
+
+func checkrepos() {
+ for i, r := range allrepos {
+ log.Warn("scannning", i, r.path)
+ r.scan()
+ }
+}
diff --git a/main.go b/main.go
index f0a6280..953294e 100644
--- a/main.go
+++ b/main.go
@@ -2,10 +2,6 @@
package main
import (
- "os"
- "strings"
- "os/exec"
-
"go.wit.com/log"
"go.wit.com/gui/gui"
@@ -38,54 +34,9 @@ func main() {
myGui = gui.New().Default()
helloworld()
-
- // This is just a optional goroutine to watch that things are alive
gui.Watchdog()
}
-func (r *repo) scan() {
- log.Info("r.path", r.path)
- out := run(r.path, "git", "describe --tags")
- r.vLabel.SetText(out)
-
- out = run(r.path, "git", "branch --show-current")
- r.bLabel.SetText(out)
-
- out = run(r.path, "git", "diff-index HEAD")
- if out == "" {
- r.sLabel.SetText("")
- r.pButton.Disable()
- } else {
- r.sLabel.SetText("dirty")
- r.pButton.Enable()
- }
-
- 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)
-
- r.tags = listFiles(fullpath(r.path + "/.git/refs/tags"))
- for _, tag := range r.tags {
- r.tagsDrop.AddText(tag)
- }
-
- // cmd := "dig +noall +answer www.wit.com A"
- // out = shell.Run(cmd)
-}
-
-func checkrepos() {
- for i, r := range allrepos {
- log.Warn("scannning", i, r.path)
- r.scan()
- }
-}
-
func addRepo(grid *gui.Node, path string) *repo {
newRepo := new(repo)
@@ -113,6 +64,7 @@ func helloworld() {
win := gadgets.NewBasicWindow(myGui, "helloworld golang wit/gui window")
box := win.Box().NewBox("bw vbox", false)
+ box2 := win.Box().NewBox("bw vbox", false)
group := box.NewGroup("test")
grid := group.NewGrid("test", 8, 1)
@@ -138,10 +90,25 @@ func helloworld() {
addRepo(grid, "go.wit.com/gui/digitalocean")
addRepo(grid, "go.wit.com/gui/cloudflare")
- box.NewButton("checkrepos()", func () {
+ box2.NewButton("checkrepos()", func () {
checkrepos()
})
- box.NewButton("hello", func () {
+ box2.NewButton("checkout jcarr (all repos)", func () {
+ for _, r := range allrepos {
+ r.checkoutBranch("jcarr")
+ }
+ })
+ box2.NewButton("checkout devel (all repos)", func () {
+ for _, r := range allrepos {
+ r.checkoutBranch("devel")
+ }
+ })
+ box2.NewButton("checkout master (all repos)", func () {
+ for _, r := range allrepos {
+ r.checkoutBranch("master")
+ }
+ })
+ box2.NewButton("hello", func () {
log.Println("world")
hellosmart()
})
@@ -167,44 +134,3 @@ func smartDraw(sw *smartwindow.SmartWindow) {
log.Println("smart")
})
}
-
-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 ""
- }
-
- // Print the output
- log.Info(string(output))
- return string(output)
-}
-
-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
-}
diff --git a/unix.go b/unix.go
new file mode 100644
index 0000000..94a722f
--- /dev/null
+++ b/unix.go
@@ -0,0 +1,55 @@
+// 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 ""
+ }
+
+ // Print the output
+ log.Info(string(output))
+ return string(output)
+}
+
+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
+}