205 lines
4.3 KiB
Go
205 lines
4.3 KiB
Go
// This is a simple example
|
|
package main
|
|
|
|
import (
|
|
"os"
|
|
"strings"
|
|
"os/exec"
|
|
|
|
"go.wit.com/log"
|
|
|
|
"go.wit.com/gui/gui"
|
|
"go.wit.com/gui/gadgets"
|
|
"go.wit.com/apps/control-panel-dns/smartwindow"
|
|
)
|
|
|
|
var myGui *gui.Node
|
|
|
|
var allrepos []*repo
|
|
|
|
type repo struct {
|
|
path string
|
|
lasttagrev string
|
|
lasttag string
|
|
tags []string
|
|
|
|
pLabel *gui.Node // path label
|
|
bLabel *gui.Node // branch label
|
|
lastLabel *gui.Node // last tagged version label
|
|
vLabel *gui.Node // version label
|
|
sLabel *gui.Node // git state (dirty or not?)
|
|
|
|
cButton *gui.Node // commit button
|
|
pButton *gui.Node // push button
|
|
}
|
|
|
|
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"))
|
|
|
|
// 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)
|
|
|
|
newRepo.path = path
|
|
newRepo.pLabel = grid.NewLabel(path)
|
|
newRepo.bLabel = grid.NewLabel("")
|
|
newRepo.lastLabel = grid.NewLabel("")
|
|
newRepo.vLabel = grid.NewLabel("")
|
|
newRepo.sLabel = grid.NewLabel("")
|
|
|
|
newRepo.cButton = grid.NewButton("commit", func () {
|
|
log.Println("commit")
|
|
})
|
|
newRepo.pButton = grid.NewButton("push", func () {
|
|
log.Println("push")
|
|
})
|
|
if path == "" { return newRepo }
|
|
allrepos = append(allrepos, newRepo)
|
|
return newRepo
|
|
}
|
|
|
|
// This creates a window
|
|
func helloworld() {
|
|
win := gadgets.NewBasicWindow(myGui, "helloworld golang wit/gui window")
|
|
|
|
box := win.Box().NewBox("bw vbox", false)
|
|
group := box.NewGroup("test")
|
|
grid := group.NewGrid("test", 7, 1)
|
|
|
|
grid.NewLabel("go repo")
|
|
grid.NewLabel("branch")
|
|
grid.NewLabel("last tag")
|
|
grid.NewLabel("Version")
|
|
grid.NewLabel("is dirty?")
|
|
grid.NewLabel("commit")
|
|
grid.NewLabel("push to")
|
|
|
|
addRepo(grid, "go.wit.com/log")
|
|
addRepo(grid, "go.wit.com/arg")
|
|
addRepo(grid, "go.wit.com/spew")
|
|
addRepo(grid, "go.wit.com/shell")
|
|
addRepo(grid, "")
|
|
addRepo(grid, "go.wit.com/gui/gui")
|
|
addRepo(grid, "go.wit.com/gui/widget")
|
|
addRepo(grid, "go.wit.com/gui/toolkits")
|
|
addRepo(grid, "go.wit.com/gui/debugger")
|
|
addRepo(grid, "go.wit.com/gui/gadgets")
|
|
addRepo(grid, "go.wit.com/gui/digitalocean")
|
|
addRepo(grid, "go.wit.com/gui/cloudflare")
|
|
|
|
box.NewButton("checkrepos()", func () {
|
|
checkrepos()
|
|
})
|
|
box.NewButton("hello", func () {
|
|
log.Println("world")
|
|
hellosmart()
|
|
})
|
|
}
|
|
|
|
// This creates a window
|
|
func hellosmart() {
|
|
win := smartwindow.New()
|
|
win.SetParent(myGui)
|
|
win.InitWindow()
|
|
win.Title("helloworld golang wit/gui window")
|
|
win.Vertical()
|
|
win.SetDraw(smartDraw)
|
|
win.Make()
|
|
|
|
win.Box().NewButton("test smartwindow", func () {
|
|
log.Println("smart")
|
|
})
|
|
}
|
|
|
|
func smartDraw(sw *smartwindow.SmartWindow) {
|
|
sw.Box().NewButton("hello", func () {
|
|
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
|
|
}
|