当前位置: 首页>>代码示例>>Golang>>正文


Golang pb.New函数代码示例

本文整理汇总了Golang中github.com/cheggaaa/pb.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了New函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Example_multiple

func Example_multiple() {
	// create bars
	first := pb.New(200).Prefix("First ")
	second := pb.New(200).Prefix("Second ")
	third := pb.New(200).Prefix("Third ")
	// start pool
	pool, err := pb.StartPool(first, second, third)
	if err != nil {
		panic(err)
	}
	// update bars
	wg := new(sync.WaitGroup)
	for _, bar := range []*pb.ProgressBar{first, second, third} {
		wg.Add(1)
		go func(cb *pb.ProgressBar) {
			for n := 0; n < 200; n++ {
				cb.Increment()
				time.Sleep(time.Millisecond * time.Duration(rand.Intn(100)))
			}
			cb.Finish()
			wg.Done()
		}(bar)
	}
	wg.Wait()
	// close pool
	pool.Stop()
}
开发者ID:ZhuHangpeng,项目名称:mig,代码行数:27,代码来源:example_multiple_test.go

示例2: SetupLog

//SetupLog sets up initial ConnectionLog
func SetupLog(length, noOfConn int) error {
	connLog.stats = make([]ConnectionStat, noOfConn)
	barArray := make([]*pb.ProgressBar, noOfConn+1)
	lenSub := length / noOfConn
	for i := 0; i < noOfConn; i++ {
		fileBegin := lenSub * i
		fileEnd := lenSub * (i + 1)
		if i == noOfConn-1 {
			fileEnd = length
		}
		bar := pb.New(fileEnd - fileBegin).Prefix("Connection " + strconv.Itoa(i+1) + " ")
		customizeBar(bar)
		connLog.stats[i] = ConnectionStat{connectionIndex: i, pbar: bar}
		barArray[i] = bar
	}
	bar := pb.New(length).Prefix("Total ")
	customizeBar(bar)
	connLog.totalbar = bar
	barArray[noOfConn] = bar
	var err error
	connLog.pool, err = pb.StartPool(barArray...)
	if err != nil {
		return err
	}
	return nil
}
开发者ID:prashant-agarwala,项目名称:grozilla,代码行数:27,代码来源:log.go

示例3: Update

// Update replaces the inode of the current executable with the latest version
// n.b. this won't work on Windows
func (u *Updater) Update() error {
	u.l.Infoln("Downloading version", u.ServerVersion.Version)
	werckerPath, err := filepath.Abs(os.Args[0])
	if err != nil {
		return err
	}

	// Put new version in tempfile in parent directory.
	temp, err := ioutil.TempFile(filepath.Dir(werckerPath), fmt.Sprintf(".%s-", u.ServerVersion.Version))
	if err != nil {
		return err
	}
	defer temp.Close()

	newVersion, err := http.Get(u.DownloadURL())
	if err != nil {
		return err
	}
	defer newVersion.Body.Close()

	bar := pb.New(int(newVersion.ContentLength)).SetUnits(pb.U_BYTES)
	bar.Start()
	writer := io.MultiWriter(temp, bar)

	_, err = io.Copy(writer, newVersion.Body)
	if err != nil {
		return err
	}

	temp.Chmod(0755)

	return os.Rename(temp.Name(), werckerPath)
}
开发者ID:wercker,项目名称:wercker,代码行数:35,代码来源:update.go

示例4: downloader

func downloader(uri string, file string) {
	var log = logrus.New()
	log.Formatter = new(logrus.JSONFormatter)

	log.Debug("creating file.")
	outFile, err := os.Create(file)
	if err != nil {
		os.Exit(1)
	}

	client := &http.Client{}

	log.Debugf("new request for %+v", uri)
	req, err := http.NewRequest("GET", uri, nil)

	log.Debug("request initiated.")
	resp, err := client.Do(req)

	//progress bar
	header := resp.ContentLength
	bar := pb.New(int(header)).SetUnits(pb.U_BYTES)
	bar.Start()
	reader := bar.NewProxyReader(resp.Body)

	if err != nil {
		panic(err)
	}

	// not closing reader as the NewProxyReader exits for me.
	log.Debugf("copying response data to %+v", file)
	io.Copy(outFile, reader)

	os.Exit(0)
}
开发者ID:mynameismevin,项目名称:going,代码行数:34,代码来源:going.go

示例5: runPgRestore

func runPgRestore(args *docopt.Args, client controller.Client, config *runConfig) error {
	config.Stdin = os.Stdin
	var size int64
	if filename := args.String["--file"]; filename != "" {
		f, err := os.Open(filename)
		if err != nil {
			return err
		}
		defer f.Close()
		stat, err := f.Stat()
		if err != nil {
			return err
		}
		size = stat.Size()
		config.Stdin = f
	}
	if !args.Bool["--quiet"] && term.IsTerminal(os.Stderr.Fd()) {
		bar := pb.New(0)
		bar.SetUnits(pb.U_BYTES)
		if size > 0 {
			bar.Total = size
		} else {
			bar.ShowBar = false
		}
		bar.ShowSpeed = true
		bar.Output = os.Stderr
		bar.Start()
		defer bar.Finish()
		config.Stdin = bar.NewProxyReader(config.Stdin)
	}
	return pgRestore(client, config)
}
开发者ID:ably-forks,项目名称:flynn,代码行数:32,代码来源:pg.go

