summaryrefslogtreecommitdiff
path: root/stateWindow.go
blob: 5d88d8e749fcc77840c5b282e3e01e5ef1b066ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// This window, when it's hidden, still exists to the application
// so it can be treated as if it really exists
package main

import (
	"os"

	"go.wit.com/gui"
	"go.wit.com/lib/gadgets"
	"go.wit.com/lib/gui/shell"
	"go.wit.com/log"
)

var apple *gui.Node

// This initializes the first window, a group and a button
func makebasicWindow() *gadgets.BasicWindow {
	log.Warn("init basicWindow state")
	basicWindow = gadgets.NewBasicWindow(myGui, "Create .deb files for GO applications")
	basicWindow.Make()
	basicWindow.Custom = func() {
		log.Info("got to close")
		os.Exit(0)
	}

	box1 := basicWindow.Box()
	control := newControl(box1)

	vbox := box1.Box().Horizontal()
	group1 := vbox.NewGroup("controls").Horizontal() // Vertical()

	group1.NewButton("go build", func() {
		shell.Run([]string{"go", "build", "-v", "-x"})
	})

	group1.NewButton("read control file", func() {
		control.readControlFile()
	})

	group1.NewButton("Make .deb", func() {
		basicWindow.Disable()
		if control.buildPackage() {
			log.Info("build worked")
		} else {
			log.Warn("build failed")
		}
		basicWindow.Enable()
	})

	group1.NewButton("open repo", func() {
	})
	/*
		group1.NewButton("show apple", func() {
			apple.Show()
		})
		apple = group1.NewButton("apple", func() {
			log.Info("is not a pear")
		})
	*/

	return basicWindow
}

func (c *controlFile) buildPackage() bool {
	if c.readControlFile() == nil {
		log.Warn("scan worked")
	} else {
		log.Warn("scan failed")
		return false
	}
	if shell.Run([]string{"go", "build", "-v", "-x"}) {
		log.Warn("build worked")
	} else {
		log.Warn("build failed")
		return false
	}

	filename := c.Package.String()
	if filename == "" {
		log.Warn("build failed")
		return false
	}
	if !shell.Exists(filename) {
		log.Warn("build failed")
		return false
	}

	arch := c.Architecture.String()
	version := "v0.0.0"

	debname := filename + "_" + version + "_" + arch + ".deb"

	shell.Run([]string{"strip", filename})
	shell.Run([]string{"dpkg-deb", "--build", "files", debname})
	if shell.Exists(debname) {
		log.Warn("build worked")
	} else {
		log.Warn("build failed")
		return false
	}
	return true
}