1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
// Copyright 2025 WIT.COM Inc Licensed GPL 3.0
package zoopb
import (
"fmt"
"strconv"
"strings"
"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 (t *PackagesTable) AddSmartVersion() *PackageFunc {
sf := t.AddStringFunc("Version", func(m *Package) string {
version := m.Version
if strings.Contains(version, "+b") {
parts := strings.Split(version, "+b")
if len(parts) == 2 {
version = parts[0]
}
}
if strings.HasSuffix(version, "-0") {
version = version[0 : len(version)-2]
}
return version
})
sf.Width = 12
return sf
}
func (p *Package) GetBuildCount() int {
bcount := 0
if strings.Contains(p.Version, "+b") {
parts := strings.Split(p.Version, "+b")
if len(parts) == 2 {
bcount, _ = strconv.Atoi(parts[1])
}
}
return bcount
}
func (t *PackagesTable) AddBuildCount() *PackageFunc {
sf := t.AddStringFunc(" b#", func(m *Package) string {
bcount := m.GetBuildCount()
if bcount == 0 {
return ""
}
return fmt.Sprintf("+b%d", bcount)
})
sf.Width = 5
return sf
}
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.WillUpgrade(p) {
return " U"
}
if m.IsInstalled(p.Package) {
return " X"
}
return ""
})
col.Width = 3
col = t.AddPackage()
col.Width = 16
col = t.AddSmartVersion()
col = t.AddBuildCount()
col = t.AddStringFunc("mirrors .deb ctime", func(p *Package) string {
if p.DebInfo == nil {
return "debinfo == nil"
}
if p.DebInfo.DebCtime != "" {
return cobol.Time(p.DebInfo.DebCtime)
}
return ""
})
col.Width = 28
col = t.AddStringFunc("Build Date", func(p *Package) string {
if p.DebInfo == nil {
return "debinfo == nil"
}
if p.BuildDate != nil {
return cobol.Time(p.BuildDate)
}
if p.Ctime != nil {
return "lies " + cobol.Time(p.Ctime)
}
return "p.Ctime == nil"
})
col.Width = 28
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
}
|