summaryrefslogtreecommitdiff
path: root/globalBuildOptions.go
blob: bcbdf72d9c602ccd37f5bf2076f52d1a3e21aaf7 (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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
package main

import (
	"os"
	"os/user"
	"path/filepath"

	"go.wit.com/log"

	"go.wit.com/gui"
	"go.wit.com/lib/gadgets"
	"go.wit.com/lib/gui/repolist"
	"go.wit.com/lib/gui/repostatus"
)

func doesExist(path string) bool {
	if _, err := os.Stat(path); err != nil {
		if os.IsNotExist(err) {
			return false
		}
	}
	return true
}

// only errors on bad errors
func quickCmd(fullpath string, cmd []string) bool {
	var err error
	var b bool
	var output string

	//	if me.autoWorkingPwd.String() != fullpath {
	//		me.autoWorkingPwd.SetValue(fullpath)
	//	}

	if me.autoDryRun.Checked() {
		log.Warn("RUN --dry-run", fullpath, cmd)
		return false
	} else {
		log.Warn("RUN:", fullpath, cmd)
	}

	err, b, output = repostatus.RunCmd(fullpath, cmd)
	if err != nil {
		log.Warn("cmd =", cmd)
		log.Warn("err =", err)
		log.Warn("b =", b)
		log.Warn("output =", string(output))
		return false
	} else if !b {
		log.Warn("b =", b)
		log.Warn("output =", string(output))
		return true
	}
	log.Warn("output = ", string(output))
	return true
}

func globalBuildOptions(vbox *gui.Node) {
	group1 := vbox.NewGroup("Global Build Options")
	grid := group1.NewGrid("buildOptions", 0, 0)

	// me.autoWorkingPwd = gadgets.NewOneLiner(grid, "working directory (pwd)")
	me.userHomePwd = gadgets.NewOneLiner(grid, "user home")
	grid.NextRow()
	me.goSrcPwd = gadgets.NewOneLiner(grid, "go src home")
	grid.NextRow()

	usr, _ := user.Current()
	homeDir, err := os.UserHomeDir()
	if err != nil {
		log.Warn("Error getting home directory:", err)
		homeDir = "/home/autotypist"
	}
	me.userHomePwd.SetText(homeDir)
	srcDir := filepath.Join(homeDir, "go/src")
	me.goSrcPwd.SetText(srcDir)

	// select the branch you want to test, build and develop against
	// this lets you select your user branch, but, when you are happy
	// you can merge everything into the devel branch and make sure it actually
	// works. Then, when that is good, merge and version everything in master
	me.setBranchB = grid.NewButton("set current branch to:", func() {
		targetName := me.newBranch.String()
		log.Warn("setting all branches to", targetName)
		for _, repo := range repolist.AllRepos() {
			repo.Status.CheckoutBranch(targetName)
			repo.Scan()
		}
	})
	me.newBranch = grid.NewCombobox()
	me.newBranch.AddText("master")
	me.newBranch.AddText("devel")
	me.newBranch.AddText(usr.Username)
	me.newBranch.SetText(usr.Username)

	// checking this will automatically make the branches off of devel
	me.autoCreateBranches = grid.NewCheckbox("create if missing").SetChecked(true)
	grid.NextRow()
}

// this code isn't ready yet
/*
	s.gitPullB = grid.NewButton("git pull", func() {
		me.Disable()
		defer me.Enable()
		for _, repo := range repolist.AllRepos() {
			// gitcmd := []string{"git", "fetch", "origin"}
			gitcmd := []string{"git", "pull"}
			err, output := repo.RunCmd(gitcmd)
			log.Info("output =", output)
			if err == nil {
				log.Info("git fetch worked", repo.Name())
			} else {
				log.Info("git fetch failed", repo.Name())
				return
			}
		}
		gitPullB.SetText("GOOD")
		// update the stats
		// s.Update()
	})

	s.gitPushB = grid.NewButton("git push", func() {
		me.Disable()
		defer me.Enable()
		for _, repo := range repolist.AllRepos() {
			gitcmd := []string{"git", "push"}
			err, output := repo.RunCmd(gitcmd)
			log.Info("output =", output)
			if err == nil {
				log.Info("git push worked", repo.Name())
			} else {
				log.Info("git push failed", repo.Name())
				return
			}
		}
		s.gitPushB.SetText("GOOD")
		// update the stats
		s.Update()
	})

	s.checkB = s.grid.NewButton("Check repos are working", func() {
			me.Disable()
			defer me.Enable()
			for _, repo := range repolist.AllRepos() {
				if repo.GitURL() != "" {
					log.Info("repo already checked. do they match?")
					log.Info("go.wit.com =", repo.GoURL())
					log.Info("localurl   =", repo.Path())
				} else {
					ok, giturl := gowit.CheckRegistered(repo)
					if ok {
						log.Info("is url correct?", repo.Path(), "vs", giturl)
						repo.giturl = giturl
						if giturl != repo.Path() {
							log.Info("repo check failed", repo.String())
							s.unknownOL.SetText(repo.String())
							s.unknownOL.Show()
							s.unknownSubmitB.Show()
							return
						}
					} else {
						log.Info("repo check failed", repo.String())
						repo.giturl = "look in .git/config"
						s.unknownOL.SetText(repo.String())
						s.unknownOL.Show()
						s.unknownSubmitB.Show()
						return
					}
				}
			}
			s.checkB.SetText("GOOD")
	})
*/