From 209074a2448b17dfbd6d92057e4410bc4309830d Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 18 Jan 2024 14:21:02 -0600 Subject: [PATCH] strangely time.Sleep() doesn't seem to work Signed-off-by: Jeff Carr --- globalBuildOptions.go | 73 +++++++++++++------------------------------ unix.go | 49 ++++++++++++++++++++++++++++- 2 files changed, 69 insertions(+), 53 deletions(-) diff --git a/globalBuildOptions.go b/globalBuildOptions.go index db6e676..1e64b28 100644 --- a/globalBuildOptions.go +++ b/globalBuildOptions.go @@ -9,7 +9,6 @@ import ( "go.wit.com/gui" "go.wit.com/lib/gadgets" - "go.wit.com/lib/gui/repostatus" ) func doesExist(path string) bool { @@ -27,13 +26,15 @@ func quickCmd(fullpath string, cmd []string) bool { var b bool var output string + log.Warn("RUN:", fullpath, cmd) cmd = []string{"mkdir", "-p", "go.wit.com/apps/"} if err != nil { - err, b, output = repostatus.RunCmd(fullpath, cmd) - log.Error(err, b, string(output)) + err, b, output = RunCmdNew(fullpath, cmd) + log.Error(err) return false } else if ! b { - log.Error(err, b, string(output)) + log.Warn("b =", b) + log.Warn("output =", string(output)) return true } log.Warn("output = ", string(output)) @@ -78,68 +79,36 @@ func globalBuildOptions(box *gui.Node) { quickCmd(fullpath, []string{"mkdir", "-p", "go.wit.com/apps/"}) fullpath = "/home/jcarr/go/src/go.wit.com/apps/autotypist" - cmd := []string{"go", "get", "-v", "-u", "go.wit.com/apps/autotypist"} - err, b, output := repostatus.RunCmd(fullpath, cmd) - 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)) + quickCmd(fullpath, []string{"go", "get", "-v", "-u", "go.wit.com/apps/autotypist"}) + quickCmd(fullpath, []string{"go", "get", "-v", "-u", "go.wit.com/toolkits/debian"}) fullpath = "/home/jcarr/go/src/go.wit.com/toolkits/debian" + quickCmd(fullpath, []string{"make"}) - cmd = []string{"make"} - err, b, output = repostatus.RunCmd(fullpath, cmd) - log.Warn(err, b, string(output)) + fullpath = "/home/jcarr/go/src/go.wit.com/apps/autotypist" + quickCmd(fullpath, []string{"go", "-v", "-x", "build"}) }) me.rerunGoMod = groupvbox.NewButton("re-run go mod & go tidy", func() { me.rerunGoMod.Disable() log.Warn("scanning allrepos") os.Unsetenv("GO111MODULE") - for repo, path := range me.allrepos { - var cmd []string - var err error - var b bool - var output string - - log.Warn("found repo", path, repo.String()) + for _, path := range me.allrepos { fullpath := "/home/jcarr/go/src/" + path - + // set the button text for the user me.rerunGoMod.SetText("Running go.mod " + fullpath) - cmd = []string{"rm", "go.mod", "go.sum"} - // log.Warn("Actually RUN path =", fullpath, "cmd =", cmd) - err, b, output = repostatus.RunCmd(fullpath, cmd) - log.Warn(err, b, string(output)) + quickCmd(fullpath, []string{"pwd"}) + quickCmd(fullpath, []string{"ls", "-l"}) + quickCmd(fullpath, []string{"go", "status"}) // TODO: process this? + quickCmd(fullpath, []string{"rm", "go.mod", "go.sum"}) - log.Sleep(.1) - - cmd = []string{"go", "mod", "init"} - // 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(.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)) + quickCmd(fullpath, []string{"go", "mod", "init"}) + log.Sleep(.1) // don't hammer google's golang versioning system + quickCmd(fullpath, []string{"go", "mod", "tidy"}) + log.Sleep(.2) // don't hammer google's golang versioning system } + // re-enable the button me.rerunGoMod.SetText("re-run go mod & go tidy") me.rerunGoMod.Enable() }) diff --git a/unix.go b/unix.go index 5574e5d..f2e27f7 100644 --- a/unix.go +++ b/unix.go @@ -1,9 +1,13 @@ package main import ( - "go.wit.com/log" + "os" + "os/exec" + "time" "strings" + "errors" + "go.wit.com/log" "go.wit.com/lib/gui/repostatus" ) @@ -87,3 +91,46 @@ func runCommandsOld() bool { 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 +}