示例6: newPb

func newPb(size int) (bar *pb.ProgressBar) {
	bar = pb.New(size)
	bar.SetRefreshRate(time.Millisecond)
	bar.ShowSpeed = true
	bar.Start()
	return
}
开发者ID:WayneZhouChina,项目名称:goxel,代码行数:7,代码来源:goxeler.go

示例7: share

func share(srv *drive.Service, accountFrom string, accountTo string) error {
	// List all files and folders
	files, err := findAllFilesFrom(srv, accountFrom)
	if err != nil {
		return err
	}
	fmt.Printf("Found: %d files or directories\n", len(files))

	// Progress bar
	bar := pb.New(len(files))
	bar.SetRefreshRate(time.Second)
	bar.Start()

	for _, file := range files {
		bar.Increment()
		err := shareFile(srv, file, accountTo)
		if err != nil {
			return err
		}
	}
	bar.FinishPrint("Done.")

	// Everything is OK
	return nil
}
开发者ID:xert,项目名称:gdriver,代码行数:25,代码来源:share.go

示例8: imageDownloader

func imageDownloader(uri string, filename string, wg *sync.WaitGroup) {
	defer wg.Done()

	tokens := strings.Split(uri, "/")
	fileName := tokens[len(tokens)-1]

	outFile, err := os.Create(fileName)
	if err != nil {
		fmt.Println(err)
	}

	client := &http.Client{}

	req, err := http.NewRequest("GET", uri, nil)

	resp, err := client.Do(req)
	if err != nil {
		fmt.Println(err)
	}
	defer resp.Body.Close()

	header := resp.ContentLength
	bar := pb.New(int(header)).SetUnits(pb.U_BYTES)
	bar.SetRefreshRate(time.Millisecond)
	//	bar.Start()
	rd := bar.NewProxyReader(resp.Body)
	// and copy from reader
	io.Copy(outFile, rd)
	if err != nil {
		fmt.Println(err)
	}
}
开发者ID:mynameismevin,项目名称:takegur,代码行数:32,代码来源:takegur.go

示例9: runRedisDump

func runRedisDump(args *docopt.Args, client controller.Client, config *runConfig) error {
	config.Stdout = os.Stdout
	if filename := args.String["--file"]; filename != "" {
		f, err := os.Create(filename)
		if err != nil {
			return err
		}
		defer f.Close()
		config.Stdout = f
	}

	if !args.Bool["--quiet"] && term.IsTerminal(os.Stderr.Fd()) {
		bar := pb.New(0)
		bar.SetUnits(pb.U_BYTES)
		bar.ShowBar = false
		bar.ShowSpeed = true
		bar.Output = os.Stderr
		bar.Start()
		defer bar.Finish()
		config.Stdout = io.MultiWriter(config.Stdout, bar)
	}

	config.Args[0] = "/bin/dump-flynn-redis"
	return runJob(client, *config)
}
开发者ID:ably-forks,项目名称:flynn,代码行数:25,代码来源:redis.go

示例10: newPb

func newPb(size int) (bar *pb.ProgressBar) {
	bar = pb.New(size)
	bar.Current = barChar
	bar.BarStart = ""
	bar.BarEnd = ""
	bar.Start()
	return
}
开发者ID:nunogt,项目名称:boom,代码行数:8,代码来源:boom.go

示例11: Start

// Start starts showing progress
func (t *TextProgress) Start(pkg string, total float64) {
	// TODO go to New64 once we update the pb package.
	t.pbar = pb.New(0)
	t.pbar.Total = int64(total)
	t.pbar.ShowSpeed = true
	t.pbar.Units = pb.U_BYTES
	t.pbar.Start()
}
开发者ID:dholbach,项目名称:snappy,代码行数:9,代码来源:progress.go

示例12: SetupResumeLog

