Пример #1
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
}
Пример #2
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
}