submit-patchset/scan.go

95 lines
2.0 KiB
Go

package main
import (
"fmt"
"os/user"
"time"
"go.wit.com/log"
"go.wit.com/lib/gui/repostatus"
)
func (r *repo) newScan() bool {
if r.status == nil {
log.Warn("repo.status = nil. not initialized for some reason")
return false
}
// r.scan()
if repostatus.VerifyLocalGoRepo(r.getPath()) {
log.Verbose("repo actually exists", r.getPath())
} else {
log.Warn("repo does not exist", r.getPath())
return false
}
mname := r.status.GetMasterBranchName()
mver := r.status.GetMasterVersion()
if mname != "guimaster" {
mver = mver + " (" + mname + ")"
}
r.masterVersion.SetLabel(mver)
dname := r.status.GetDevelBranchName()
dver := r.status.GetDevelVersion()
if dname != "devel" {
dver = dver + " (" + dname + ")"
}
r.develVersion.SetLabel(dver)
uname := r.status.GetUserBranchName()
uver := r.status.GetUserVersion()
usr, _ := user.Current()
if uname != usr.Username {
uver = uver + " (" + uname + ")"
}
r.userVersion.SetLabel(uver)
cbname := r.status.GetCurrentBranchName()
cbversion := r.status.GetCurrentBranchVersion()
lasttag := r.status.GetLastTagVersion()
r.lastTag.SetLabel(lasttag)
r.vLabel.SetLabel(cbname + " " + cbversion)
if r.status.Changed() {
log.Warn("should scan here")
}
status := r.status.GetStatus()
r.dirtyLabel.SetLabel(status)
if status == "PERFECT" {
if me.autoHidePerfect.Checked() {
r.Hide()
}
return true
}
return false
}
// timeFunction takes a function as an argument and returns the execution time.
func timeFunction(f func()) time.Duration {
startTime := time.Now() // Record the start time
f() // Execute the function
return time.Since(startTime) // Calculate the elapsed time
}
func myTicker(t time.Duration, name string, f func()) {
ticker := time.NewTicker(t)
defer ticker.Stop()
done := make(chan bool)
/*
go func() {
time.Sleep(10 * time.Second)
done <- true
}()
*/
for {
select {
case <-done:
fmt.Println("Done!")
return
case t := <-ticker.C:
log.Verbose(name, "Current time: ", t)
f()
}
}
}