strangely time.Sleep() doesn't seem to work

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-01-18 14:21:02 -06:00
parent afcf7f87aa
commit 209074a244
2 changed files with 69 additions and 53 deletions

View File

@ -9,7 +9,6 @@ import (
"go.wit.com/gui" "go.wit.com/gui"
"go.wit.com/lib/gadgets" "go.wit.com/lib/gadgets"
"go.wit.com/lib/gui/repostatus"
) )
func doesExist(path string) bool { func doesExist(path string) bool {
@ -27,13 +26,15 @@ func quickCmd(fullpath string, cmd []string) bool {
var b bool var b bool
var output string var output string
log.Warn("RUN:", fullpath, cmd)
cmd = []string{"mkdir", "-p", "go.wit.com/apps/"} cmd = []string{"mkdir", "-p", "go.wit.com/apps/"}
if err != nil { if err != nil {
err, b, output = repostatus.RunCmd(fullpath, cmd) err, b, output = RunCmdNew(fullpath, cmd)
log.Error(err, b, string(output)) log.Error(err)
return false return false
} else if ! b { } else if ! b {
log.Error(err, b, string(output)) log.Warn("b =", b)
log.Warn("output =", string(output))
return true return true
} }
log.Warn("output = ", string(output)) log.Warn("output = ", string(output))
@ -78,68 +79,36 @@ func globalBuildOptions(box *gui.Node) {
quickCmd(fullpath, []string{"mkdir", "-p", "go.wit.com/apps/"}) quickCmd(fullpath, []string{"mkdir", "-p", "go.wit.com/apps/"})
fullpath = "/home/jcarr/go/src/go.wit.com/apps/autotypist" fullpath = "/home/jcarr/go/src/go.wit.com/apps/autotypist"
cmd := []string{"go", "get", "-v", "-u", "go.wit.com/apps/autotypist"} quickCmd(fullpath, []string{"go", "get", "-v", "-u", "go.wit.com/apps/autotypist"})
err, b, output := repostatus.RunCmd(fullpath, cmd) quickCmd(fullpath, []string{"go", "get", "-v", "-u", "go.wit.com/toolkits/debian"})
log.Warn(err, b, string(output))
cmd = []string{"go", "get", "-v", "-u", "go.wit.com/toolkits/debian"}
err, b, output = repostatus.RunCmd(fullpath, cmd)
log.Warn(err, b, string(output))
fullpath = "/home/jcarr/go/src/go.wit.com/toolkits/debian" fullpath = "/home/jcarr/go/src/go.wit.com/toolkits/debian"
quickCmd(fullpath, []string{"make"})
cmd = []string{"make"} fullpath = "/home/jcarr/go/src/go.wit.com/apps/autotypist"
err, b, output = repostatus.RunCmd(fullpath, cmd) quickCmd(fullpath, []string{"go", "-v", "-x", "build"})
log.Warn(err, b, string(output))
}) })
me.rerunGoMod = groupvbox.NewButton("re-run go mod & go tidy", func() { me.rerunGoMod = groupvbox.NewButton("re-run go mod & go tidy", func() {
me.rerunGoMod.Disable() me.rerunGoMod.Disable()
log.Warn("scanning allrepos") log.Warn("scanning allrepos")
os.Unsetenv("GO111MODULE") os.Unsetenv("GO111MODULE")
for repo, path := range me.allrepos { for _, path := range me.allrepos {
var cmd []string
var err error
var b bool
var output string
log.Warn("found repo", path, repo.String())
fullpath := "/home/jcarr/go/src/" + path fullpath := "/home/jcarr/go/src/" + path
// set the button text for the user
me.rerunGoMod.SetText("Running go.mod " + fullpath) me.rerunGoMod.SetText("Running go.mod " + fullpath)
cmd = []string{"rm", "go.mod", "go.sum"} quickCmd(fullpath, []string{"pwd"})
// log.Warn("Actually RUN path =", fullpath, "cmd =", cmd) quickCmd(fullpath, []string{"ls", "-l"})
err, b, output = repostatus.RunCmd(fullpath, cmd) quickCmd(fullpath, []string{"go", "status"}) // TODO: process this?
log.Warn(err, b, string(output)) quickCmd(fullpath, []string{"rm", "go.mod", "go.sum"})
log.Sleep(.1) quickCmd(fullpath, []string{"go", "mod", "init"})
log.Sleep(.1) // don't hammer google's golang versioning system
cmd = []string{"go", "mod", "init"} quickCmd(fullpath, []string{"go", "mod", "tidy"})
// log.Warn("Actually RUN path =", fullpath, "cmd =", cmd) log.Sleep(.2) // don't hammer google's golang versioning system
err, b, output = repostatus.RunCmd(fullpath, cmd)
log.Warn(err, b, string(output))
if err != nil {
return
}
log.Sleep(.1)
cmd = []string{"go", "mod", "tidy"}
// log.Warn("Actually RUN path =", fullpath, "cmd =", cmd)
err, b, output = repostatus.RunCmd(fullpath, cmd)
log.Warn(err, b, string(output))
if err != nil {
return
}
log.Sleep(.2)
cmd = []string{"git", "status"}
// log.Warn("Actually RUN path =", fullpath, "cmd =", cmd)
err, b, output = repostatus.RunCmd(fullpath, cmd)
log.Warn(err, b, string(output))
} }
// re-enable the button
me.rerunGoMod.SetText("re-run go mod & go tidy") me.rerunGoMod.SetText("re-run go mod & go tidy")
me.rerunGoMod.Enable() me.rerunGoMod.Enable()
}) })

49
unix.go
View File

@ -1,9 +1,13 @@
package main package main
import ( import (
"go.wit.com/log" "os"
"os/exec"
"time"
"strings" "strings"
"errors"
"go.wit.com/log"
"go.wit.com/lib/gui/repostatus" "go.wit.com/lib/gui/repostatus"
) )
@ -87,3 +91,46 @@ func runCommandsOld() bool {
return true return true
} }
*/ */
func RunCmdNew(workingpath string, parts []string) (error, bool, string) {
time.Sleep(10 * time.Second)
return RunCmd(workingpath, parts)
}
func RunCmd(workingpath string, parts []string) (error, bool, string) {
if len(parts) == 0 {
log.Warn("command line was empty")
return errors.New("empty"), false, ""
}
if parts[0] == "" {
log.Warn("command line was empty")
return errors.New("empty"), false, ""
}
thing := parts[0]
parts = parts[1:]
log.Warn("working path =", workingpath, "thing =", thing, "cmdline =", parts)
if thing == "pwd" {
os.Exit(-1)
}
// Create the command
cmd := exec.Command(thing, parts...)
// Set the working directory
cmd.Dir = workingpath
// Execute the command
output, err := cmd.CombinedOutput()
if err != nil {
log.Error(err)
log.Warn("output was", string(output))
log.Warn("cmd exited with error", err)
return err, false, string(output)
}
tmp := string(output)
tmp = strings.TrimSpace(tmp)
// Print the output
return nil, true, tmp
}