Refactoring: new packages console, http, Progress is interface.

This commit is contained in:
Andrey Smirnov
2014-02-19 13:08:55 +04:00
parent bd119dbfed
commit 2d589bd23d
18 changed files with 193 additions and 138 deletions
+29 -1
View File
@@ -4,6 +4,7 @@ package aptly
import (
"github.com/smira/aptly/utils"
"io"
"os"
)
@@ -13,7 +14,7 @@ import (
type PackagePool interface {
Path(filename string, hashMD5 string) (string, error)
RelativePath(filename string, hashMD5 string) (string, error)
FilepathList(progress *utils.Progress) ([]string, error)
FilepathList(progress Progress) ([]string, error)
Remove(path string) (size int64, err error)
}
@@ -26,3 +27,30 @@ type PublishedStorage interface {
LinkFromPool(prefix string, component string, poolDirectory string, sourcePool PackagePool, sourcePath string) (string, error)
ChecksumsForFile(path string) (utils.ChecksumInfo, error)
}
// Progress is a progress displaying entity, it allows progress bars & simple prints
type Progress interface {
// Writer interface to support progress bar ticking
io.Writer
// Start makes progress start its work
Start()
// Shutdown shuts down progress display
Shutdown()
// InitBar starts progressbar for count bytes or count items
InitBar(count int64, isBytes bool)
// ShutdownBar stops progress bar and hides it
ShutdownBar()
// AddBar increments progress for progress bar
AddBar(count int)
// Printf does printf but in safe manner: not overwriting progress bar
Printf(msg string, a ...interface{})
}
// Downloader is parallel HTTP fetcher
type Downloader interface {
Download(url string, destination string, result chan<- error)
DownloadWithChecksum(url string, destination string, result chan<- error, expected utils.ChecksumInfo, ignoreMismatch bool)
Pause()
Resume()
Shutdown()
}