コード例 #1
0
ファイル: build.go プロジェクト: sqp/godock
// makeBuild builds sources in the build subdir.
//
// Progress is sent to the update callback provided.
//
func (build *BuilderBase) makeBuild(dir string, progress func(float64)) error {
	jobs := strconv.Itoa(runtime.NumCPU())

	build.log.Info("make", "-j", jobs)
	cmd := build.log.ExecCmd("make", "-j", jobs)
	cmd.Dir = dir

	lastvalue := 0
	cmd.Stdout = linesplit.NewWriter(func(line string) {
		curvalue, curstr, text := trimInt(line)
		if curvalue > -1 {
			if curvalue > lastvalue {
				progress(float64(curvalue) / 100)
				lastvalue = curvalue
			}
			fmt.Printf("%s %s\n", curstr, color.Green(text))

		} else {
			println(line)
		}
	})

	e := cmd.Run()
	if e != nil {
		return e
	}

	return build.makeInstall(dir)
}
コード例 #2
0
ファイル: youtubedl.go プロジェクト: sqp/godock
// Formats returns the list of available streams and formats for the video.
//
func (f *YoutubeDLFile) Formats() ([]*Format, error) {
	init := false

	cmd := f.log.ExecCmd(cmdName, "-F", f.url)
	cmd.Stdout = linesplit.NewWriter(func(s string) { // results display formatter.

		if strings.HasPrefix(s, "format code") {
			init = true
			return
		}
		if !init {
			return
		}

		args := strings.Fields(s)
		code, e := strconv.Atoi(args[0])
		f.log.Err(e, "convert code ID")
		if len(args) >= 3 {
			form := &Format{
				Itag:       code,
				Extension:  args[1],
				Resolution: args[2],
			}

			if len(args) > 3 {
				// form.Note = args[3]
			}
			if len(args) > 4 {
				last := args[len(args)-1]
				if strings.HasSuffix(last, "iB") {
					if strings.HasSuffix(last, "MiB") {
						// form.Size = last[:len(last)-3]
						// f.log.Info("SIZE M", last[:len(last)-3])
					}
					args = args[:len(args)-1]
				}

				f.log.Info("more", len(args)-3, args[3:])
			}

			f.log.Info("ik", form)
			f.formats = append(f.formats, form)
		}
	})

	lastID := len(f.formats) - 1
	// ids := ""
	sel := []*Format{}
	for i := range f.formats {
		form := f.formats[lastID-i] // Reverse list order (best quality first).
		sel = append(sel, form)
		// if form.Note == "" || form.Note == "(best)" { // TODO: improve.
		// ids = strhelp.Separator(ids, ";", strhelp.Separator(form.Extension, ": ", form.Resolution))
		// }
	}
	f.formats = sel

	e := cmd.Run()
	return f.formats, e
}
コード例 #3
0
ファイル: update.go プロジェクト: sqp/godock
// GrepTarget searches the directory for the given string.
//
func (app *Applet) GrepTarget(search string) {
	if len(search) < 2 { // security, need to confirm or improve.
		app.Log().NewErr("grep", "search query too short, need at least 2 chars")
		return
	}

	// Escape ." chars (dot and quotes).
	query := strings.Replace(search, `"`, `\"`, -1)
	query = strings.Replace(query, ".", `\.`, -1)

	// Prepare command.
	out := ""
	count := 0
	cmd := app.Log().ExecCmd("grep", append(grepCmdArgs, query)...) // get the command with default args.
	cmd.Dir = app.target.SourceDir()                                // set command dir to reduce file path.
	cmd.Stdout = linesplit.NewWriter(func(s string) {               // results display formatter.
		count++
		sp := strings.SplitN(s, ":", 2)
		if len(sp) == 2 {
			out += grepFileFormatter(sp[0]) + ":\t" // start line with percent and a tab.
			colored := strings.Replace(sp[1], search, grepQueryFormatter(search), -1)
			out += strings.TrimLeft(colored, " \t") + "\n" // remove space and tab.

		} else {
			out += s + "\n"
		}
	})

	// app.Log().Info("grep", append(grepCmdArgs, query))

	// Launch command.
	e := cmd.Run()
	app.Log().Err(e, "Grep target")

	// Print title and list.
	found := "none found"
	if count > 0 {
		found = fmt.Sprintf("count %d", count)
	}
	fmt.Printf(grepTitlePattern, grepTitleFormatter(search), found)
	fmt.Println(out)
}