//SetupResumeLog sets up ConnectionLog for a resumed download
func SetupResumeLog(filename string, length, noOfConn int) error {
	connLog.stats = make([]ConnectionStat, noOfConn)
	barArray := make([]*pb.ProgressBar, noOfConn+1)
	totalbar := pb.New(length).Prefix("Total ")
	lenSub := length / noOfConn
	for i := 0; i < noOfConn; i++ {
		partFilename := "temp/" + filename + "_" + strconv.Itoa(i)
		if _, err := os.Stat(partFilename); err == nil {
			reader, err := ioutil.ReadFile(partFilename)
			if err != nil {
				return err
			}
			header := reader[:16]
			fileBegin := int(binary.LittleEndian.Uint64(header[0:8]))
			fileEnd := int(binary.LittleEndian.Uint64(header[8:16]))
			bar := pb.New(fileEnd - fileBegin).Prefix("Connection " + strconv.Itoa(i+1) + " ")
			for j := 0; j < len(reader)-16; j++ {
				bar.Increment()
				totalbar.Increment()
			}
			customizeBar(bar)
			connLog.stats[i] = ConnectionStat{connectionIndex: i, pbar: bar}
			barArray[i] = bar
		} else {
			fileBegin := lenSub * i
			fileEnd := lenSub * (i + 1)
			if i == noOfConn-1 {
				fileEnd = length
			}
			bar := pb.New(fileEnd - fileBegin).Prefix("Connection " + strconv.Itoa(i+1) + " ")
			customizeBar(bar)
			connLog.stats[i] = ConnectionStat{connectionIndex: i, pbar: bar}
			barArray[i] = bar
		}
	}
	customizeBar(totalbar)
	connLog.totalbar = totalbar
	barArray[noOfConn] = totalbar
	var err error
	connLog.pool, err = pb.StartPool(barArray...)
	if err != nil {
		return err
	}
	return nil
}
开发者ID:prashant-agarwala,项目名称:grozilla,代码行数:46,代码来源:log.go

示例13: main

func main() {
	runClean := flag.Bool("cleanup", false, "Cleanup merged branches")
	noUpdate := flag.Bool("no-update", false, "Skip updating repositories")
	flag.Parse()

	if len(flag.Arg(0)) == 0 {
		fmt.Println("ERROR: You have to specify the directory with repositiories to update.")
		os.Exit(1)
	}

	errors := ""

	u := api.Updater{}
	u.DirHandler = &git.GitHandler{Dir: flag.Arg(0)}

	if err := u.DirHandler.Prepare(); err != nil {
		errors += fmt.Sprintf("Pre-update errors:\n%s", err)
	}

	bar := pb.New(len(u.DirHandler.Repositories()))
	bar.ShowTimeLeft = false
	bar.ShowSpeed = false
	bar.Start()

	completeFunc := func() error {
		bar.Increment()
		return nil
	}

	if !*noUpdate {
		fmt.Fprintf(os.Stdout, "Updating repositories ...\n")
		if err := u.DirHandler.Update(completeFunc); err != nil {
			errors += fmt.Sprintf("Post-update errors:\n%s", err)
		}

		bar.FinishPrint(u.DirHandler.Summary())
	}

	if *runClean {
		fmt.Fprintf(os.Stdout, "Cleaning up merged branches ...\n")
		report := ""
		for _, r := range u.DirHandler.Repositories() {
			out, err := git.CleanMergedBranches(r, completeFunc)
			if err != nil {
				errors += fmt.Sprintf("\n%s\n", err)
			} else {
				report += fmt.Sprintf("\n%s:%s\n", r.Name(), out)
			}
		}
		bar.FinishPrint(report)
	}

	if len(errors) > 0 {
		fmt.Fprintf(os.Stderr, "%s", errors)
		os.Exit(1)
	}
}
开发者ID:soltysh,项目名称:git-sync,代码行数:57,代码来源:git-sync-repos.go

示例14: rangeFunc

func rangeFunc(cmd *cobra.Command, args []string) {
	if len(args) == 0 || len(args) > 2 {
		fmt.Fprintln(os.Stderr, cmd.Usage())
		os.Exit(1)
	}

	k := args[0]
	end := ""
	if len(args) == 2 {
		end = args[1]
	}

	if rangeConsistency == "l" {
		fmt.Println("bench with linearizable range")
	} else if rangeConsistency == "s" {
		fmt.Println("bench with serializable range")
	} else {
		fmt.Fprintln(os.Stderr, cmd.Usage())
		os.Exit(1)
	}

	results = make(chan result)
	requests := make(chan v3.Op, totalClients)
	bar = pb.New(rangeTotal)

	clients := mustCreateClients(totalClients, totalConns)

	bar.Format("Bom !")
	bar.Start()

	for i := range clients {
		wg.Add(1)
		go doRange(clients[i].KV, requests)
	}

	pdoneC := printReport(results)

	go func() {
		for i := 0; i < rangeTotal; i++ {
			opts := []v3.OpOption{v3.WithRange(end)}
			if rangeConsistency == "s" {
				opts = append(opts, v3.WithSerializable())
			}
			op := v3.OpGet(k, opts...)
			requests <- op
		}
		close(requests)
	}()

	wg.Wait()

	bar.Finish()

	close(results)
	<-pdoneC
}
开发者ID:rhuss,项目名称:gofabric8,代码行数:56,代码来源:range.go

示例15: printStatus

func printStatus() {
	count := cap(Buffers[0])
	bar = pb.New(count)

	bar.SetRefreshRate(100 * time.Millisecond)
	bar.ShowCounters = true
	bar.ShowTimeLeft = false

	bar.Start()
}
开发者ID:xthexder,项目名称:rawstreamer,代码行数:10,代码来源:rawplayer.go


注:本文中的github.com/cheggaaa/pb.New函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。