repolist/scan.go

82 lines
1.5 KiB
Go

package repolist
import (
"fmt"
"strconv"
"strings"
"go.wit.com/log"
)
func (r *RepoList) SetAutoScan(b bool) {
me.autoScan = b
}
func (r *RepoList) RegisterHideFunction(f func(*RepoRow)) {
me.hideFunction = f
}
func (r *RepoList) ScanRepositories() (int, string) {
var i int
var shown int
var total int
t := TimeFunction(func() {
for _, repo := range me.allrepos {
i += 1
changed := repo.NewScan()
total += changed
if me.hideFunction == nil {
// application didn't register a hide function
} else {
me.hideFunction(repo)
}
}
var hidden int
for _, repo := range me.allrepos {
if repo.Hidden() {
hidden += 1
} else {
shown += 1
}
}
})
s := fmt.Sprint(t)
tmp := strconv.Itoa(shown) + " repos shown"
log.Info("Setting shownCount to", tmp)
me.shownCount.SetText(tmp)
me.duration.SetText(s)
log.Info("Scanned", i, "repositories.", total, "changes in", s)
return i, s
}
func (r *RepoRow) NewScan() int {
var changed int = 0
if r.Status == nil {
log.Warn("repo.Status = nil. not initialized for some reason")
return changed
}
// run the repostatus update
r.Status.Update()
// print out whatever changes have happened
if c, ok := r.Status.Changed(); ok {
c := strings.TrimSpace(c)
for _, line := range strings.Split(c, "\n") {
log.Info(r.Status.Path(), line)
changed += 1
}
}
// hide or show repos based on the checkboxes
if me.autoHidePerfect {
if r.IsPerfect() {
r.Hide()
} else {
r.Show()
}
}
return changed
}