2024-01-20 16:09:15 -06:00
|
|
|
// This is a simple example
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"net/http"
|
2024-01-25 13:09:33 -06:00
|
|
|
"os"
|
2024-01-26 14:21:05 -06:00
|
|
|
"path/filepath"
|
2024-01-20 16:09:15 -06:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
"go.wit.com/gui"
|
|
|
|
"go.wit.com/log"
|
|
|
|
|
|
|
|
"go.wit.com/lib/gadgets"
|
2024-01-26 13:45:27 -06:00
|
|
|
"go.wit.com/lib/gui/repostatus"
|
2024-01-20 16:09:15 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
var lw *gadgets.BasicWindow
|
2024-01-27 09:05:14 -06:00
|
|
|
|
2024-01-20 16:09:15 -06:00
|
|
|
var allsections []*section
|
|
|
|
|
2024-01-25 13:09:33 -06:00
|
|
|
type witRepo struct {
|
|
|
|
sec *section
|
|
|
|
path *gui.Node
|
|
|
|
downloadB *gui.Node
|
|
|
|
}
|
|
|
|
|
2024-01-20 16:09:15 -06:00
|
|
|
type section struct {
|
2024-01-26 13:45:27 -06:00
|
|
|
name string
|
|
|
|
hidden bool
|
|
|
|
|
2024-01-29 09:38:32 -06:00
|
|
|
parent *gui.Node
|
|
|
|
box *gui.Node
|
|
|
|
group *gui.Node
|
|
|
|
grid *gui.Node // where the repos are listed
|
|
|
|
hideCB *gui.Node
|
2024-01-27 15:09:51 -06:00
|
|
|
downloadAllB *gui.Node
|
2024-01-29 09:38:32 -06:00
|
|
|
witRepos []*witRepo
|
2024-01-20 16:09:15 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func listWindow() {
|
|
|
|
if lw != nil {
|
|
|
|
lw.Toggle()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
lw = gadgets.NewBasicWindow(me.myGui, "go.wit.com repositories")
|
|
|
|
lw.Custom = func() {
|
|
|
|
log.Warn("got to close")
|
|
|
|
}
|
|
|
|
|
|
|
|
lw.Make()
|
|
|
|
lw.StandardClose()
|
|
|
|
lw.Draw()
|
|
|
|
box := lw.Box()
|
|
|
|
group := box.NewGroup("list")
|
|
|
|
group.NewButton("blah", func() {})
|
|
|
|
|
|
|
|
var lines []string
|
|
|
|
var curs *section
|
|
|
|
|
|
|
|
lines = dumpURL("https://go.wit.com/list")
|
|
|
|
for i, line := range lines {
|
|
|
|
if line == "" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if line[0] == '#' {
|
|
|
|
curs = NewSection(group, line)
|
|
|
|
log.Warn("new group:", line)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
log.Warn(i, line)
|
|
|
|
parts := strings.Split(line, " ")
|
|
|
|
if curs != nil {
|
|
|
|
curs.add(parts[0])
|
|
|
|
}
|
|
|
|
}
|
2024-01-26 13:45:27 -06:00
|
|
|
for i, sec := range allsections {
|
|
|
|
log.Info("section name:", sec.name, "hidden:", sec.hidden, i)
|
|
|
|
parts := strings.Split(sec.name, " ")
|
|
|
|
if len(parts) > 1 {
|
|
|
|
if parts[1] != "Applications" {
|
|
|
|
sec.Hide()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// lw.Toggle()
|
2024-01-20 16:09:15 -06:00
|
|
|
}
|
|
|
|
|
2024-01-27 14:40:17 -06:00
|
|
|
func downloadRepo(path string) bool {
|
|
|
|
log.Info("downloading", path, "here")
|
|
|
|
os.Setenv("GO111MODULE", "off")
|
|
|
|
|
|
|
|
goSrcDir := me.goSrcPwd.String()
|
2024-01-29 09:38:32 -06:00
|
|
|
if !quickCmd(goSrcDir, []string{"go", "get", "-v", path}) {
|
2024-01-27 14:40:17 -06:00
|
|
|
log.Info("go get failed")
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
fullpath := filepath.Join(goSrcDir, path)
|
2024-01-29 09:38:32 -06:00
|
|
|
if !quickCmd(fullpath, []string{"go", "get", "-v", "-u", "."}) {
|
2024-01-27 14:40:17 -06:00
|
|
|
log.Info("go get depends failed")
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if me.autoDryRun.Checked() {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2024-01-27 15:09:51 -06:00
|
|
|
func (r *witRepo) doDownload() bool {
|
|
|
|
if me.autoDryRun.Checked() {
|
|
|
|
r.downloadB.SetLabel("uncheck --dry-run")
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if r.downloadB.String() == "downloaded" {
|
|
|
|
log.Info("skipping already downloaded", r.path.String())
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
if downloadRepo(r.path.String()) {
|
|
|
|
log.Info("download", r.path.String(), "worked")
|
|
|
|
r.downloadB.SetLabel("downloaded")
|
|
|
|
r.downloadB.Disable()
|
|
|
|
} else {
|
|
|
|
r.downloadB.SetLabel("failed")
|
|
|
|
log.Info("download", r.path.String(), "failed")
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2024-01-20 16:09:15 -06:00
|
|
|
func (s *section) add(path string) {
|
|
|
|
if s == nil {
|
|
|
|
return
|
|
|
|
}
|
2024-01-25 13:09:33 -06:00
|
|
|
tmp := new(witRepo)
|
|
|
|
tmp.sec = s
|
|
|
|
tmp.path = s.grid.NewLabel(path)
|
|
|
|
tmp.downloadB = s.grid.NewButton("download", func() {
|
|
|
|
lw.Disable()
|
2024-01-27 15:09:51 -06:00
|
|
|
tmp.doDownload()
|
2024-01-25 13:09:33 -06:00
|
|
|
lw.Enable()
|
|
|
|
})
|
2024-01-26 13:45:27 -06:00
|
|
|
if repostatus.VerifyLocalGoRepo(path) {
|
|
|
|
log.Verbose("newRepo actually exists", path)
|
|
|
|
tmp.downloadB.SetLabel("downloaded")
|
|
|
|
tmp.downloadB.Disable()
|
|
|
|
}
|
2024-01-25 13:09:33 -06:00
|
|
|
|
|
|
|
s.witRepos = append(s.witRepos, tmp)
|
2024-01-20 16:09:15 -06:00
|
|
|
}
|
|
|
|
|
2024-01-26 13:45:27 -06:00
|
|
|
func NewSection(parent *gui.Node, desc string) *section {
|
2024-01-20 16:09:15 -06:00
|
|
|
news := new(section)
|
2024-01-26 13:45:27 -06:00
|
|
|
news.name = desc
|
2024-01-20 16:09:15 -06:00
|
|
|
news.parent = parent
|
|
|
|
news.box = news.parent.NewBox("bw vbox", true)
|
2024-01-26 13:45:27 -06:00
|
|
|
news.group = news.box.NewGroup(desc)
|
2024-01-25 13:09:33 -06:00
|
|
|
news.hideCB = news.box.NewCheckbox("hide")
|
|
|
|
news.hideCB.Custom = func() {
|
2024-01-20 16:09:15 -06:00
|
|
|
news.toggle()
|
|
|
|
}
|
2024-01-27 15:09:51 -06:00
|
|
|
news.downloadAllB = news.box.NewButton("download all", func() {
|
|
|
|
lw.Disable()
|
|
|
|
log.Warn("Download all here")
|
|
|
|
for i, wrepo := range news.witRepos {
|
|
|
|
log.Warn("download:", i, wrepo.path.String())
|
|
|
|
wrepo.doDownload()
|
|
|
|
//wrepo.path.Show()
|
|
|
|
//wrepo.downloadB.Show()
|
|
|
|
}
|
|
|
|
lw.Enable()
|
|
|
|
})
|
2024-01-25 13:09:33 -06:00
|
|
|
news.grid = news.parent.NewGrid("sections", 2, 1)
|
2024-01-20 16:09:15 -06:00
|
|
|
allsections = append(allsections, news)
|
|
|
|
return news
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *section) toggle() {
|
|
|
|
log.Warn(s.name)
|
2024-01-26 13:45:27 -06:00
|
|
|
if s.hidden {
|
|
|
|
s.hidden = false
|
|
|
|
for i, wrepo := range s.witRepos {
|
|
|
|
log.Warn(i, wrepo.path.String())
|
|
|
|
wrepo.path.Show()
|
|
|
|
wrepo.downloadB.Show()
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
s.Hide()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *section) Hide() {
|
|
|
|
s.hidden = true
|
|
|
|
s.hideCB.SetChecked(true)
|
2024-01-25 13:09:33 -06:00
|
|
|
for i, wrepo := range s.witRepos {
|
|
|
|
log.Warn(i, wrepo.path.String())
|
|
|
|
wrepo.path.Hide()
|
|
|
|
wrepo.downloadB.Hide()
|
2024-01-20 16:09:15 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
func dumpURL(url string) string {
|
|
|
|
resp, err := http.Get(url)
|
|
|
|
if err != nil {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
return resp.Body.String()
|
|
|
|
|
|
|
|
_, err = io.Copy(os.Stdout, resp.Body)
|
|
|
|
if err != nil {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
func dumpURL(url string) []string {
|
|
|
|
resp, err := http.Get(url)
|
|
|
|
if err != nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
bodyBytes, err := ioutil.ReadAll(resp.Body)
|
|
|
|
if err != nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return strings.Split(string(bodyBytes), "\n")
|
|
|
|
}
|