summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-10-05 12:04:57 -0500
committerJeff Carr <[email protected]>2025-10-05 12:04:57 -0500
commit0fd8346eddc8e8e1b99f631baff8f3ac3f76c616 (patch)
treefaa2e77542b8866812eb9172d88026f7f996f3ad
parent9da07a667a769d30be1841b39e29ae5f8e95d3e7 (diff)
smarter table of installed packagesv0.0.72
-rw-r--r--tableDefault.go95
1 files changed, 95 insertions, 0 deletions
diff --git a/tableDefault.go b/tableDefault.go
index 33abe26..86f8790 100644
--- a/tableDefault.go
+++ b/tableDefault.go
@@ -2,6 +2,11 @@
package zoopb
+import (
+ "go.wit.com/lib/fhelp"
+ "go.wit.com/log"
+)
+
// this is the default table layout for repos in forge
func (pb *Packages) PrintTable() {
@@ -35,3 +40,93 @@ func (pb *Packages) makeDefaultTable() *PackagesTable {
return t
}
+
+func (m *Machine) PrintTable(pb *Packages) {
+ tablePB := m.makeSmartTable(pb)
+ tablePB.PrintTable()
+}
+
+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.Name) {
+ 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("BAD", func(p *Package) string {
+ if m.MirrorsOutOfDate(p) {
+ return "BAD"
+ }
+ return ""
+ })
+ col.Width = 3
+
+ col = t.AddName()
+ col.Width = 30
+
+ col = t.AddVersion()
+ col.Width = 20
+
+ col = t.AddPkgName()
+ 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.Name)
+ if check == nil {
+ // not installed. can not upgrade
+ return false
+ }
+ v1, _ := fhelp.NewDebVersion(check.Version)
+ v2, _ := fhelp.NewDebVersion(p.Version)
+ if v1.Equal(v2) {
+ // log.Info("do nothing", v1, v2)
+ return false
+ }
+ if v1.LessThan(v2) {
+ log.Info("upgrading from", v1, "to", v2)
+ return true
+ }
+ log.Info("WEIRD: keeping on machine version:", v1, "newer than mirrors.wit.com:", v2)
+ return false
+}
+
+// this means somehow this machine has a newer version than the mirrors have
+// true if the package 'p' is newer than the installed package
+func (m *Machine) MirrorsOutOfDate(p *Package) bool {
+ check := m.FindInstalledByName(p.Name)
+ if check == nil {
+ // not installed
+ return false
+ }
+ v1, _ := fhelp.NewDebVersion(check.Version)
+ v2, _ := fhelp.NewDebVersion(p.Version)
+ if v1.Equal(v2) {
+ // log.Info("do nothing", v1, v2)
+ return false
+ }
+ if v2.LessThan(v1) {
+ log.Info("wow. you have a newer version on this box than the mirrors", v1, "to", v2)
+ return true
+ }
+ return false
+}