playing with the ui

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2019-04-05 19:54:50 -07:00
parent 1d84dc6ee3
commit d9357e9e2d
3 changed files with 34 additions and 15 deletions

View File

@ -4,6 +4,7 @@ import "log"
import "fmt"
import "strings"
import "reflect"
import "os"
import "os/exec"
import "bytes"
@ -66,19 +67,26 @@ func format(mybut *ui.Button) {
// exampleCommand("ls", "/tmp")
// stdoutExec("ls /tmp", 50)
// ping("git.wit.com", 5)
// simpleScanner("ping git.wit.com")
// simpleScanner("dd if=/home/pinebook/factory/factory-pine14inch of=/dev/sdb status=progress bs=1M oflag=sync count=300");
// simpleScanner("dd if=/home/pinebook/factory/factory-pine14inch of=/dev/sdb status=progress bs=1M oflag=sync count=300");
simpleScanner("parted /dev/sdb mklabel msdos")
simpleScanner("parted /dev/sdb mkpart primary ext4 1MiB 8GB")
simpleScanner("parted /dev/sdb mkpart primary ext4 8GB 32GB")
simpleScanner("sleep 1")
simpleScanner("mkfs.ext4 /dev/sdb1")
simpleScanner("mkfs.ext4 /dev/sdb2")
simpleScanner("e2label /dev/sdb1 root")
simpleScanner("e2label /dev/sdb2 factory-image")
simpleScanner("mount /dev/sdb1 /mnt/sdcard/")
simpleScanner("dd if=u-boot-sunxi-with-spl.bin of=/dev/sdb bs=1K seek=8")
// simpleProcess("ping git.wit.com")
// simpleProcess("dd if=/home/pinebook/factory/factory-pine14inch of=/dev/sdb status=progress bs=1M oflag=sync count=300");
// simpleProcess("dd if=/home/pinebook/factory/factory-pine14inch of=/dev/sdb status=progress bs=1M oflag=sync count=300");
simpleProcess("pwd")
simpleProcess("ls -l")
os.Chdir("/mnt")
simpleProcess("pwd")
simpleProcess("ls -l")
return
simpleProcess("parted -s /dev/sdb mklabel msdos")
simpleProcess("parted -s /dev/sdb mkpart primary ext4 1MiB 8GB")
simpleProcess("parted -s /dev/sdb mkpart primary ext4 8GB 32GB")
simpleProcess("sleep 1")
simpleProcess("mkfs.ext4 /dev/sdb1")
simpleProcess("mkfs.ext4 /dev/sdb2")
simpleProcess("e2label /dev/sdb1 root")
simpleProcess("e2label /dev/sdb2 factory-image")
simpleProcess("mount /dev/sdb1 /mnt/sdcard/")
simpleProcess("dd if=../u-boot/u-boot-sunxi-with-spl.bin of=/dev/sdb bs=1K seek=8")
}
func hostnameButton(hostname string, something func(*ui.Button)) ui.Control {

View File

@ -7,6 +7,8 @@ import "io"
import "os"
import "os/exec"
import "bufio"
import "reflect"
import "github.com/davecgh/go-spew/spew"
/*
func exampleCommand(a string, b ...string) {
@ -62,7 +64,8 @@ func ping(hostname string, count int) {
cmd.Wait()
}
func simpleScanner(cmd string) {
// Spawns a process and captures stdout and stderr
func simpleProcess(cmd string) {
log.Println("START " + cmd)
// cmd := exec.Command("ls", "/tmp", "/ballon", "/")
@ -72,7 +75,12 @@ func simpleScanner(cmd string) {
stderr, _ := process.StderrPipe()
process.Start()
fmt.Println("start ls /tmp")
pid := process.Process.Pid
fmt.Println("start ls /tmp pid =", pid)
log.Println(reflect.ValueOf(process.Process).Elem())
log.Println(reflect.TypeOf(process.Process))
spew.Dump(process)
merged := io.MultiReader(stderr, stdout)
scanner := bufio.NewScanner(merged)
@ -84,6 +92,9 @@ func simpleScanner(cmd string) {
// fmt.Fprintln(os.Stderr, "reading standard input:", err)
fmt.Println("reading standard input:", err)
}
// One must wait for the process to formally finish and flush all buffer output
process.Wait()
log.Println("END " + cmd)
}