Fixed the progress bars ^_^
parent
35e473ad4b
commit
7fa4e054f3
3
go.mod
3
go.mod
|
@ -9,7 +9,7 @@ require (
|
|||
github.com/blang/semver v3.5.0+incompatible
|
||||
github.com/c4milo/gotoolkit v0.0.0-20170318115440-bcc06269efa9 // indirect
|
||||
github.com/cenkalti/backoff v2.2.1+incompatible
|
||||
github.com/cheggaaa/pb v1.0.27
|
||||
github.com/cheggaaa/pb/v3 v3.0.1
|
||||
github.com/cloudfoundry-attic/jibber_jabber v0.0.0-20151120183258-bcc4c8345a21
|
||||
github.com/cloudfoundry/jibber_jabber v0.0.0-20151120183258-bcc4c8345a21 // indirect
|
||||
github.com/docker/docker v1.13.1 // indirect
|
||||
|
@ -35,7 +35,6 @@ require (
|
|||
github.com/johanneswuerbach/nfsexports v0.0.0-20181204082207-1aa528dcb345
|
||||
github.com/libvirt/libvirt-go v3.4.0+incompatible
|
||||
github.com/machine-drivers/docker-machine-driver-vmware v0.1.1
|
||||
github.com/mattn/go-colorable v0.1.2 // indirect
|
||||
github.com/mattn/go-isatty v0.0.8
|
||||
github.com/mitchellh/go-ps v0.0.0-20170309133038-4fdf99ab2936
|
||||
github.com/moby/hyperkit v0.0.0-20171020124204-a12cd7250bcd
|
||||
|
|
4
go.sum
4
go.sum
|
@ -33,6 +33,8 @@ github.com/Sirupsen/logrus v0.0.0-20170822132746-89742aefa4b2 h1:k1A7eIeUk6rnX2y
|
|||
github.com/Sirupsen/logrus v0.0.0-20170822132746-89742aefa4b2/go.mod h1:rmk17hk6i8ZSAJkSDa7nOxamrG+SP4P0mm+DAvExv4U=
|
||||
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d h1:G0m3OIz70MZUWq3EgK3CesDbo8upS2Vm9/P3FtgI+Jk=
|
||||
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
|
||||
github.com/VividCortex/ewma v1.1.1 h1:MnEK4VOv6n0RSY4vtRe3h11qjxL3+t0B8yOL8iMXdcM=
|
||||
github.com/VividCortex/ewma v1.1.1/go.mod h1:2Tkkvm3sRDVXaiyucHiACn4cqf7DpdyLvmxzcbUokwA=
|
||||
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c=
|
||||
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
|
||||
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
|
||||
|
@ -59,6 +61,8 @@ github.com/cespare/prettybench v0.0.0-20150116022406-03b8cfe5406c/go.mod h1:Xe6Z
|
|||
github.com/chai2010/gettext-go v0.0.0-20160711120539-c6fed771bfd5/go.mod h1:/iP1qXHoty45bqomnu2LM+VVyAEdWN+vtSHGlQgyxbw=
|
||||
github.com/cheggaaa/pb v1.0.27 h1:wIkZHkNfC7R6GI5w7l/PdAdzXzlrbcI3p8OAlnkTsnc=
|
||||
github.com/cheggaaa/pb v1.0.27/go.mod h1:pQciLPpbU0oxA0h+VJYYLxO+XeDQb5pZijXscXHm81s=
|
||||
github.com/cheggaaa/pb/v3 v3.0.1 h1:m0BngUk2LuSRYdx4fujDKNRXNDpbNCfptPfVT2m6OJY=
|
||||
github.com/cheggaaa/pb/v3 v3.0.1/go.mod h1:SqqeMF/pMOIu3xgGoxtPYhMNQP258xE4x/XRTYua+KU=
|
||||
github.com/client9/misspell v0.0.0-20170928000206-9ce5d979ffda/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||
github.com/cloudflare/cfssl v0.0.0-20180726162950-56268a613adf/go.mod h1:yMWuSON2oQp+43nFtAV/uvKQIFpSPerB57DCt9t8sSA=
|
||||
|
|
|
@ -21,13 +21,11 @@ limitations under the License.
|
|||
package util
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
|
||||
"github.com/cheggaaa/pb"
|
||||
"github.com/golang/glog"
|
||||
"github.com/cheggaaa/pb/v3"
|
||||
"github.com/hashicorp/go-getter"
|
||||
)
|
||||
|
||||
|
@ -35,8 +33,7 @@ var defaultProgressBar getter.ProgressTracker = &progressBar{}
|
|||
|
||||
type progressBar struct {
|
||||
lock sync.Mutex
|
||||
pool *pb.Pool
|
||||
pbs int
|
||||
progress *pb.ProgressBar
|
||||
}
|
||||
|
||||
// TrackProgress instantiates a new progress bar that will
|
||||
|
@ -45,38 +42,25 @@ type progressBar struct {
|
|||
func (cpb *progressBar) TrackProgress(src string, currentSize, totalSize int64, stream io.ReadCloser) io.ReadCloser {
|
||||
cpb.lock.Lock()
|
||||
defer cpb.lock.Unlock()
|
||||
|
||||
if cpb.pool == nil {
|
||||
cpb.pool = pb.NewPool()
|
||||
if err := cpb.pool.Start(); err != nil {
|
||||
glog.Errorf("pool start: %v", err)
|
||||
}
|
||||
if cpb.progress == nil {
|
||||
cpb.progress = pb.New64(totalSize)
|
||||
}
|
||||
tmpl := `{{ string . "filePath" }} {{ bar . "-" "█" (cycle . "↖" "↗" "↘" "↙" ) "." "-"}} {{speed . }} {{percent .}} {{ rtime . " ETA - %s"}} {{ etime . " Elapsed - %s"}}`
|
||||
p := pb.ProgressBarTemplate(tmpl).Start64(totalSize)
|
||||
p.Set("filePath", filepath.Base(src))
|
||||
p.SetCurrent(currentSize)
|
||||
p.Set(pb.Bytes, true)
|
||||
|
||||
p := pb.New64(totalSize)
|
||||
p.Set64(currentSize)
|
||||
p.SetUnits(pb.U_BYTES)
|
||||
p.Prefix(fmt.Sprintf(" %s:", filepath.Base(src)))
|
||||
// Just a hair less than 80 (standard terminal width) for aesthetics & pasting into docs
|
||||
p.SetWidth(78)
|
||||
cpb.pool.Add(p)
|
||||
reader := p.NewProxyReader(stream)
|
||||
p.SetWidth(79)
|
||||
barReader := p.NewProxyReader(stream)
|
||||
|
||||
cpb.pbs++
|
||||
return &readCloser{
|
||||
Reader: reader,
|
||||
Reader: barReader,
|
||||
close: func() error {
|
||||
cpb.lock.Lock()
|
||||
defer cpb.lock.Unlock()
|
||||
|
||||
p.Finish()
|
||||
cpb.pbs--
|
||||
if cpb.pbs <= 0 {
|
||||
if err := cpb.pool.Stop(); err != nil {
|
||||
glog.Errorf("pool stop: %v", err)
|
||||
}
|
||||
cpb.pool = nil
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue