diff --git a/argv.go b/argv.go index 3ed58bf..39e206f 100644 --- a/argv.go +++ b/argv.go @@ -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 { diff --git a/doGui.go b/doGui.go index 8ee8c30..7eb60e9 100644 --- a/doGui.go +++ b/doGui.go @@ -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 } diff --git a/structs.go b/structs.go index 20b3a34..154af32 100644 --- a/structs.go +++ b/structs.go @@ -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 similarity index 53% rename from windowZooPB.go rename to 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() +}