parse config file options
This commit is contained in:
parent
ec7dd061e2
commit
6b7ab8a752
126
configfile.go
126
configfile.go
|
@ -12,15 +12,83 @@ import (
|
||||||
func (v *RepoList) InitRepoList(cfgfile string) {
|
func (v *RepoList) InitRepoList(cfgfile string) {
|
||||||
lines := parsecfg(cfgfile)
|
lines := parsecfg(cfgfile)
|
||||||
for _, line := range lines {
|
for _, line := range lines {
|
||||||
log.Verbose("repo =", line)
|
var repo *RepoRow
|
||||||
|
var err error
|
||||||
line = strings.TrimSpace(line)
|
line = strings.TrimSpace(line)
|
||||||
|
if line == "" {
|
||||||
|
// skip empty lines
|
||||||
|
continue
|
||||||
|
}
|
||||||
if strings.HasPrefix(line, "#") {
|
if strings.HasPrefix(line, "#") {
|
||||||
|
// skip config file comment lines
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
parts := strings.Split(line, " ")
|
parts := strings.Split(line, " ")
|
||||||
|
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")
|
||||||
|
private = true
|
||||||
|
} else {
|
||||||
|
log.Log(REPOWARN, repodir, "setting ReadOnly to false")
|
||||||
|
private = false
|
||||||
|
}
|
||||||
|
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
|
||||||
|
}
|
||||||
if len(parts) > 0 {
|
if len(parts) > 0 {
|
||||||
path := parts[0]
|
path := parts[0]
|
||||||
v.NewRepo(path)
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,7 +96,11 @@ func (v *RepoList) InitRepoList(cfgfile string) {
|
||||||
func parsecfg(f string) []string {
|
func parsecfg(f string) []string {
|
||||||
homeDir, _ := os.UserHomeDir()
|
homeDir, _ := os.UserHomeDir()
|
||||||
cfgfile := filepath.Join(homeDir, f)
|
cfgfile := filepath.Join(homeDir, f)
|
||||||
content, _ := ioutil.ReadFile(cfgfile)
|
content, err := ioutil.ReadFile(cfgfile)
|
||||||
|
if err != nil {
|
||||||
|
log.Log(REPOWARN, "read cfgfile error", err)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
out := string(content)
|
out := string(content)
|
||||||
out = strings.TrimSpace(out)
|
out = strings.TrimSpace(out)
|
||||||
lines := strings.Split(out, "\n")
|
lines := strings.Split(out, "\n")
|
||||||
|
@ -36,15 +108,15 @@ func parsecfg(f string) []string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rl *RepoList) ArgCheckoutUser() bool {
|
func (rl *RepoList) ArgCheckoutUser() bool {
|
||||||
log.Info("running git checkout devel everwhere")
|
log.Log(REPOWARN, "running git checkout devel everwhere")
|
||||||
var failed int = 0
|
var failed int = 0
|
||||||
for _, repo := range rl.AllRepos() {
|
for _, repo := range rl.AllRepos() {
|
||||||
if repo.Status.ReadOnly() {
|
if repo.Status.ReadOnly() {
|
||||||
// log.Info("skipping read-only", repo.Name())
|
// log.Log(REPOWARN,"skipping read-only", repo.Name())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if repo.Status.CheckDirty() {
|
if repo.Status.CheckDirty() {
|
||||||
log.Info("skipping dirty repo", repo.Name())
|
log.Log(REPOWARN, "skipping dirty repo", repo.Name())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
branch := repo.Status.GetUserBranchName()
|
branch := repo.Status.GetUserBranchName()
|
||||||
|
@ -53,68 +125,68 @@ func (rl *RepoList) ArgCheckoutUser() bool {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
cmd := []string{"git", "checkout", branch}
|
cmd := []string{"git", "checkout", branch}
|
||||||
log.Info("Running:", cmd, "in", repo.Name())
|
log.Log(REPOWARN, "Running:", cmd, "in", repo.Name())
|
||||||
err, output := repo.RunCmd(cmd)
|
err, output := repo.RunCmd(cmd)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
log.Info("git checkout worked", output)
|
log.Log(REPOWARN, "git checkout worked", output)
|
||||||
} else {
|
} else {
|
||||||
failed += 1
|
failed += 1
|
||||||
log.Info("git checkout failed")
|
log.Log(REPOWARN, "git checkout failed")
|
||||||
log.Info("Something went wrong. Got err", err)
|
log.Log(REPOWARN, "Something went wrong. Got err", err)
|
||||||
log.Info("output =", output)
|
log.Log(REPOWARN, "output =", output)
|
||||||
// return false
|
// return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.Info("Ran git checkout in all repos. failure count =", failed)
|
log.Log(REPOWARN, "Ran git checkout in all repos. failure count =", failed)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rl *RepoList) ArgGitPull() bool {
|
func (rl *RepoList) ArgGitPull() bool {
|
||||||
log.Info("running git pull everywhere")
|
log.Log(REPOWARN, "running git pull everywhere")
|
||||||
cmd := []string{"git", "pull"}
|
cmd := []string{"git", "pull"}
|
||||||
var failed int = 0
|
var failed int = 0
|
||||||
for _, repo := range rl.AllRepos() {
|
for _, repo := range rl.AllRepos() {
|
||||||
log.Info("Running:", repo.Status.Path(), cmd)
|
log.Log(REPOWARN, "Running:", repo.Status.Path(), cmd)
|
||||||
err, output := repo.RunCmd(cmd)
|
err, output := repo.RunCmd(cmd)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
log.Info(output)
|
log.Log(REPOWARN, output)
|
||||||
} else {
|
} else {
|
||||||
failed += 1
|
failed += 1
|
||||||
log.Info("Something went wrong. Got err", err)
|
log.Log(REPOWARN, "Something went wrong. Got err", err)
|
||||||
log.Info("output =", output)
|
log.Log(REPOWARN, "output =", output)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.Info("Ran git pull in all repos. failure count =", failed)
|
log.Log(REPOWARN, "Ran git pull in all repos. failure count =", failed)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rl *RepoList) ArgCheckoutDevel() bool {
|
func (rl *RepoList) ArgCheckoutDevel() bool {
|
||||||
log.Info("running git checkout devel everwhere")
|
log.Log(REPOWARN, "running git checkout devel everwhere")
|
||||||
var failed int = 0
|
var failed int = 0
|
||||||
for _, repo := range rl.AllRepos() {
|
for _, repo := range rl.AllRepos() {
|
||||||
if repo.Status.ReadOnly() {
|
if repo.Status.ReadOnly() {
|
||||||
// log.Info("skipping read-only", repo.Name())
|
// log.Log(REPOWARN,"skipping read-only", repo.Name())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if repo.CheckDirty() {
|
if repo.CheckDirty() {
|
||||||
log.Info("skipping dirty repo", repo.Name())
|
log.Log(REPOWARN, "skipping dirty repo", repo.Name())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
branch := repo.Status.GetDevelBranchName()
|
branch := repo.Status.GetDevelBranchName()
|
||||||
cmd := []string{"git", "checkout", branch}
|
cmd := []string{"git", "checkout", branch}
|
||||||
log.Info("Running:", cmd, "in", repo.Name())
|
log.Log(REPOWARN, "Running:", cmd, "in", repo.Name())
|
||||||
err, output := repo.RunCmd(cmd)
|
err, output := repo.RunCmd(cmd)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
log.Info("git checkout worked", output)
|
log.Log(REPOWARN, "git checkout worked", output)
|
||||||
} else {
|
} else {
|
||||||
failed += 1
|
failed += 1
|
||||||
log.Info("git checkout failed")
|
log.Log(REPOWARN, "git checkout failed")
|
||||||
log.Info("Something went wrong. Got err", err)
|
log.Log(REPOWARN, "Something went wrong. Got err", err)
|
||||||
log.Info("output =", output)
|
log.Log(REPOWARN, "output =", output)
|
||||||
// return false
|
// return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.Info("Ran git checkout in all repos. failure count =", failed)
|
log.Log(REPOWARN, "Ran git checkout in all repos. failure count =", failed)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,6 +50,12 @@ func (r *RepoRow) Show() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *RepoList) NewRepo(path string) (*RepoRow, error) {
|
func (r *RepoList) NewRepo(path string) (*RepoRow, error) {
|
||||||
|
test, ok := r.allrepos[path]
|
||||||
|
if ok {
|
||||||
|
// this repo already exists
|
||||||
|
return test, nil
|
||||||
|
}
|
||||||
|
|
||||||
status, err := repostatus.New(path)
|
status, err := repostatus.New(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
Loading…
Reference in New Issue