コード例 #1
0
ファイル: main.go プロジェクト: adilr00t/distributive
// checklistsFromDir reads all of the files in the path and parses their utf8
// encoded json data, turning it into a checklist struct.
func checklistsFromDir(dirpath string) (chklsts []Checklist) {
	paths := wrkutils.GetFilesWithExtension(dirpath, ".json")
	// send one checklist per path to the channel
	out := make(chan Checklist)
	for _, path := range paths {
		go func(path string, out chan Checklist) {
			out <- checklistFromFile(path)
		}(path, out)
	}
	// get all values from the channel, return them
	for _ = range paths {
		chklsts = append(chklsts, <-out)
	}
	return chklsts
}
コード例 #2
0
ファイル: packages.go プロジェクト: pinterb/distributive
// getAptrepos constructs repos from the sources.list file at path. Gives
// non-zero URLs
func getAptRepos() (repos []repo) {
	// getAptSources returns all the urls of all apt sources (including source
	// code repositories
	getAptSources := func() (urls []string) {
		otherLists := wrkutils.GetFilesWithExtension("/etc/apt/sources.list.d", ".list")
		sourceLists := append([]string{"/etc/apt/sources.list"}, otherLists...)
		for _, f := range sourceLists {
			split := tabular.ProbabalisticSplit(wrkutils.FileToString(f))
			// filter out comments
			commentRegex := regexp.MustCompile(`^\s*#`)
			for _, line := range split {
				if len(line) > 1 && !(commentRegex.MatchString(line[0])) {
					urls = append(urls, line[1])
				}
			}
		}
		return urls
	}
	for _, src := range getAptSources() {
		repos = append(repos, repo{URL: src})
	}
	return repos
}