summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-01-18 14:21:02 -0600
committerJeff Carr <[email protected]>2024-01-18 14:21:02 -0600
commit209074a2448b17dfbd6d92057e4410bc4309830d (patch)
treeacb4e470b4c2bb328ab77bef80f7d82897556d24
parentafcf7f87aa8f35ca2fe69c54373d28788ba03f84 (diff)
strangely time.Sleep() doesn't seem to work
Signed-off-by: Jeff Carr <[email protected]>
-rw-r--r--globalBuildOptions.go73
-rw-r--r--unix.go49
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))
-
- 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)
+ 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"})
- 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
+}