more code cleanup
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
289c319ea9
commit
5067224fc8
|
@ -2,11 +2,14 @@ package main
|
|||
|
||||
import "log"
|
||||
import "fmt"
|
||||
import "runtime"
|
||||
import "os/exec"
|
||||
import "strings"
|
||||
|
||||
import "git.wit.com/wit/gui"
|
||||
import pb "git.wit.com/wit/witProtobuf"
|
||||
|
||||
// import "github.com/davecgh/go-spew/spew"
|
||||
import "github.com/davecgh/go-spew/spew"
|
||||
|
||||
//
|
||||
// THIS IS THE STANDARD VM DISPLAY TABLE
|
||||
|
@ -121,26 +124,77 @@ func createVmBox(gw *gui.GuiWindow, vm *pb.Event_VM) {
|
|||
gui.MakeEntryVbox(box, "Disk (GB):", fmt.Sprintf("%d",vm.Disk), true, "Disk")
|
||||
gui.MakeEntryVbox(box, "OS Image:", vm.BaseImage, true, "BaseImage")
|
||||
|
||||
gui.HorizontalBreak(box)
|
||||
|
||||
a := gui.CreateButton(box, nil, vm, "Power On", "POWERON", nil)
|
||||
gui.AddButtonToBox(box, a)
|
||||
a = gui.CreateButton(box, nil, vm, "Power Off", "POWEROFF", nil)
|
||||
gui.AddButtonToBox(box, a)
|
||||
a = gui.CreateButton(box, nil, vm, "Destroy", "DESTROY", nil)
|
||||
gui.AddButtonToBox(box, a)
|
||||
a = gui.CreateButton(box, nil, vm, "ping", "PING", runPingClick)
|
||||
gui.AddButtonToBox(box, a)
|
||||
a = gui.CreateButton(box, nil, vm, "Console", "XTERM", runTestExecClick)
|
||||
gui.AddButtonToBox(box, a)
|
||||
a = gui.CreateButton(box, nil, vm, "Save", "SAVE", nil)
|
||||
gui.AddButtonToBox(box, a)
|
||||
a = gui.CreateButton(box, nil, vm, "Done", "DONE", nil)
|
||||
gui.AddButtonToBox(box, a)
|
||||
}
|
||||
|
||||
func runTestHide(b *gui.GuiButton) {
|
||||
/*
|
||||
vbox.Append(ui.NewHorizontalSeparator(), false)
|
||||
|
||||
hboxButtons := ui.NewHorizontalBox()
|
||||
hboxButtons.SetPadded(true)
|
||||
vbox.Append(hboxButtons, false)
|
||||
|
||||
a := CreateButton(box, nil, vm, "Power On", "POWERON", nil)
|
||||
hboxButtons.Append(a.B, false)
|
||||
a = CreateButton(box, nil, vm, "Power Off", "POWEROFF", nil)
|
||||
hboxButtons.Append(a.B, false)
|
||||
a = CreateButton(box, nil, vm, "Destroy", "DESTROY", nil)
|
||||
hboxButtons.Append(a.B, false)
|
||||
a = CreateButton(box, nil, vm, "ping", "PING", runPingClick)
|
||||
hboxButtons.Append(a.B, false)
|
||||
a = CreateButton(box, nil, vm, "Console", "XTERM", runTestExecClick)
|
||||
hboxButtons.Append(a.B, false)
|
||||
a = CreateButton(box, nil, vm, "Save", "SAVE", nil)
|
||||
hboxButtons.Append(a.B, false)
|
||||
a = CreateButton(box, nil, vm, "Done", "DONE", nil)
|
||||
hboxButtons.Append(a.B, false)
|
||||
log.Println("runTestHide START")
|
||||
Data.Window1.Box1.Hide()
|
||||
Data.Window1.Box2.Hide()
|
||||
// time.Sleep(2000 * time.Millisecond)
|
||||
Data.State = "HIDE"
|
||||
log.Println("runTestHide END")
|
||||
*/
|
||||
}
|
||||
|
||||
func runPingClick(b *gui.GuiButton) {
|
||||
log.Println("runPingClick START")
|
||||
log.Println("runTestExecClick b.VM", b.VM)
|
||||
hostname := "localhost"
|
||||
if (b.VM != nil) {
|
||||
hostname = b.VM.Hostname
|
||||
}
|
||||
spew.Dump(b)
|
||||
var tmp []string
|
||||
tmp = append(tmp, "xterm", "-geometry", "120x30", "-e", "ping " + hostname + ";sleep 3")
|
||||
go runCommand(tmp)
|
||||
log.Println("runPingClick END")
|
||||
}
|
||||
|
||||
func runTestExecClick(b *gui.GuiButton) {
|
||||
log.Println("runTestExecClick START")
|
||||
if runtime.GOOS == "linux" {
|
||||
go runSimpleCommand("xterm -report-fonts")
|
||||
} else if runtime.GOOS == "windows" {
|
||||
go runSimpleCommand("mintty.exe")
|
||||
} else {
|
||||
go runSimpleCommand("xterm")
|
||||
}
|
||||
log.Println("runTestExecClick END")
|
||||
}
|
||||
|
||||
func runSimpleCommand(s string) {
|
||||
cmd := strings.TrimSpace(s) // this is like 'chomp' in perl
|
||||
cmdArgs := strings.Fields(cmd)
|
||||
runCommand(cmdArgs)
|
||||
}
|
||||
|
||||
func runCommand(cmdArgs []string) {
|
||||
log.Println("runCommand() START", cmdArgs)
|
||||
process := exec.Command(cmdArgs[0], cmdArgs[1:len(cmdArgs)]...)
|
||||
// process := exec.Command("xterm", "-e", "ping localhost")
|
||||
log.Println("runCommand() process.Start()")
|
||||
process.Start()
|
||||
log.Println("runCommand() process.Wait()")
|
||||
process.Wait()
|
||||
log.Println("runCommand() NEED TO CHECK THE TIME HERE TO SEE IF THIS WORKED")
|
||||
log.Println("runCommand() OTHERWISE INFORM THE USER")
|
||||
log.Println("runCommand() END")
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue