コード例 #1
0
ファイル: linesInFiles.go プロジェクト: rudenoise/counting
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())
	flag.Parse()
	dirStr := filepath.Dir(flag.Arg(0))
	pths, err := dir.AllPaths(dirStr, *exclude, *include)
	total := 0
	if err != nil {
		panic(err)
	}
	limit := 5000
	if len(pths) < limit {
		files := OpenParallel(pths)
		sort.Sort(ByLengthReverse{files})
		// decide length of output
		length := len(files)
		if *lmt != 0 && *lmt <= length {
			length = *lmt
		}
		for i := 0; i < length; i++ {
			total += files[i].LineCount
			fmt.Printf("%7d\t%s\n", files[i].LineCount, files[i].FilePath)
		}
		fmt.Printf("\n%7d\ttotal\n\n", total)
	} else {
		fmt.Printf("\nDidn't bother, you tried to meaure %d files, limit set to %d\n\n", len(pths), limit)
	}
}
コード例 #2
0
ファイル: sizeFiles.go プロジェクト: rudenoise/counting
func main() {
	flag.Parse()
	// start at current dir or path from args
	dirStr := filepath.Dir(flag.Arg(0))
	fps, err := dir.AllPaths(dirStr, *exclude, *include)
	if err != nil {
		panic(err)
	}
	filePaths := fullInfo(fps, *ignoreCommentsEmptyLines)
	// order by args
	if *byBytes {
		if *asc {
			sort.Sort(ByByteLen{filePaths})
		} else {
			sort.Sort(ByByteLenReverse{filePaths})
		}
	} else {
		if *asc {
			sort.Sort(ByLines{filePaths})
		} else {
			sort.Sort(ByLinesReverse{filePaths})
		}
	}
	// decide length of output
	length := len(filePaths)
	if *lmt != 0 && *lmt <= length {
		length = *lmt
	}
	// print output
	out(filePaths, length)
}
コード例 #3
0
ファイル: timeSeries.go プロジェクト: rudenoise/counting
func getPaths(dirStr string) []string {
	paths, err := dir.AllPaths(dirStr, *exclude, *include)
	if err != nil {
		panic(err)
	}
	return paths
}
コード例 #4
0
ファイル: tokensInFiles.go プロジェクト: rudenoise/counting
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())
	flag.Parse()
	dirStr := filepath.Dir(flag.Arg(0))

	filePaths, err := dir.AllPaths(dirStr, *exclude, *include)
	if err != nil {
		panic(err)
	}

	limit := 5000
	length := len(filePaths)

	if length < limit {
		tMap := make(count.TokensMap)
		count.TokensInFiles(filePaths, *tokenRegExp, tMap)

		tSlice := tMap.ToSlice()
		if *asc == true {
			sort.Sort(count.TokenSliceByCountAsc{tSlice})
		} else {
			sort.Sort(count.TokenSliceByCountDesc{tSlice})
		}
		length = len(tSlice)
		if *lmt != 0 && *lmt <= length {
			length = *lmt
		}
		for i := 0; i < length; i++ {
			fmt.Printf("%7d\t%s\n", tSlice[i].Count, tSlice[i].Token)
		}

	} else {
		fmt.Printf("\nDidn't bother, you tried to meaure %d files, limit set to %d\n\n", length, limit)
	}
}
コード例 #5
0
ファイル: inPath.go プロジェクト: rudenoise/counting
func main() {
	flag.Parse()
	dirStr := filepath.Dir(flag.Arg(0))
	paths, err := dir.AllPaths(dirStr, "^$", *re)
	if err != nil {
		panic(err)
	}
	for i := 0; i < len(paths); i++ {
		fmt.Println(paths[i])
	}
}
コード例 #6
0
ファイル: pubSubMap.go プロジェクト: rudenoise/counting
func main() {
	// parse cmd flags
	flag.Parse()
	// get the directory from which to start searching
	dirStr := filepath.Dir(flag.Arg(0))
	// traverse all child directories and collect a slice of file paths
	filePaths, err := dir.AllPaths(dirStr, *exclude, *include)
	if err != nil {
		panic(err)
	}
	// create the regexp to isolate the key
	compiledTokenRE, err := regexp.Compile(tokenRE)
	// create a difinitive map of tokens
	allTokens := make(AllTokens)
	// create a map for files
	files := make(map[string]File)
	// loop all files paths
	length := len(filePaths)
	for i := 0; i < length; i++ {
		// collect published tokens from file
		pubMap := make(count.TokensMap)
		count.TokensInFile(filePaths[i], pubRE, pubMap)
		// collect subscribed tokens from file
		subMap := make(count.TokensMap)
		count.TokensInFile(filePaths[i], subRE, subMap)
		// collect state.set tokens from file
		stateSetMap := make(count.TokensMap)
		count.TokensInFile(filePaths[i], stateSetRE, stateSetMap)
		// collect state.get tokens from file
		stateGetMap := make(count.TokensMap)
		count.TokensInFile(filePaths[i], stateGetRE, stateGetMap)
		// collect all state and pubSub interactions for this file
		files[filePaths[i]] = File{
			loopTokens(pubMap, compiledTokenRE, allTokens, 0),
			loopTokens(subMap, compiledTokenRE, allTokens, 0),
			loopTokens(stateSetMap, compiledTokenRE, allTokens, 1),
			loopTokens(stateGetMap, compiledTokenRE, allTokens, 1),
		}
	}
	// now we have a map of all files and their publshed and subscribed keys
	printInDotFormat(
		allTokens,
		filterEmptyFiles(files),
	)
}