Progress when downloading single files and when parsing remote mirrors.

This commit is contained in:
Andrey Smirnov
2014-03-07 00:37:06 +04:00
parent 04d6603f38
commit 74c88f3ef6
5 changed files with 37 additions and 0 deletions

View File

@@ -54,6 +54,8 @@ type Progress interface {
ShutdownBar()
// AddBar increments progress for progress bar
AddBar(count int)
// SetBar sets current position for progress bar
SetBar(count int)
// Printf does printf but in safe manner: not overwriting progress bar
Printf(msg string, a ...interface{})
// ColoredPrintf does printf in colored way + newline
@@ -73,4 +75,6 @@ type Downloader interface {
// Shutdown stops downloader after current tasks are finished,
// but doesn't process rest of queue
Shutdown()
// GetProgress returns Progress object
GetProgress() Progress
}

View File

@@ -101,6 +101,13 @@ func (p *Progress) AddBar(count int) {
}
}
// SetBar sets current position for progress bar
func (p *Progress) SetBar(count int) {
if p.bar != nil {
p.bar.Set(count)
}
}
// Printf does printf but in safe manner: not overwriting progress bar
func (p *Progress) Printf(msg string, a ...interface{}) {
p.queue <- printTask{code: codePrint, message: fmt.Sprintf(msg, a...)}

8
debian/remote.go vendored
View File

@@ -342,6 +342,9 @@ func (repo *RemoteRepo) Download(progress aptly.Progress, d aptly.Downloader, pa
}
defer packagesFile.Close()
stat, _ := packagesFile.Stat()
progress.InitBar(stat.Size(), true)
sreader := NewControlFileReader(packagesReader)
for {
@@ -353,6 +356,9 @@ func (repo *RemoteRepo) Download(progress aptly.Progress, d aptly.Downloader, pa
break
}
off, _ := packagesFile.Seek(0, 1)
progress.SetBar(int(off))
var p *Package
if kind == "binary" {
@@ -373,6 +379,8 @@ func (repo *RemoteRepo) Download(progress aptly.Progress, d aptly.Downloader, pa
return err
}
}
progress.ShutdownBar()
}
progress.Printf("Building download queue...\n")

View File

@@ -85,6 +85,11 @@ func (downloader *downloaderImpl) Resume() {
}
}
// GetProgress returns Progress object
func (downloader *downloaderImpl) GetProgress() aptly.Progress {
return downloader.progress
}
// Download starts new download task
func (downloader *downloaderImpl) Download(url string, destination string, result chan<- error) {
downloader.DownloadWithChecksum(url, destination, result, utils.ChecksumInfo{Size: -1}, false)
@@ -211,6 +216,10 @@ func DownloadTempWithChecksum(downloader aptly.Downloader, url string, expected
tempfile := filepath.Join(tempdir, "buffer")
if expected.Size != -1 && downloader.GetProgress() != nil {
downloader.GetProgress().InitBar(expected.Size, true)
}
ch := make(chan error, 1)
downloader.DownloadWithChecksum(url, tempfile, ch, expected, ignoreMismatch)
@@ -219,6 +228,10 @@ func DownloadTempWithChecksum(downloader aptly.Downloader, url string, expected
return nil, err
}
if expected.Size != -1 && downloader.GetProgress() != nil {
downloader.GetProgress().ShutdownBar()
}
file, err := os.Open(tempfile)
if err != nil {
return nil, err

View File

@@ -130,3 +130,8 @@ func (f *FakeDownloader) Pause() {
// Resume does nothing
func (f *FakeDownloader) Resume() {
}
// GetProgress returns Progress object
func (f *FakeDownloader) GetProgress() aptly.Progress {
return nil
}