예제 #1
0
func main() {
	var err error
	var dumpPath string
	var noHeaders bool
	var printRow_arg printRow_arg
	var channelsNum int

	getopt.StringVar(&dumpPath, 'i', "dump-path")
	getopt.StringVar(&printRow_arg.outputPath, 'o', "output-path").SetOptional()
	getopt.BoolVar(&noHeaders, 'n', "no-headers").SetOptional()
	getopt.IntVar(&channelsNum, 'c', "force-channels-num").SetOptional()
	getopt.BoolVar(&printRow_arg.binaryOutput, 'b', "binary-output").SetOptional()
	getopt.BoolVar(&printRow_arg.insertParseTime, 't', "insert-parse-time").SetOptional()

	getopt.Parse()
	if getopt.NArgs() > 0 || dumpPath == "" {
		getopt.Usage()
		os.Exit(-2)
	}
	switch printRow_arg.outputPath {
	/*		case "":
			now              := time.Now()
			year, month, day := now.Date()
			hour, min,   sec := now.Clock()
			printRow_arg.outputPath = fmt.Sprintf("%v_%v-%02v-%02v_%02v:%02v:%02v.csv", h.DeviceName, year, int(month), day, hour, min, sec)
			break*/
	case "", "-":
		printRow_arg.outputPath = "/dev/stdout"
		printRow_arg.outputFile = os.Stdout
		break
	default:
		printRow_arg.outputFile, err = os.Open(printRow_arg.outputPath)
		panic(fmt.Errorf("Not supported yet"))
	}

	if err != nil {
		fmt.Printf("Cannot open output file: %v", err.Error())
		os.Exit(-1)
	}
	//if (printRow_arg.binaryOutput) {
	//	err = binary.Write(printRow_arg.outputFile, binary.LittleEndian, printRow_arg)
	//}

	err = voltloggerParser.ParseVoltloggerDump(dumpPath, noHeaders, channelsNum, handleHeader, printRow, &printRow_arg)
	if err != nil {
		fmt.Printf("Cannot parse the dump: %v\n", err.Error())
		os.Exit(-1)
	}
	printRow_arg.outputFile.Close()

	fmt.Printf("%v %v\n", dumpPath, printRow_arg)
}
예제 #2
0
func main() {
	log.SetFlags(log.LstdFlags | log.Lshortfile)
	// var needle string
	// var filepattern string
	var distance int
	var patternFile string
	var help bool
	var verbose bool
	var simpleoutput bool

	getopt.IntVarLong(&distance, "edit", 'e', "Compute the approximate matching", "max_dist")
	getopt.StringVarLong(&patternFile, "pattern", 'p', "Use line-break separated patterns from a file", "filepath")
	getopt.StringVarLong(&cpuprofile, "cpuprofile", 0, "Write cpuprofile file", "path")
	getopt.StringVarLong(&memprofile, "memprofile", 0, "Write memprofile file", "path")
	getopt.BoolVarLong(&help, "help", 'h', "Shows this message")
	getopt.BoolVarLong(&verbose, "verbose", 'v', "Show log messages")
	getopt.BoolVarLong(&simpleoutput, "simple", 's', "Show simple output")
	getopt.SetProgram("pmt")
	getopt.SetParameters("needle [haystack ...]")
	getopt.SetUsage(func() {
		getopt.PrintUsage(os.Stderr)
		fmt.Fprintf(os.Stderr, "needle - only if -p was not used\n")
		fmt.Fprint(os.Stderr, "haystack\n")
	})
	getopt.Parse()

	if cpuprofile != "" {
		f, err := os.Create(cpuprofile)
		if err != nil {
			log.Fatal(err)
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}

	if help {
		getopt.Usage()
		return
	}

	var patterns []string
	var files []string

	if patternFile == "" {
		// if(len(getopt.Args() )
		if getopt.NArgs() < 1 {
			fmt.Fprintf(os.Stderr, "Needle is missing!\n")
			getopt.Usage()
			os.Exit(1)
		}
		patterns = getopt.Args()[:1]
		files = getopt.Args()[1:]

	} else {
		var err error
		patterns, err = readLinesFromFile(patternFile)
		if err != nil {
			log.Fatal(err)
		}
		files = getopt.Args()
	}

	if verbose {
		log.Printf("%v %v %v\n", patterns, files, distance)
	}

	fileset := findFilesMatch(files)

	if distance == 0 {
		if len(patterns) == 1 {
			matcher := streammatch.NewKMP([]byte(patterns[0]))
			for fp, _ := range fileset {
				file, err := os.Open(fp)
				if err != nil {
					log.Fatal(err)
				}
				matches, err := processSingleExactMatcher(file, matcher, true)

				if err != nil {
					log.Fatal(err)
				}

				if !simpleoutput {
					printMatches(fp, file, patterns, matches, distance)
					if len(matches) > 0 {
						fmt.Println("###")
					}
				} else {
					printSimpleMatches(fp, file, patterns, matches)
				}

			}
		} else if len(patterns) > 1 {
			bpatterns := make([][]byte, len(patterns))
			for i, pattern := range patterns {
				bpatterns[i] = []byte(pattern)
			}
			matcher := streammatch.NewAhoCorasick(bpatterns)
			for fp, _ := range fileset {
				file, err := os.Open(fp)
				if err != nil {
					log.Fatal(err)
				}
				matches, err := processMultiExactMatcher(file, matcher)

				if err != nil {
					log.Fatal(err)
				}

				if !simpleoutput {
					printMatches(fp, file, patterns, matches, distance)
					if len(matches) > 0 {
						fmt.Println("###")
					}
				} else {
					printSimpleMatches(fp, file, patterns, matches)
				}

			}
		}
	} else {
		matchers := make([]streammatch.Matcher, 0, len(patterns))
		for i := 0; i < len(patterns); i++ {
			matchers = append(matchers, streammatch.NewSellers([]byte(patterns[i]), distance))
		}

		for fp, _ := range fileset {
			file, err := os.Open(fp)
			if err != nil {
				log.Fatal(err)
			}

			bufreader := bufio.NewReaderSize(file, defaultBufSize)
			allmatches := make([]matchRecord, 0, 2)
			for _, matcher := range matchers {
				_, err := file.Seek(0, 0)
				if err != nil {
					log.Fatal(err)
				}
				bufreader.Reset(file)
				matches, err := processSingleExactMatcher(bufreader, matcher, false)
				if err != nil {
					log.Fatal(err)
				}
				allmatches = append(allmatches, matches...)
			}

			sort.Stable(matchRecordList(allmatches))

			if !simpleoutput {
				printMatches(fp, file, patterns, allmatches, distance)
				if len(allmatches) > 0 {
					fmt.Println("###")
				}
			} else {
				printSimpleMatches(fp, file, patterns, allmatches)
			}
		}
	}
	if memprofile != "" {
		f, err := os.Create(memprofile)
		if err != nil {
			log.Fatal(err)
		}
		pprof.WriteHeapProfile(f)
		defer f.Close()
		return
	}
}
예제 #3
0
파일: main.go 프로젝트: sykesm/git-duet
func main() {
	var (
		quiet  = getopt.BoolLong("quiet", 'q', "Silence output")
		global = getopt.BoolLong("global", 'g', "Change global config")
		help   = getopt.BoolLong("help", 'h', "Help")
	)

	getopt.Parse()

	if *help {
		getopt.Usage()
		os.Exit(0)
	}

	configuration, err := duet.NewConfiguration()
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	if getopt.NArgs() == 0 {
		gitConfig, err := duet.GetAuthorConfig(configuration.Namespace)
		if err != nil {
			fmt.Println(err)
			os.Exit(1)
		}

		author, err := gitConfig.GetAuthor()
		if err != nil {
			fmt.Println(err)
			os.Exit(1)
		}

		printAuthor(author)
		os.Exit(0)
	}

	gitConfig := &duet.GitConfig{
		Namespace: configuration.Namespace,
	}
	if configuration.Global || *global {
		gitConfig.Scope = duet.Global
	}

	pairs, err := duet.NewPairsFromFile(configuration.PairsFile, configuration.EmailLookup)
	if err != nil {
		fmt.Println(err)
		os.Exit(0)
	}

	author, err := pairs.ByInitials(getopt.Arg(0))
	if err != nil {
		fmt.Println(err)
		os.Exit(86)
	}

	if err = gitConfig.SetAuthor(author); err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	if err = gitConfig.ClearCommitter(); err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	if !*quiet {
		printAuthor(author)
	}
}
예제 #4
0
파일: main.go 프로젝트: Jdavid1001/git-duet
func main() {
	var (
		quiet  = getopt.BoolLong("quiet", 'q', "Silence output")
		global = getopt.BoolLong("global", 'g', "Change global config")
		help   = getopt.BoolLong("help", 'h', "Help")
	)

	getopt.Parse()

	if *help {
		getopt.Usage()
		os.Exit(0)
	}

	configuration, err := duet.NewConfiguration()
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	if getopt.NArgs() == 0 {
		gitConfig, err := duet.GetAuthorConfig(configuration.Namespace)
		if err != nil {
			fmt.Println(err)
			os.Exit(1)
		}

		author, err := gitConfig.GetAuthor()
		if err != nil {
			fmt.Println(err)
			os.Exit(1)
		}
		committer, err := gitConfig.GetCommitter()
		if err != nil {
			fmt.Println(err)
			os.Exit(1)
		}

		if committer == nil {
			committer = author
		}

		printAuthor(author)
		printCommitter(committer)
		os.Exit(0)
	}

	gitConfig := &duet.GitConfig{
		Namespace: configuration.Namespace,
	}
	if configuration.Global || *global {
		gitConfig.Scope = duet.Global
	}

	if getopt.NArgs() <= 2 {
		fmt.Println("must specify more than two sets of initials")
		os.Exit(1)
	}

	pairs, err := duet.NewPairsFromFile(configuration.PairsFile, configuration.EmailLookup)
	if err != nil {
		fmt.Println(err)
		os.Exit(0)
	}

	author, err := pairs.ByInitials(getopt.Arg(0))
	if err != nil {
		fmt.Println(err)
		os.Exit(86)
	}

	if err = gitConfig.SetAuthor(author); err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	number_of_committers := getopt.NArgs() - 1
	committers := make([]*duet.Pair, number_of_committers)

	for i := 1; i < getopt.NArgs(); i++ {
		committer, err := pairs.ByInitials(getopt.Arg(i))
		if err == nil {
			committers[i-1] = committer
		} else {
			fmt.Println(err)
			os.Exit(1)
		}
	}

	committer := makeTeamCommitter(committers)

	if err = gitConfig.SetCommitter(committer); err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	if !*quiet {
		printAuthor(author)
		printCommitter(committer)
	}
}