repolist/configfile.go

198 lines
4.4 KiB
Go
Raw Normal View History

2024-02-22 21:12:35 -06:00
package repolist
import (
2024-02-29 19:51:56 -06:00
"errors"
2024-02-22 21:12:35 -06:00
2024-02-29 19:51:56 -06:00
"go.wit.com/lib/gui/repostatus"
2024-03-01 21:35:42 -06:00
"go.wit.com/log"
2024-02-22 21:12:35 -06:00
)
/*
2024-02-22 21:12:35 -06:00
func (v *RepoList) InitRepoList(cfgfile string) {
2024-03-01 18:03:17 -06:00
v.cfgfile = cfgfile
2024-02-22 21:12:35 -06:00
lines := parsecfg(cfgfile)
for _, line := range lines {
2024-02-23 11:01:23 -06:00
var repo *RepoRow
var err error
2024-02-22 21:12:35 -06:00
line = strings.TrimSpace(line)
2024-02-23 11:01:23 -06:00
if line == "" {
// skip empty lines
continue
}
2024-02-22 21:12:35 -06:00
if strings.HasPrefix(line, "#") {
2024-02-23 11:01:23 -06:00
// skip config file comment lines
2024-02-22 21:12:35 -06:00
continue
}
parts := strings.Split(line, " ")
2024-02-23 11:01:23 -06:00
var private bool = false
var readonly bool = false
var userdir bool = false
if len(parts) > 1 {
repodir := parts[0]
for _, s := range parts[1:] {
option := strings.Split(s, "=")
if len(option) != 2 {
log.Log(REPOWARN, "can not parse cfgfile line:", line)
continue
}
switch option[0] {
case "private":
if option[1] == "true" {
log.Log(REPOWARN, repodir, "setting private to true")
private = true
} else {
log.Log(REPOWARN, repodir, "setting private to false")
private = false
}
case "readonly":
if option[1] == "true" {
log.Log(REPOWARN, repodir, "setting ReadOnly to true")
2024-02-23 11:11:26 -06:00
readonly = true
2024-02-23 11:01:23 -06:00
} else {
log.Log(REPOWARN, repodir, "setting ReadOnly to false")
2024-02-23 11:11:26 -06:00
readonly = false
2024-02-23 11:01:23 -06:00
}
case "userdir":
if option[1] == "true" {
log.Log(REPOWARN, repodir, "setting this directory as Writable()")
userdir = true
} else {
userdir = false
}
default:
log.Log(REPOWARN, "unknown config file option", s)
}
}
}
if userdir {
log.Log(REPOWARN, "add this as a writable dir", line)
continue
}
2024-02-22 21:12:35 -06:00
if len(parts) > 0 {
path := parts[0]
2024-02-23 11:01:23 -06:00
repo, err = v.NewRepo(path)
}
if err != nil {
log.Log(REPOWARN, line, "repo could not be added", err)
continue
}
if repo == nil {
// there is not a new repo
continue
}
if private {
repo.Status.SetPrivate(true)
} else {
repo.Status.SetPrivate(false)
}
if readonly {
repo.Status.SetReadOnly(true)
} else {
repo.Status.SetReadOnly(false)
2024-02-22 21:12:35 -06:00
}
}
}
func parsecfg(f string) []string {
homeDir, _ := os.UserHomeDir()
cfgfile := filepath.Join(homeDir, f)
2024-02-23 11:01:23 -06:00
content, err := ioutil.ReadFile(cfgfile)
if err != nil {
log.Log(REPOWARN, "read cfgfile error", err)
return nil
}
2024-02-22 21:12:35 -06:00
out := string(content)
out = strings.TrimSpace(out)
lines := strings.Split(out, "\n")
return lines
}
*/
2024-02-23 07:02:31 -06:00
func (rl *RepoList) ArgGitPull() bool {
var localonly int
var badmap int
2024-02-23 11:01:23 -06:00
log.Log(REPOWARN, "running git pull everywhere")
2024-02-23 07:02:31 -06:00
var failed int = 0
2024-11-14 21:48:00 -06:00
loop := rl.ReposSortByName()
for loop.Scan() {
repo := loop.Repo()
2024-02-29 19:51:56 -06:00
if out, err := repo.Status.GitPull(); err == nil {
log.Log(REPOWARN, "Ran git pull ok", repo.Status.Path(), out)
2024-02-23 07:02:31 -06:00
} else {
failed += 1
repo.Status.DumpTags()
2024-02-29 19:51:56 -06:00
if errors.Is(repostatus.ErrorGitPullOnLocal, err) {
localonly += 1
continue
}
2024-02-29 19:51:56 -06:00
badmap += 1
log.Log(REPOWARN, "bad unknown git error", repo.Status.Path(), out, err)
2024-02-23 07:02:31 -06:00
}
}
2024-02-23 11:01:23 -06:00
log.Log(REPOWARN, "Ran git pull in all repos. failure count =", failed)
2024-02-29 19:51:56 -06:00
log.Log(REPOWARN, "Ran git pull in all repos. bad errors =", badmap)
if localonly != 0 {
log.Log(REPOWARN, "Ran git pull in all repos. ignored local only branches =", localonly)
}
2024-02-23 07:02:31 -06:00
return true
}
func (rl *RepoList) ArgCheckoutDevel() bool {
2024-02-23 11:01:23 -06:00
log.Log(REPOWARN, "running git checkout devel everwhere")
2024-02-23 07:02:31 -06:00
var failed int = 0
2024-02-25 13:10:23 -06:00
var count int = 0
2024-11-14 21:48:00 -06:00
loop := rl.ReposSortByName()
for loop.Scan() {
repo := loop.Repo()
2024-02-25 13:10:23 -06:00
count += 1
if repo.Status.CheckoutDevel() {
// checkout ok
} else {
failed += 1
2024-02-23 07:02:31 -06:00
}
2024-02-25 13:10:23 -06:00
}
log.Log(REPOWARN, "Ran git checkout in", count, "repos. failure count =", failed)
return true
}
func (rl *RepoList) ArgCheckoutMaster() bool {
log.Log(REPOWARN, "running git checkout master everwhere")
var failed int = 0
var count int = 0
2024-11-14 21:48:00 -06:00
loop := rl.ReposSortByName()
for loop.Scan() {
repo := loop.Repo()
2024-02-25 13:10:23 -06:00
count += 1
if repo.Status.CheckoutMaster() {
// checkout ok
} else {
failed += 1
2024-02-23 07:02:31 -06:00
}
2024-02-25 13:10:23 -06:00
}
log.Log(REPOWARN, "Ran git checkout in", count, "repos. failure count =", failed)
return true
}
func (rl *RepoList) ArgCheckoutUser() bool {
log.Log(REPOWARN, "running git checkout master everwhere")
var failed int = 0
var count int = 0
2024-11-14 21:48:00 -06:00
loop := rl.ReposSortByName()
for loop.Scan() {
repo := loop.Repo()
2024-02-25 13:10:23 -06:00
count += 1
if repo.Status.CheckoutUser() {
// checkout ok
2024-02-23 07:02:31 -06:00
} else {
failed += 1
}
}
2024-02-25 13:10:23 -06:00
log.Log(REPOWARN, "Ran git checkout in", count, "repos. failure count =", failed)
2024-02-23 07:02:31 -06:00
return true
}
2024-03-01 18:03:17 -06:00
func (rl *RepoList) Cfgfile() string {
return rl.cfgfile
}