예제 #1
0
func (pkg *LocalPackage) readDesc(v *viper.Viper) (*PackageDesc, error) {
	pdesc := &PackageDesc{}

	pdesc.Author = v.GetString("pkg.author")
	pdesc.Homepage = v.GetString("pkg.homepage")
	pdesc.Description = v.GetString("pkg.description")
	pdesc.Keywords = v.GetStringSlice("pkg.keywords")

	return pdesc, nil
}
예제 #2
0
func (proj *Project) loadRepo(rname string, v *viper.Viper) error {
	varName := fmt.Sprintf("repository.%s", rname)

	repoVars := v.GetStringMapString(varName)
	if len(repoVars) == 0 {
		return util.NewNewtError(fmt.Sprintf("Missing configuration for "+
			"repository %s.", rname))
	}
	if repoVars["type"] == "" {
		return util.NewNewtError(fmt.Sprintf("Missing type for repository " +
			rname))
	}

	dl, err := downloader.LoadDownloader(rname, repoVars)
	if err != nil {
		return err
	}

	rversreq := repoVars["vers"]
	r, err := repo.NewRepo(rname, rversreq, dl)
	if err != nil {
		return err
	}

	for _, ignDir := range ignoreSearchDirs {
		r.AddIgnoreDir(ignDir)
	}

	rd, err := repo.NewRepoDependency(rname, rversreq)
	if err != nil {
		return err
	}
	rd.Storerepo = r

	proj.localRepo.AddDependency(rd)

	log.Debugf("Loaded repository %s (type: %s, user: %s, repo: %s)", rname,
		repoVars["type"], repoVars["user"], repoVars["repo"])

	proj.repos[r.Name()] = r
	return nil
}
예제 #3
0
func GetSliceFeatures(v *viper.Viper, features map[string]bool,
	key string) []interface{} {

	val := v.Get(key)
	vals := []interface{}{val}

	// Process the features in alphabetical order to ensure consistent
	// results across repeated runs.
	var featureKeys []string
	for feature, _ := range features {
		featureKeys = append(featureKeys, feature)
	}
	sort.Strings(featureKeys)

	for _, feature := range featureKeys {
		overwriteVal := v.Get(key + "." + feature + ".OVERWRITE")
		if overwriteVal != nil {
			return []interface{}{overwriteVal}
		}

		appendVal := v.Get(key + "." + feature)
		if appendVal != nil {
			vals = append(vals, appendVal)
		}
	}

	return vals
}
예제 #4
0
func GetStringFeatures(v *viper.Viper, features map[string]bool,
	key string) string {
	val := v.GetString(key)

	// Process the features in alphabetical order to ensure consistent
	// results across repeated runs.
	var featureKeys []string
	for feature, _ := range features {
		featureKeys = append(featureKeys, feature)
	}
	sort.Strings(featureKeys)

	for _, feature := range featureKeys {
		overwriteVal := v.GetString(key + "." + feature + ".OVERWRITE")
		if overwriteVal != "" {
			val = strings.Trim(overwriteVal, "\n")
			break
		}

		appendVal := v.GetString(key + "." + feature)
		if appendVal != "" {
			val += " " + strings.Trim(appendVal, "\n")
		}
	}
	return strings.TrimSpace(val)
}
예제 #5
0
func (r *Repo) readDepRepos(v *viper.Viper) ([]*Repo, error) {
	rdesc := r.rdesc
	repos := []*Repo{}

	branch, _, ok := rdesc.Match(r)
	if !ok {
		// No matching branch, barf!
		return nil, util.NewNewtError(fmt.Sprintf("No "+
			"matching branch for %s repo", r.Name()))
	}

	repoTag := fmt.Sprintf("%s.repositories", branch)

	repoList := v.GetStringMap(repoTag)
	for repoName, repoItf := range repoList {
		repoVars := cast.ToStringMapString(repoItf)

		dl, err := downloader.LoadDownloader(repoName, repoVars)
		if err != nil {
			return nil, err
		}

		rversreq := repoVars["vers"]
		newRepo, err := NewRepo(repoName, rversreq, dl)
		if err != nil {
			return nil, err
		}

		rd, err := NewRepoDependency(repoName, rversreq)
		if err != nil {
			return nil, err
		}
		rd.Storerepo = newRepo

		r.AddDependency(rd)

		repos = append(repos, newRepo)
	}
	return repos, nil
}