stepping through init on a window with state

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-01-06 11:12:10 -06:00
parent c59247824f
commit f6f5bdba4e
9 changed files with 97 additions and 68 deletions

View File

@ -9,53 +9,31 @@ import (
)
var NOW log.LogFlag
var INFO log.LogFlag
var NET log.LogFlag
var DNS log.LogFlag
var PROC log.LogFlag
var SPEW log.LogFlag
var WARN log.LogFlag
var CHANGE log.LogFlag
var STATUS log.LogFlag
func init() {
NOW.B = false
NOW.Name = "NOW"
NOW.Subsystem = "cpdns"
NOW.Desc = "temp debugging stuff"
NOW.Register()
NET.B = false
NET.Name = "NET"
NET.Subsystem = "cpdns"
NET.Desc = "Network logging"
NET.Register()
DNS.B = false
DNS.Name = "DNS"
DNS.Subsystem = "cpdns"
DNS.Desc = "dnsStatus.update()"
DNS.Register()
PROC.B = false
PROC.Name = "PROC"
PROC.Subsystem = "cpdns"
PROC.Desc = "/proc logging"
PROC.Register()
SPEW.B = false
SPEW.Name = "SPEW"
SPEW.Subsystem = "cpdns"
SPEW.Desc = "spew logging"
SPEW.Register()
CHANGE.B = false
CHANGE.Name = "CHANGE"
CHANGE.Subsystem = "cpdns"
CHANGE.Desc = "show droplet state changes"
CHANGE.Register()
STATUS.B = false
STATUS.Name = "STATUS"
STATUS.Subsystem = "cpdns"
STATUS.Desc = "updateStatus()"
STATUS.Register()
func myreg(f *log.LogFlag, b bool, name string, desc string) {
f.B = b
f.Subsystem = "go.wit.com/control-panels/dns/linuxstatus"
f.Short = "linux"
f.Desc = desc
f.Name = name
f.Register()
}
func init() {
myreg(&NOW, true, "NOW", "temp debugging stuff")
myreg(&NET, false, "NET", "Network Logging")
myreg(&DNS, false, "DNS", "dnsStatus.update()")
myreg(&PROC, false, "PROC", "/proc logging")
myreg(&SPEW, false, "SPEW", "spew stuff")
myreg(&WARN, true, "WARN", "bad things")
myreg(&CHANGE, true, "CHANGE", "show droplet state changes")
myreg(&STATUS, false, "STATUS", "Update() details")
}

View File

@ -3,30 +3,52 @@ package linuxstatus
import (
"go.wit.com/log"
"go.wit.com/gui/gui"
)
func (ls *LinuxStatus) Draw() {
log.Log(CHANGE, "linuxStatus.Draw() window")
if ! ls.Ready() {return}
log.Log(CHANGE, "linuxStatus.Draw() window ready =", ls.ready)
ls.window.Draw()
ls.ready = true
}
func (ls *LinuxStatus) Draw2() {
log.Log(CHANGE, "draw(ls)")
if ! ls.Ready() {return}
log.Log(CHANGE, "draw(ls) ready =", ls.ready)
draw(ls)
}
func (ls *LinuxStatus) Show() {
log.Log(CHANGE, "linuxStatus.Show() window")
if ! ls.Ready() {return}
log.Log(CHANGE, "linuxStatus.Show() window ready =", ls.ready)
ls.window.Show()
ls.hidden = false
}
func (ls *LinuxStatus) Hide() {
log.Log(CHANGE, "linuxStatus.Hide() window")
if ! ls.Ready() {return}
log.Log(CHANGE, "linuxStatus.Hide() window ready =", ls.ready)
ls.window.Hide()
ls.hidden = true
}
func (ls *LinuxStatus) Toggle() {
log.Log(CHANGE, "linuxStatus.Toggle() window")
if ! ls.Ready() {return}
log.Log(CHANGE, "linuxStatus.Toggle() window ready =", ls.ready)
if ls.hidden {
ls.window.Show()
ls.Show()
} else {
ls.window.Hide()
ls.Hide()
}
}
func (ls *LinuxStatus) Ready() bool {
log.Log(CHANGE, "Ready() ls =", ls)
if me == nil {return false}
if ls == nil {return false}
if ls.window == nil {return false}
@ -34,8 +56,22 @@ func (ls *LinuxStatus) Ready() bool {
}
func (ls *LinuxStatus) Initialized() bool {
log.Log(CHANGE, "checking Initialized() ls =", ls)
if me == nil {return false}
if ls == nil {return false}
if ls.parent == nil {return false}
return true
}
func (ls *LinuxStatus) SetParent(p *gui.Node) {
log.Log(CHANGE, "Attempting SetParent =", p)
if me == nil {return}
if ls == nil {return}
if ls.parent == nil {
log.Log(CHANGE, "SetParent =", p)
ls.parent = p
return
} else {
log.Log(CHANGE, "SetParent was already set to =", ls.parent)
}
}

View File

@ -27,6 +27,7 @@ func draw(ls *LinuxStatus) {
ls.grid.NewLabel("interfaces =")
ls.Interfaces = ls.grid.NewCombobox("Interfaces")
ls.speed = gadgets.NewOneLiner(ls.grid, "refresh speed =")
ls.speedActual = gadgets.NewOneLiner(ls.grid, "refresh speed =")
ls.grid.Margin()

View File

@ -3,6 +3,8 @@
package linuxstatus
import (
"errors"
"go.wit.com/log"
"go.wit.com/shell"
@ -28,7 +30,7 @@ func getHostname() {
log.Error(err, "FQDN hostname error")
return
}
log.Warn("full hostname should be:", s)
log.Error(errors.New("full hostname should be: " + s))
dn := run("domainname")
if (me.domainname.Get() != dn) {

View File

@ -15,7 +15,7 @@ import (
func linuxLoop() {
me.changed = false
duration := timeFunction(getHostname)
log.Info("getHostname() execution Time: ", duration, "me.changed =", me.changed)
log.Log(INFO, "getHostname() execution Time: ", duration, "me.changed =", me.changed)
duration = timeFunction(scanInterfaces)
log.Log(NET, "scanInterfaces() execution Time: ", duration)
@ -33,7 +33,7 @@ func linuxLoop() {
// me.IPv6.SetText(all)
user, _ := user.Current()
log.Println("os.Getuid =", user.Username, os.Getuid())
log.Log(INFO, "os.Getuid =", user.Username, os.Getuid())
if (me.uid != nil) {
me.uid.Set(user.Username + " (" + strconv.Itoa(os.Getuid()) + ")")
}

View File

@ -74,7 +74,7 @@ func renameInterface(i *net.Interface) {
func checkInterface(i net.Interface) {
val, ok := me.ifmap[i.Index]
if ! ok {
log.Info(i.Name, "is a new network interface. The linux kernel index =", i.Index)
log.Log(INFO, i.Name, "is a new network interface. The linux kernel index =", i.Index)
me.ifmap[i.Index] = new(IFtype)
me.ifmap[i.Index].gone = false
me.ifmap[i.Index].iface = &i
@ -88,7 +88,7 @@ func checkInterface(i net.Interface) {
me.ifmap[i.Index].gone = false
log.Log(NET, "me.ifmap[i] does exist. Need to compare everything.", i.Index, i.Name, val.iface.Index, val.iface.Name)
if (val.iface.Name != i.Name) {
log.Info(val.iface.Name, "has changed to it's name to", i.Name)
log.Log(INFO, val.iface.Name, "has changed to it's name to", i.Name)
me.ifmap[i.Index].iface = &i
me.changed = true
if (me.Interfaces != nil) {
@ -143,14 +143,14 @@ func checkDNS() (map[string]*IPtype, map[string]*IPtype) {
ipt = "IPv6"
}
if (t.IsReal()) {
log.Info("\tIP is Real ", ipt, i.Index, i.Name, s)
log.Log(INFO, "\tIP is Real ", ipt, i.Index, i.Name, s)
if (t.ipv6) {
ipv6s[s] = t
} else {
ipv4s[s] = t
}
} else {
log.Info("\tIP is not Real", ipt, i.Index, i.Name, s)
log.Log(INFO, "\tIP is not Real", ipt, i.Index, i.Name, s)
}
}
return ipv6s, ipv4s
@ -192,14 +192,14 @@ func checkIP(ip *net.IPNet, i net.Interface) bool {
}
}
if (IsReal(&ip.IP)) {
log.Info("\tIP is Real ", t, i.Index, i.Name, realip)
log.Log(INFO, "\tIP is Real ", t, i.Index, i.Name, realip)
} else {
log.Info("\tIP is not Real", t, i.Index, i.Name, realip)
log.Log(INFO, "\tIP is not Real", t, i.Index, i.Name, realip)
}
log.Log(NET, "\t\tIP is IsPrivate() =", ip.IP.IsPrivate())
log.Log(NET, "\t\tIP is IsLoopback() =", ip.IP.IsLoopback())
log.Log(NET, "\t\tIP is IsLinkLocalUnicast() =", ip.IP.IsLinkLocalUnicast())
// log.Info("HERE HERE", "realip =", realip, "me.ip[realip]=", me.ipmap[realip])
// log.Log(INFO, "HERE HERE", "realip =", realip, "me.ip[realip]=", me.ipmap[realip])
return true
}
@ -210,7 +210,7 @@ func scanInterfaces() {
log.Log(NET, SPEW, ifaces)
for _, i := range ifaces {
addrs, _ := i.Addrs()
// log.Info("range ifaces = ", i)
// log.Log(INFO, "range ifaces = ", i)
checkInterface(i)
log.Log(NET, "*net.Interface.Name = ", i.Name, i.Index)
log.Log(NET, SPEW, i)

View File

@ -9,29 +9,31 @@ import (
func New() *LinuxStatus {
if me != nil {
log.Warn("You have done New() twice. You can only do this once")
log.Log(WARN, "You have done New() twice. You can only do this once")
return me
}
me = &LinuxStatus {
hidden: true,
ready: false,
}
me.ifmap = make(map[int]*IFtype)
me.ipmap = make(map[string]*IPtype)
return me
}
func (ls *LinuxStatus) InitWindow() {
if ! ls.Initialized() {
log.Warn("LinuxStatus() is not initalized yet (no parent for the window?)")
log.Log(WARN, "not initalized yet (no parent for the window?)")
return
}
if ls.window != nil {
log.Warn("You already have a window")
log.Log(WARN, "You already have a window")
ls.ready = true
return
}
ls.ready = true
log.Warn("Creating the Window")
log.Log(WARN, "Creating the Window")
ls.window = gadgets.NewBasicWindow(ls.parent, "Linux OS Details")
ls.ready = true
}

View File

@ -36,6 +36,7 @@ type LinuxStatus struct {
IPv6 *gadgets.OneLiner
workingIPv6 *gadgets.OneLiner
Interfaces *gui.Node
speed *gadgets.OneLiner
speedActual *gadgets.OneLiner
}

View File

@ -1,31 +1,40 @@
package linuxstatus
import (
"errors"
"fmt"
"time"
"errors"
"go.wit.com/log"
)
func (ls *LinuxStatus) Update() {
log.Info("linuxStatus() Update() START")
if ls == nil {
log.Error(errors.New("linuxStatus() Update() ls == nil"))
if ! ls.Ready() {
log.Warn("can't update yet. ready is false")
log.Error(errors.New("Update() is not ready yet"))
return
}
log.Log(INFO, "Update() START")
duration := timeFunction(func () {
linuxLoop()
})
ls.SetSpeed(duration)
log.Info("linuxStatus() Update() END")
}
func (ls *LinuxStatus) SetSpeed(duration time.Duration) {
s := fmt.Sprint(duration)
if ls.speedActual == nil {
log.Warn("can't actually warn")
return
}
ls.speedActual.Set(s)
if (duration > 500 * time.Millisecond ) {
// ls.speed, "SLOW")
ls.speed.Set("SLOW")
} else if (duration > 100 * time.Millisecond ) {
// ls.speed, "OK")
ls.speed.Set("OK")
} else {
// ls.speed, "FAST")
ls.speed.Set("FAST")
}
log.Info("linuxStatus() Update() END")
}