diff options
| author | Jeff Carr <[email protected]> | 2025-03-06 04:36:07 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-03-06 05:34:25 -0600 |
| commit | 8edebe18e163c8043be04f7dfe757683982c791f (patch) | |
| tree | 8a4452f502d1257e1fa4f00e5443cd333bebb9a7 | |
| parent | f97e2a48c6330baea7e99dd5dc1e560c23e64494 (diff) | |
cleaner window code
| -rw-r--r-- | argv.go | 5 | ||||
| -rw-r--r-- | doGui.go | 45 | ||||
| -rw-r--r-- | structs.go | 18 | ||||
| -rw-r--r-- | windowZood.go (renamed from windowZooPB.go) | 49 |
4 files changed, 83 insertions, 34 deletions
@@ -15,8 +15,9 @@ import ( var argv args type args struct { - Daemon bool `arg:"--daemon" default:"false" help:"run in daemon mode"` - Port int `arg:"--port" default:"8080" help:"port to run on"` + Verbose bool `arg:"--verbose" default:"false" help:"talk more"` + Daemon bool `arg:"--daemon" default:"false" help:"run in daemon mode"` + Port int `arg:"--port" default:"8080" help:"port to run on"` } func (args) Version() string { @@ -11,17 +11,17 @@ import ( "go.wit.com/gui" "go.wit.com/lib/gadgets" - "go.wit.com/lib/protobuf/zoopb" "go.wit.com/log" ) -func debug() { - for { - time.Sleep(90 * time.Second) - log.Info("TODO: zookeeper scan here. repo count =") - if me.machinesWin != nil { - doMachinesUpgradeTable() - } +// refresh the windows & tables the user has open +func refresh() { + time.Sleep(90 * time.Second) + if argv.Verbose { + log.Info("zookeeper scan here") + } + if me.zood != nil { + doMachinesUpgradeTable() } } @@ -45,29 +45,22 @@ func doGui() { group1 := vbox.NewGroup("Zookeeper Settings") grid := group1.NewGrid("buildOptions", 0, 0) - grid.NewButton("show zoo", func() { + grid.NewButton("zood versions", func() { // if the window exists, just toggle it open or closed - if me.machinesWin != nil { - me.machinesWin.Toggle() + if me.zood != nil { + me.zood.Toggle() return } - - me.machinesWin = gadgets.NewGenericWindow("Zoo Machines", "Stuff") - me.machinesWin.Win.Custom = func() { - log.Info("test delete window here") + makeZoodWin() + }) + grid.NewButton("update zood versions", func() { + if me.zood != nil { + doMachinesUpgradeTable() } - me.machinesBox = me.machinesWin.Bottom.Box().SetProgName("TBOX") - doMachinesUpgradeTable() }) - // sits here forever - debug() -} - -func findVersion(m *zoopb.Machine, pkgname string) string { - zood := m.Packages.FindByName(pkgname) - if zood == nil { - return "n/a" + // sit here forever refreshing the GUI + for { + refresh() } - return zood.Version } @@ -29,4 +29,22 @@ type zookeep struct { machinesWin *gadgets.GenericWindow // the machines gui window machinesBox *gui.Node // the machines gui parent box widget machinesTB *zoopb.MachinesTable // the machines gui table buffer + zood *stdTableWin // the zood version window +} + +type stdTableWin struct { + win *gadgets.GenericWindow // the machines gui window + box *gui.Node // the machines gui parent box widget + TB *zoopb.MachinesTable // the machines gui table buffer + update bool // if the window should be updated +} + +func (w *stdTableWin) Toggle() { + if w == nil { + return + } + if w.win == nil { + return + } + w.win.Toggle() } diff --git a/windowZooPB.go b/windowZood.go index 5f7eb74..65304f7 100644 --- a/windowZooPB.go +++ b/windowZood.go @@ -8,25 +8,40 @@ import ( "time" "go.wit.com/gui" + "go.wit.com/lib/gadgets" "go.wit.com/lib/protobuf/zoopb" "go.wit.com/log" ) +func makeZoodWin() { + me.zood = new(stdTableWin) + me.zood.win = gadgets.NewGenericWindow("zood daemon versions", "todo: add global controls here") + me.zood.win.Custom = func() { + log.Info("test delete window here") + } + group := me.zood.win.Group + group.NewButton("save machines.pb", func() { + saveMachineState() + }) + me.zood.box = me.zood.win.Bottom.Box().SetProgName("TBOX") + doMachinesUpgradeTable() +} + func doMachinesUpgradeTable() { - if me.machinesTB != nil { - me.machinesTB.Delete() - me.machinesTB = nil + if me.zood.TB != nil { + me.zood.TB.Delete() + me.zood.TB = nil } // display the protobuf - me.machinesTB = AddMachinesPB(me.machinesBox, me.machines) + me.zood.TB = AddMachinesPB(me.zood.box, me.machines) f := func(m *zoopb.Machine) { log.Info("upgrade machine", m.Hostname, "memory", m.Memory/(1024*1024*1024)) log.Info("ADD THE CODE TO TRIGGER AN UPGRADE HERE") log.Info("ADD THE CODE TO TRIGGER AN UPGRADE HERE") } - me.machinesTB.Custom(f) - log.Info("table has uuid", me.machinesTB.GetUuid()) + me.zood.TB.Custom(f) + log.Info("table has uuid", me.zood.TB.GetUuid()) } func AddMachinesPB(tbox *gui.Node, pb *zoopb.Machines) *zoopb.MachinesTable { @@ -40,9 +55,11 @@ func AddMachinesPB(tbox *gui.Node, pb *zoopb.Machines) *zoopb.MachinesTable { t.AddStringFunc("sMB", func(m *zoopb.Machine) string { return fmt.Sprintf("%d mb", m.Memory/(1024*1024)) }) + t.AddStringFunc("zood", func(m *zoopb.Machine) string { return findVersion(m, "zood") }) + t.AddTimeFunc("age", func(m *zoopb.Machine) time.Time { return m.Laststamp.AsTime() }) @@ -55,3 +72,23 @@ func AddMachinesPB(tbox *gui.Node, pb *zoopb.Machines) *zoopb.MachinesTable { t.ShowTable() return t } + +func findVersion(m *zoopb.Machine, pkgname string) string { + zood := m.Packages.FindByName(pkgname) + if zood == nil { + return "n/a" + } + return zood.Version +} + +func saveMachineState() { + now := zoopb.NewMachines() + + all := me.machines.SortByHostname() + for all.Scan() { + m := all.Next() + log.Info("have machine:", m.Hostname) + now.Append(m) + } + // me.machines.ConfigSave() +} |
