diff options
| -rw-r--r-- | addRepo.go | 18 | ||||
| -rw-r--r-- | common.go | 45 | ||||
| -rw-r--r-- | new.go | 77 | ||||
| -rw-r--r-- | repolist.go | 248 | ||||
| -rw-r--r-- | scan.go | 10 | ||||
| -rw-r--r-- | structs.go | 3 | ||||
| -rw-r--r-- | viewAutotypist.go | 29 | ||||
| -rw-r--r-- | watchdog.go | 4 |
8 files changed, 132 insertions, 302 deletions
@@ -45,11 +45,11 @@ func (r *Repo) Show() { } func (r *RepoList) AddRepo(path string, master string, devel string, user string) *Repo { - return addRepo(r.reposgrid, path, master, devel, user) + return r.addRepo(r.reposgrid, path, master, devel, user) } -func addRepo(grid *gui.Node, path string, master string, devel string, user string) *Repo { - _, ok := me.allrepos[path] +func (r *RepoList) addRepo(grid *gui.Node, path string, master string, devel string, user string) *Repo { + _, ok := r.allrepos[path] if ok { log.Info("addRepo() already had path", path) return nil @@ -89,14 +89,14 @@ func addRepo(grid *gui.Node, path string, master string, devel string, user stri }) newRepo.endBox.NewButton("show diff", func() { - me.reposwin.Disable() + r.reposbox.Disable() // newRepo.status.XtermNohup([]string{"git diff"}) newRepo.status.Xterm("git diff; bash") - me.reposwin.Enable() + r.reposbox.Enable() }) newRepo.endBox.NewButton("commit all", func() { - me.reposwin.Disable() + r.reposbox.Disable() // restore anything staged so everything can be reviewed newRepo.status.RunCmd([]string{"git", "restore", "--staged", "."}) newRepo.status.XtermWait("git diff") @@ -107,9 +107,9 @@ func addRepo(grid *gui.Node, path string, master string, devel string, user stri // commit was not done, restore diff newRepo.status.RunCmd([]string{"git", "restore", "--staged", "."}) } else { - newRepo.newScan() + newRepo.NewScan() } - me.reposwin.Enable() + r.reposbox.Enable() }) newRepo.hidden = false @@ -134,6 +134,6 @@ func addRepo(grid *gui.Node, path string, master string, devel string, user stri } grid.NextRow() - me.allrepos[path] = newRepo + r.allrepos[path] = newRepo return newRepo } @@ -9,16 +9,26 @@ func (r *Repo) String() string { return r.status.String() } +// full path "/home/username/go/src/go.wit.com/apps/autotypist" +func (r *Repo) Path() string { + return r.status.Path() +} + +// go path "go.wit.com/apps/autotypist" +func (r *Repo) GoPath() string { + return r.status.GoName() +} + func (r *RepoList) Hidden() bool { - return r.reposwin.Hidden() + return r.reposbox.Hidden() } func (r *RepoList) Show() { - r.reposwin.Show() + r.reposbox.Show() } func (r *RepoList) Hide() { - r.reposwin.Hide() + r.reposbox.Hide() } func (r *RepoList) AllRepos() []*Repo { @@ -38,8 +48,32 @@ func AllRepos() []*Repo { return all } +func (r *Repo) Build() bool { + return r.status.Build() +} + +func (r *Repo) Xterm(s string) { + r.status.Xterm(s) +} + +func (r *Repo) RepoType() string { + return r.status.RepoType() +} + +func (r *Repo) Status() string { + return r.dirtyLabel.String() +} + +func (r *Repo) MergeDevelToMaster() bool { + return r.status.MergeDevelToMaster() +} + +func (r *Repo) MergeUserToDevel() bool { + return r.status.MergeUserToDevel() +} + func (r *Repo) Scan() bool { - return r.newScan() + return r.NewScan() } func (r *Repo) Exists(s string) bool { @@ -69,6 +103,9 @@ func (r *Repo) IsPerfect() bool { if r.dirtyLabel.String() == "PERFECT" { return true } + if r.dirtyLabel.String() == "unchanged" { + return true + } return false } @@ -1,46 +1,55 @@ package repolist import ( - "go.wit.com/lib/gadgets" + "strings" + "go.wit.com/log" ) -// This creates a view of the repos -// you can only have one at this point -func AutotypistView() *RepoList { - if me != nil { - return me - } - me = new(RepoList) - me.allrepos = make(map[string]*Repo) - - me.reposwin = gadgets.RawBasicWindow("All git repositories in ~/go/src/") - me.reposwin.Make() - - me.reposbox = me.reposwin.Box().NewBox("bw vbox", false) - // me.reposwin.Draw() - me.reposwin.Custom = func() { - log.Warn("GOT HERE: main() gadgets.NewBasicWindow() close") - log.Warn("Should I do something special here?") +func RemoveFirstElement(slice []string) (string, []string) { + if len(slice) == 0 { + return "", slice // Return the original slice if it's empty } + return slice[0], slice[1:] // Return the slice without the first element +} - repoAllButtons(me.reposbox) - - me.reposgroup = me.reposbox.NewGroup("git repositories (configure in ~/.config/myrepolist)") - me.reposgrid = me.reposgroup.NewGrid("test", 0, 0) - - me.reposgrid.NewLabel("") // path goes here - - me.reposgrid.NewLabel("last tag").SetProgName("last tag") - - me.reposgrid.NewLabel("master version") - me.reposgrid.NewLabel("devel version") - me.reposgrid.NewLabel("user version") +// returns path, master branch name, devel branch name, user branch name +func splitLine(line string) (string, string, string, string) { + var path, master, devel, user string + parts := strings.Split(line, " ") + path, parts = RemoveFirstElement(parts) + master, parts = RemoveFirstElement(parts) + devel, parts = RemoveFirstElement(parts) + user, parts = RemoveFirstElement(parts) + // path, master, devel, user := strings.Split(line, " ") + return path, master, devel, user +} - me.reposgrid.NewLabel("Status") +func RepoType() { + for _, repo := range me.allrepos { + switch repo.status.RepoType() { + case "binary": + //log.Info("compile here. Show()") + repo.Show() + case "library": + //log.Info("library here. Hide()") + repo.Hide() + default: + log.Info("showApps() unknown. Show()") + repo.Hide() + } - me.reposgrid.NewLabel("Current Version").SetProgName("Current Version") - me.reposgrid.NextRow() + } +} - return me +/* +func myrepolist() []string { + homeDir, _ := os.UserHomeDir() + cfgfile := filepath.Join(homeDir, ".config/autotypist") + content, _ := ioutil.ReadFile(cfgfile) + out := string(content) + out = strings.TrimSpace(out) + lines := strings.Split(out, "\n") + return lines } +*/ diff --git a/repolist.go b/repolist.go deleted file mode 100644 index 2878c09..0000000 --- a/repolist.go +++ /dev/null @@ -1,248 +0,0 @@ -package repolist - -import ( - "io/ioutil" - "os" - "os/user" - "path/filepath" - "strings" - - "go.wit.com/gui" - "go.wit.com/lib/gadgets" - "go.wit.com/lib/gui/repostatus" - "go.wit.com/log" -) - -func RemoveFirstElement(slice []string) (string, []string) { - if len(slice) == 0 { - return "", slice // Return the original slice if it's empty - } - return slice[0], slice[1:] // Return the slice without the first element -} - -// returns path, master branch name, devel branch name, user branch name -func splitLine(line string) (string, string, string, string) { - var path, master, devel, user string - parts := strings.Split(line, " ") - path, parts = RemoveFirstElement(parts) - master, parts = RemoveFirstElement(parts) - devel, parts = RemoveFirstElement(parts) - user, parts = RemoveFirstElement(parts) - // path, master, devel, user := strings.Split(line, " ") - return path, master, devel, user -} - -func myrepolist() []string { - homeDir, _ := os.UserHomeDir() - cfgfile := filepath.Join(homeDir, ".config/autotypist") - content, _ := ioutil.ReadFile(cfgfile) - out := string(content) - out = strings.TrimSpace(out) - lines := strings.Split(out, "\n") - return lines -} - -// This creates a window -func RepolistWindow() *gadgets.BasicWindow { - me.reposwin = gadgets.RawBasicWindow("All git repositories in ~/go/src/") - me.reposwin.Make() - - me.reposbox = me.reposwin.Box().NewBox("bw vbox", false) - // me.reposwin.Draw() - me.reposwin.Custom = func() { - log.Warn("GOT HERE: main() gadgets.NewBasicWindow() close") - log.Warn("Should I do something special here?") - } - - repoAllButtons(me.reposbox) - - me.reposgroup = me.reposbox.NewGroup("git repositories (configure in ~/.config/myrepolist)") - me.reposgrid = me.reposgroup.NewGrid("test", 0, 0) - - me.reposgrid.NewLabel("") // path goes here - - me.reposgrid.NewLabel("last tag").SetProgName("last tag") - - me.reposgrid.NewLabel("master version") - me.reposgrid.NewLabel("devel version") - me.reposgrid.NewLabel("user version") - - me.reposgrid.NewLabel("Status") - - me.reposgrid.NewLabel("Current Version").SetProgName("Current Version") - me.reposgrid.NextRow() - - usr, _ := user.Current() - repos := myrepolist() - for _, line := range repos { - log.Verbose("repo =", line) - path, mbranch, dbranch, ubranch := splitLine(line) - if mbranch == "" { - mbranch = "master" - } - if dbranch == "" { - dbranch = "devel" - } - if ubranch == "" { - ubranch = usr.Username - } - newrepo := addRepo(me.reposgrid, path, mbranch, dbranch, ubranch) - if newrepo != nil { - // assume repos from ~/.config/autotypist file might be modified - newrepo.status.Writable() - } - me.reposgrid.NextRow() - } - - // if me.onlyMe { - // log.Info("not scanning everything") - // } else { - log.Info("scanning everything in ~/go/src") - for i, path := range repostatus.ListGitDirectories() { - // log.Info("addRepo()", i, path) - path = strings.TrimPrefix(path, me.goSrcPwd) - log.Info("addRepo()", i, path) - addRepo(me.reposgrid, path, "master", "devel", usr.Username) - me.reposgrid.NextRow() - } - // } - - return me.reposwin -} - -func showApps() { - for _, repo := range me.allrepos { - switch repo.status.RepoType() { - case "binary": - //log.Info("compile here. Show()") - repo.Show() - case "library": - //log.Info("library here. Hide()") - repo.Hide() - default: - log.Info("showApps() unknown. Show()") - repo.Hide() - } - - } -} - -func repoAllButtons(box *gui.Node) { - // reposbox.SetExpand(false) - group1 := box.NewGroup("Run on all repos:") - - hbox := group1.Box() - // hbox.Horizontal() - hbox.Vertical() - - box2 := hbox.Box().Vertical() - box2.NewButton("merge all user to devel", func() { - me.reposwin.Disable() - if !mergeAllUserToDevel() { - return - } - me.reposwin.Enable() - }) - - box2.NewButton("merge all devel to main", func() { - me.reposwin.Disable() - if !mergeAllDevelToMain() { - return - } - me.reposwin.Enable() - }) - - box2.NewButton("merge it all", func() { - me.reposwin.Disable() - if !mergeAllUserToDevel() { - return - } - if !mergeAllDevelToMain() { - return - } - me.reposwin.Enable() - }) - - box2.NewButton("test all builds", func() { - me.reposwin.Disable() - defer me.reposwin.Enable() - showApps() - for _, repo := range me.allrepos { - if repo.Hidden() { - // log.Info("skip hidden", repo.String()) - } else { - log.Info("try to build", repo.String()) - if repo.status.Build() { - log.Info("build worked", repo.String()) - } else { - log.Info("build failed", repo.String()) - go repo.status.Xterm("bash") - return - } - } - } - log.Info("") - log.Info("every build worked !!!") - log.Info("") - }) -} - -func mergeAllDevelToMain() bool { - log.Info("merge all here") - for _, repo := range me.allrepos { - if repo.status.ReadOnly() { - log.Info("skipping readonly", repo.String(), repo.dirtyLabel.String()) - continue - } - if repo.dirtyLabel.String() != "merge to main" { - log.Info("skipping. not merge to main", repo.String(), repo.dirtyLabel.String()) - continue - } - if repo.status.CheckDirty() { - log.Info("skipping dirty", repo.String(), repo.dirtyLabel.String()) - continue - } - log.Info("found", repo.String(), repo.dirtyLabel.String()) - repo.newScan() - if repo.status.MergeDevelToMaster() { - log.Warn("THINGS SEEM OK fullAutomation() returned true.") - } else { - log.Warn("last repo:", repo.status.Path()) - log.Warn("THINGS FAILED fullAutomation() returned false") - return false - } - repo.newScan() - } - log.Warn("EVERYTHING WORKED") - return true -} - -func mergeAllUserToDevel() bool { - log.Info("merge all here") - for _, repo := range me.allrepos { - if repo.status.ReadOnly() { - log.Info("skipping readonly", repo.String(), repo.dirtyLabel.String()) - continue - } - if repo.dirtyLabel.String() != "merge to devel" { - log.Info("skipping. not merge to devel", repo.String(), repo.dirtyLabel.String()) - continue - } - if repo.status.CheckDirty() { - log.Info("skipping dirty", repo.String(), repo.dirtyLabel.String()) - continue - } - log.Info("found", repo.String(), repo.dirtyLabel.String()) - repo.newScan() - if repo.status.MergeUserToDevel() { - log.Warn("THINGS SEEM OK fullAutomation() returned true.") - } else { - log.Warn("last repo:", repo.status.Path()) - log.Warn("THINGS FAILED fullAutomation() returned false") - return false - } - repo.newScan() - } - log.Warn("EVERYTHING WORKED") - return true -} @@ -8,12 +8,16 @@ import ( "go.wit.com/log" ) -func ScanRepositories() (int, string) { +func (r *RepoList) SetAutoScan(b bool) { + me.autoScan = b +} + +func (r *RepoList) ScanRepositories() (int, string) { var i int t := timeFunction(func() { for _, repo := range me.allrepos { i += 1 - repo.newScan() + repo.NewScan() } }) s := fmt.Sprint(t) @@ -21,7 +25,7 @@ func ScanRepositories() (int, string) { return i, s } -func (r *Repo) newScan() bool { +func (r *Repo) NewScan() bool { if r.status == nil { log.Warn("repo.status = nil. not initialized for some reason") return false @@ -2,7 +2,6 @@ package repolist import ( "go.wit.com/gui" - "go.wit.com/lib/gadgets" "go.wit.com/lib/gui/repostatus" ) @@ -24,7 +23,7 @@ type RepoList struct { autoScan bool allrepos map[string]*Repo - reposwin *gadgets.BasicWindow + // reposwin *gadgets.BasicWindow reposbox *gui.Node reposgrid *gui.Node reposgroup *gui.Node diff --git a/viewAutotypist.go b/viewAutotypist.go new file mode 100644 index 0000000..9753bce --- /dev/null +++ b/viewAutotypist.go @@ -0,0 +1,29 @@ +package repolist + +import "go.wit.com/gui" + +// This creates a view of the repos +// you can only have one at this point +func AutotypistView(parent *gui.Node) *RepoList { + if me != nil { + return me + } + me = new(RepoList) + me.allrepos = make(map[string]*Repo) + + // me.reposbox = gui.RawBox() + me.reposbox = parent + + me.reposgroup = me.reposbox.NewGroup("git repositories (configure in ~/.config/myrepolist)") + me.reposgrid = me.reposgroup.NewGrid("test", 0, 0) + + me.reposgrid.NewLabel("") // path goes here + me.reposgrid.NewLabel("last tag").SetProgName("last tag") + me.reposgrid.NewLabel("master version") + me.reposgrid.NewLabel("devel version") + me.reposgrid.NewLabel("user version") + me.reposgrid.NewLabel("Status") + me.reposgrid.NewLabel("Current Version").SetProgName("Current Version") + me.reposgrid.NextRow() + return me +} diff --git a/watchdog.go b/watchdog.go index 949d455..e1648c7 100644 --- a/watchdog.go +++ b/watchdog.go @@ -21,7 +21,7 @@ import ( // the delay, then the scan will run right away, but if // you check the checkbox twice in 5 seconds, it won't // rerun until the delay again -func Watchdog() { +func (r *RepoList) Watchdog() { var delay int = 99 var i int = delay MyTicker(1*time.Second, "newScan()", func() { @@ -41,7 +41,7 @@ func Watchdog() { return } i = 0 - ScanRepositories() + r.ScanRepositories() }) } |
