common repolist code
This commit is contained in:
parent
0bc14b6145
commit
e0bda97e5f
|
@ -3,35 +3,14 @@ package main
|
|||
// this initializes the repos
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/user"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"go.wit.com/lib/gui/repolist"
|
||||
"go.wit.com/lib/gui/repostatus"
|
||||
"go.wit.com/log"
|
||||
)
|
||||
|
||||
func (r *repoWindow) initRepoList() {
|
||||
usr, _ := user.Current()
|
||||
|
||||
repos := parsecfg("~/.config/autotypist")
|
||||
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
|
||||
}
|
||||
r.View.AddRepo(path, mbranch, dbranch, ubranch)
|
||||
}
|
||||
r.View.InitRepoList("~/.config/autotypist")
|
||||
|
||||
if args.OnlyMe {
|
||||
log.Info("not scanning everything")
|
||||
|
@ -42,29 +21,7 @@ func (r *repoWindow) initRepoList() {
|
|||
path = strings.TrimPrefix(path, me.goSrcPwd.String())
|
||||
path = strings.Trim(path, "/")
|
||||
log.Info("addRepo()", i, path)
|
||||
r.View.AddRepo(path, "master", "devel", usr.Username)
|
||||
r.View.NewRepo(path)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func parsecfg(f string) []string {
|
||||
homeDir, _ := os.UserHomeDir()
|
||||
cfgfile := filepath.Join(homeDir, f)
|
||||
content, _ := ioutil.ReadFile(cfgfile)
|
||||
out := string(content)
|
||||
out = strings.TrimSpace(out)
|
||||
lines := strings.Split(out, "\n")
|
||||
return lines
|
||||
}
|
||||
|
||||
// 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 = repolist.RemoveFirstElement(parts)
|
||||
master, parts = repolist.RemoveFirstElement(parts)
|
||||
devel, parts = repolist.RemoveFirstElement(parts)
|
||||
user, parts = repolist.RemoveFirstElement(parts)
|
||||
// path, master, devel, user := strings.Split(line, " ")
|
||||
return path, master, devel, user
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue