Compare commits
5 Commits
Author | SHA1 | Date |
---|---|---|
|
364d53efcd | |
|
c4d4a25800 | |
|
8d55a8316a | |
|
efba612ad6 | |
|
316c1b8cc2 |
2
Makefile
2
Makefile
|
@ -1,5 +1,5 @@
|
||||||
all:
|
all:
|
||||||
@GO111MODULE=off go build
|
@GO111MODULE=off go vet
|
||||||
@echo this is a go library with buildable code
|
@echo this is a go library with buildable code
|
||||||
|
|
||||||
goimports:
|
goimports:
|
||||||
|
|
|
@ -1,55 +0,0 @@
|
||||||
package gowit
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"go.wit.com/lib/gui/repolist"
|
|
||||||
"go.wit.com/log"
|
|
||||||
)
|
|
||||||
|
|
||||||
func DumpVersions(view *repolist.RepoList) {
|
|
||||||
f, _ := os.OpenFile("/tmp/go.wit.com.versions", os.O_WRONLY|os.O_CREATE, 0600)
|
|
||||||
defer f.Close()
|
|
||||||
for _, sec := range allsections {
|
|
||||||
for _, wrepo := range sec.witRepos {
|
|
||||||
var r *repolist.RepoRow
|
|
||||||
r = view.FindRepo(wrepo.path.String())
|
|
||||||
if r == nil {
|
|
||||||
log.Info("repo not scanned for some reason", wrepo.path.String())
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
lastTag := r.LastTag()
|
|
||||||
_, out := r.Status.RunCmd([]string{"git", "log", "-1", "--format=%at", lastTag})
|
|
||||||
out = strings.TrimSpace(out)
|
|
||||||
|
|
||||||
// Convert the string to an integer
|
|
||||||
gitTagTimestampInt, err := strconv.ParseInt(out, 10, 64)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("Error converting timestamp:", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parse the Unix timestamp into a time.Time object
|
|
||||||
gitTagDate := time.Unix(gitTagTimestampInt, 0)
|
|
||||||
|
|
||||||
// Get the current time
|
|
||||||
currentTime := time.Now()
|
|
||||||
|
|
||||||
// Calculate the duration between the git tag date and the current time
|
|
||||||
duration := currentTime.Sub(gitTagDate)
|
|
||||||
|
|
||||||
// s := fmt.Sprint(duration)
|
|
||||||
// fmt.Println("Duration since the git tag date:", s)
|
|
||||||
|
|
||||||
// fmt.Println("Default formatting:", duration.String())
|
|
||||||
// fmt.Println("Custom formatting:", formatDuration(duration))
|
|
||||||
log.Warn("found:", wrepo.path.String(), lastTag, out, formatDuration(duration))
|
|
||||||
fmt.Fprintln(f, wrepo.path.String(), lastTag, out)
|
|
||||||
//wrepo.path.Show()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
328
listWindow.go
328
listWindow.go
|
@ -1,328 +0,0 @@
|
||||||
package gowit
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"go.wit.com/gui"
|
|
||||||
"go.wit.com/log"
|
|
||||||
|
|
||||||
"go.wit.com/lib/gadgets"
|
|
||||||
"go.wit.com/lib/gui/repostatus"
|
|
||||||
"go.wit.com/lib/gui/repolist"
|
|
||||||
"go.wit.com/lib/gui/shell"
|
|
||||||
)
|
|
||||||
|
|
||||||
var lw *gadgets.BasicWindow
|
|
||||||
|
|
||||||
var allsections []*section
|
|
||||||
|
|
||||||
type witRepo struct {
|
|
||||||
sec *section
|
|
||||||
path *gui.Node
|
|
||||||
downloadB *gui.Node
|
|
||||||
}
|
|
||||||
|
|
||||||
type section struct {
|
|
||||||
name string
|
|
||||||
hidden bool
|
|
||||||
|
|
||||||
parent *gui.Node
|
|
||||||
box *gui.Node
|
|
||||||
group *gui.Node
|
|
||||||
grid *gui.Node // where the repos are listed
|
|
||||||
hideCB *gui.Node
|
|
||||||
downloadAllB *gui.Node
|
|
||||||
witRepos []*witRepo
|
|
||||||
}
|
|
||||||
|
|
||||||
func CheckRegistered(rs *repostatus.RepoStatus) (bool, string) {
|
|
||||||
var found bool = false
|
|
||||||
var source string
|
|
||||||
url := "https://" + rs.String()
|
|
||||||
lines := dumpURL(url)
|
|
||||||
for _, line := range lines {
|
|
||||||
// log.Info("HTTP:", i, line)
|
|
||||||
if strings.Contains(line, "\"go-import\"") {
|
|
||||||
line = strings.TrimSuffix(line, "\">")
|
|
||||||
parts := strings.Split(line, " ")
|
|
||||||
source = parts[len(parts)-1]
|
|
||||||
// log.Verbose("FOUND IMPORT:", i, source)
|
|
||||||
found = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return found, source
|
|
||||||
}
|
|
||||||
|
|
||||||
func myrepolist() []string {
|
|
||||||
homeDir, _ := os.UserHomeDir()
|
|
||||||
cfgfile := filepath.Join(homeDir, ".config/myrepolist")
|
|
||||||
content, _ := ioutil.ReadFile(cfgfile)
|
|
||||||
out := string(content)
|
|
||||||
out = strings.TrimSpace(out)
|
|
||||||
lines := strings.Split(out, "\n")
|
|
||||||
return lines
|
|
||||||
}
|
|
||||||
|
|
||||||
func ListWindow(view *repolist.RepoList) *gadgets.BasicWindow {
|
|
||||||
if lw != nil {
|
|
||||||
if lw.Hidden() {
|
|
||||||
lw.Show()
|
|
||||||
} else {
|
|
||||||
lw.Hide()
|
|
||||||
}
|
|
||||||
return lw
|
|
||||||
}
|
|
||||||
lw = gadgets.RawBasicWindow("go.wit.com repositories")
|
|
||||||
lw.Custom = func() {
|
|
||||||
log.Warn("got to close")
|
|
||||||
}
|
|
||||||
lw.Make()
|
|
||||||
box := lw.Box()
|
|
||||||
group := box.NewGroup("list")
|
|
||||||
group.NewButton("make new go version list", func() {
|
|
||||||
DumpVersions(view)
|
|
||||||
})
|
|
||||||
|
|
||||||
var lines []string
|
|
||||||
var currents *section
|
|
||||||
|
|
||||||
currents = NewSection(group, "local (~/.config/myrepolist)")
|
|
||||||
for i, line := range myrepolist() {
|
|
||||||
line = strings.TrimSpace(line)
|
|
||||||
if line == "" {
|
|
||||||
// skip blank lines
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if strings.HasPrefix(line, "#") {
|
|
||||||
// skip comment lines
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
parts := strings.Split(line, " ")
|
|
||||||
log.Info("adding:", i, parts)
|
|
||||||
currents.add(view, parts[0])
|
|
||||||
}
|
|
||||||
|
|
||||||
lines = dumpURL("https://go.wit.com/list")
|
|
||||||
for i, line := range lines {
|
|
||||||
if line == "" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if line[0] == '#' {
|
|
||||||
currents = NewSection(group, line)
|
|
||||||
log.Warn("new group:", line)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
log.Warn(i, line)
|
|
||||||
parts := strings.Split(line, " ")
|
|
||||||
if currents != nil {
|
|
||||||
currents.add(view, parts[0])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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" {
|
|
||||||
// leave expanded
|
|
||||||
} else if parts[0] == "local" {
|
|
||||||
// leave expanded
|
|
||||||
} else {
|
|
||||||
sec.Hide()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return lw
|
|
||||||
}
|
|
||||||
|
|
||||||
func downloadRepo(path string) bool {
|
|
||||||
log.Info("downloading", path, "here")
|
|
||||||
os.Setenv("GO111MODULE", "off")
|
|
||||||
|
|
||||||
// goSrcDir := me.goSrcPwd.String()
|
|
||||||
goSrcDir := "/home/jcarr/go/src"
|
|
||||||
err, ok, output := shell.RunCmd(goSrcDir, []string{"go", "get", "-v", path})
|
|
||||||
if !ok {
|
|
||||||
log.Info("go get failed")
|
|
||||||
log.Info("err =", err)
|
|
||||||
log.Info("output =", output)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
fullpath := filepath.Join(goSrcDir, path)
|
|
||||||
err, ok, output = shell.RunCmd(fullpath, []string{"go", "get", "-v", "-u", "."})
|
|
||||||
if !ok {
|
|
||||||
log.Info("go get depends failed")
|
|
||||||
log.Info("err =", err)
|
|
||||||
log.Info("output =", output)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
if me.autoDryRun.Checked() {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
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())
|
|
||||||
r.downloadB.Disable()
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *section) add(view *repolist.RepoList, path string) {
|
|
||||||
if s == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
tmp := new(witRepo)
|
|
||||||
tmp.sec = s
|
|
||||||
tmp.path = s.grid.NewLabel(path)
|
|
||||||
tmp.downloadB = s.grid.NewButton("download", func() {
|
|
||||||
lw.Disable()
|
|
||||||
tmp.doDownload()
|
|
||||||
lw.Enable()
|
|
||||||
})
|
|
||||||
repo := view.FindRepo(path)
|
|
||||||
if repo != nil {
|
|
||||||
log.Verbose("repo is already downloaded", path)
|
|
||||||
tmp.downloadB.SetLabel("downloaded")
|
|
||||||
tmp.downloadB.Disable()
|
|
||||||
s.grid.NewButton("Configure", func() {
|
|
||||||
log.Log(WIT, "todo: open the repo window here")
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
s.grid.NextRow()
|
|
||||||
s.witRepos = append(s.witRepos, tmp)
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewSection(parent *gui.Node, desc string) *section {
|
|
||||||
news := new(section)
|
|
||||||
news.name = desc
|
|
||||||
news.parent = parent
|
|
||||||
news.box = news.parent.NewBox("bw vbox", true)
|
|
||||||
news.group = news.box.NewGroup(desc)
|
|
||||||
news.hideCB = news.box.NewCheckbox("hide")
|
|
||||||
news.hideCB.Custom = func() {
|
|
||||||
news.toggle()
|
|
||||||
}
|
|
||||||
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()
|
|
||||||
})
|
|
||||||
news.grid = news.parent.NewGrid("sections", 0, 0)
|
|
||||||
allsections = append(allsections, news)
|
|
||||||
return news
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *section) toggle() {
|
|
||||||
log.Warn(s.name)
|
|
||||||
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)
|
|
||||||
for i, wrepo := range s.witRepos {
|
|
||||||
log.Warn(i, wrepo.path.String())
|
|
||||||
wrepo.path.Hide()
|
|
||||||
wrepo.downloadB.Hide()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
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")
|
|
||||||
}
|
|
||||||
|
|
||||||
func formatDuration(d time.Duration) string {
|
|
||||||
seconds := int(d.Seconds()) % 60
|
|
||||||
minutes := int(d.Minutes()) % 60
|
|
||||||
hours := int(d.Hours()) % 24
|
|
||||||
days := int(d.Hours()) / 24
|
|
||||||
|
|
||||||
result := ""
|
|
||||||
if days > 0 {
|
|
||||||
result += fmt.Sprintf("%dd ", days)
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
if hours > 0 {
|
|
||||||
result += fmt.Sprintf("%dh ", hours)
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
if minutes > 0 {
|
|
||||||
result += fmt.Sprintf("%dm ", minutes)
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
if seconds > 0 {
|
|
||||||
result += fmt.Sprintf("%ds", seconds)
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
|
@ -4,10 +4,10 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"os/user"
|
"os/user"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"go.wit.com/lib/gui/shell"
|
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ func Register(gopath string, giturl string) bool {
|
||||||
req.Header.Set("giturl", giturl)
|
req.Header.Set("giturl", giturl)
|
||||||
usr, _ := user.Current()
|
usr, _ := user.Current()
|
||||||
req.Header.Set("author", usr.Username)
|
req.Header.Set("author", usr.Username)
|
||||||
hostname := shell.RunCapture("hostname -f")
|
hostname, _ := os.Hostname()
|
||||||
req.Header.Set("hostname", hostname)
|
req.Header.Set("hostname", hostname)
|
||||||
|
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
|
|
Loading…
Reference in New Issue