more stuff

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-01-09 09:35:54 -06:00
parent 3aced19260
commit 1f52d3083e
4 changed files with 167 additions and 94 deletions

View File

@ -4,6 +4,6 @@ all:
redomod:
rm -f go.*
go mod init
go mod tidy
GO111MODULE= go mod init
GO111MODULE= go mod tidy

92
git.go Normal file
View File

@ -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()
}
}

110
main.go
View File

@ -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
}

55
unix.go Normal file
View File

@ -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
}