diff options
| author | Jeff Carr <[email protected]> | 2025-10-14 07:11:55 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-10-14 07:11:55 -0500 |
| commit | d7be78aeaa1bcb8186233f5f8807d5d0c2a5dfb0 (patch) | |
| tree | b831a0b2f9d32e58020ec5e754c2b42ae6b8e87f /tableSmart.go | |
| parent | 44db8e83059e1d96abbe9b1a71aabbfa59c5b71a (diff) | |
rename
Diffstat (limited to 'tableSmart.go')
| -rw-r--r-- | tableSmart.go | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/tableSmart.go b/tableSmart.go new file mode 100644 index 0000000..64a9877 --- /dev/null +++ b/tableSmart.go @@ -0,0 +1,125 @@ +// Copyright 2025 WIT.COM Inc Licensed GPL 3.0 + +package zoopb + +import ( + "go.wit.com/lib/cobol" + "go.wit.com/log" +) + +// tables for what packages are currently installed + +func (m *Machine) PrintTable(pb *Packages) { + tablePB := m.makeSmartTable(pb) + tablePB.PrintTable() + var i int + for p := range pb.IterAll() { + if m.IsInstalled(p.Package) { + i += 1 + } + } + + log.Printf("pb.SmartTable: packages: total=%d installed=%d\n", pb.Len(), i) +} + +func (m *Machine) PrintInstalledTable() { + installed := NewPackages() + for p := range m.Wit.IterAll() { + if m.IsInstalled(p.Package) { + installed.Append(p) + } + } + tablePB := m.makeSmartTable(installed) + if tablePB == nil { + panic("WTF") + } + tablePB.PrintTable() + log.Printf("pb.SmartTable: %d installed packages\n", installed.Len()) +} + +func (m *Machine) makeSmartTable(pb *Packages) *PackagesTable { + t := pb.NewTable("apt packages") + t.NewUuid() + + var col *PackageFunc + + col = t.AddStringFunc(" I", func(p *Package) string { + if m.IsInstalled(p.Package) { + return " X" + } + return "" + }) + col.Width = 3 + + col = t.AddStringFunc("U", func(p *Package) string { + if m.WillUpgrade(p) { + return "X" + } + return "" + }) + col.Width = 1 + + col = t.AddStringFunc("DebCtime", func(p *Package) string { + if p.DebInfo == nil { + return "debinfo == nil" + } + if p.DebInfo.DebCtime != "" { + return p.DebInfo.DebCtime + } + if p.BuildDate != nil { + return "not " + cobol.Time(p.BuildDate) + } + if p.Ctime != nil { + return "lies " + cobol.Time(p.Ctime) + } + return "" + }) + col.Width = 22 + + col = t.AddStringFunc("anytime", func(p *Package) string { + if p.DebInfo == nil { + return "debinfo == nil" + } + if p.BuildDate != nil { + return "not " + cobol.Time(p.BuildDate) + } + if p.Ctime != nil { + return "lies " + cobol.Time(p.Ctime) + } + return "" + }) + col.Width = 22 + + col = t.AddPackage() + col.Width = 16 + + col = t.AddVersion() + col.Width = 20 + + col = t.AddStringFunc("md5sum", func(p *Package) string { + if p.DebInfo == nil { + return "" + } + return p.DebInfo.MD5SUM + }) + col.Width = 3 + + col = t.AddFilename() + col.Width = -1 + col.Header.Name = "apt package path" + + return t +} + +// true if the package 'p' is newer than the installed package +func (m *Machine) WillUpgrade(p *Package) bool { + check := m.FindInstalledByName(p.Package) + if check == nil { + // not installed. can not upgrade + return false + } + if check.Version != p.Version { + return true + } + return false +} |
