mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-04-19 19:28:22 +00:00
Progress during publishing.
This commit is contained in:
@@ -48,6 +48,8 @@ type Progress interface {
|
||||
Start()
|
||||
// Shutdown shuts down progress display
|
||||
Shutdown()
|
||||
// Flush returns when all queued messages are sent
|
||||
Flush()
|
||||
// InitBar starts progressbar for count bytes or count items
|
||||
InitBar(count int64, isBytes bool)
|
||||
// ShutdownBar stops progress bar and hides it
|
||||
|
||||
@@ -83,7 +83,7 @@ func aptlyPublishSnapshot(cmd *commander.Command, args []string) error {
|
||||
}
|
||||
|
||||
packageCollection := debian.NewPackageCollection(context.database)
|
||||
err = published.Publish(context.packagePool, context.publishedStorage, packageCollection, signer)
|
||||
err = published.Publish(context.packagePool, context.publishedStorage, packageCollection, signer, context.progress)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to publish: %s", err)
|
||||
}
|
||||
@@ -97,15 +97,15 @@ func aptlyPublishSnapshot(cmd *commander.Command, args []string) error {
|
||||
prefix += "/"
|
||||
}
|
||||
|
||||
fmt.Printf("\nSnapshot %s has been successfully published.\nPlease setup your webserver to serve directory '%s' with autoindexing.\n",
|
||||
context.progress.Printf("\nSnapshot %s has been successfully published.\nPlease setup your webserver to serve directory '%s' with autoindexing.\n",
|
||||
snapshot.Name, context.publishedStorage.PublicPath())
|
||||
fmt.Printf("Now you can add following line to apt sources:\n")
|
||||
fmt.Printf(" deb http://your-server/%s %s %s\n", prefix, distribution, component)
|
||||
context.progress.Printf("Now you can add following line to apt sources:\n")
|
||||
context.progress.Printf(" deb http://your-server/%s %s %s\n", prefix, distribution, component)
|
||||
if utils.StrSliceHasItem(published.Architectures, "source") {
|
||||
fmt.Printf(" deb-src http://your-server/%s %s %s\n", prefix, distribution, component)
|
||||
context.progress.Printf(" deb-src http://your-server/%s %s %s\n", prefix, distribution, component)
|
||||
}
|
||||
fmt.Printf("Don't forget to add your GPG key to apt with apt-key.\n")
|
||||
fmt.Printf("\nYou can also use `aptly serve` to publish your repositories over HTTP quickly.\n")
|
||||
context.progress.Printf("Don't forget to add your GPG key to apt with apt-key.\n")
|
||||
context.progress.Printf("\nYou can also use `aptly serve` to publish your repositories over HTTP quickly.\n")
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -13,11 +13,13 @@ const (
|
||||
codeProgress
|
||||
codeHideProgress
|
||||
codeStop
|
||||
codeFlush
|
||||
)
|
||||
|
||||
type printTask struct {
|
||||
code int
|
||||
message string
|
||||
reply chan bool
|
||||
}
|
||||
|
||||
// Progress is a progress displaying subroutine, it allows to show download and other operations progress
|
||||
@@ -55,6 +57,13 @@ func (p *Progress) Shutdown() {
|
||||
<-p.stopped
|
||||
}
|
||||
|
||||
// Flush waits for all queued messages to be displayed
|
||||
func (p *Progress) Flush() {
|
||||
ch := make(chan bool)
|
||||
p.queue <- printTask{code: codeFlush, reply: ch}
|
||||
<-ch
|
||||
}
|
||||
|
||||
// InitBar starts progressbar for count bytes or count items
|
||||
func (p *Progress) InitBar(count int64, isBytes bool) {
|
||||
if p.bar != nil {
|
||||
@@ -161,6 +170,8 @@ func (p *Progress) worker() {
|
||||
fmt.Print("\r\033[2K")
|
||||
p.barShown = false
|
||||
}
|
||||
case codeFlush:
|
||||
task.reply <- true
|
||||
case codeStop:
|
||||
p.stopped <- true
|
||||
return
|
||||
|
||||
27
debian/publish.go
vendored
27
debian/publish.go
vendored
@@ -93,7 +93,7 @@ func (p *PublishedRepo) Decode(input []byte) error {
|
||||
}
|
||||
|
||||
// Publish publishes snapshot (repository) contents, links package files, generates Packages & Release files, signs them
|
||||
func (p *PublishedRepo) Publish(packagePool aptly.PackagePool, publishedStorage aptly.PublishedStorage, packageCollection *PackageCollection, signer utils.Signer) error {
|
||||
func (p *PublishedRepo) Publish(packagePool aptly.PackagePool, publishedStorage aptly.PublishedStorage, packageCollection *PackageCollection, signer utils.Signer, progress aptly.Progress) error {
|
||||
err := publishedStorage.MkDir(filepath.Join(p.Prefix, "pool"))
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -104,8 +104,12 @@ func (p *PublishedRepo) Publish(packagePool aptly.PackagePool, publishedStorage
|
||||
return err
|
||||
}
|
||||
|
||||
if progress != nil {
|
||||
progress.Printf("Loading packages...\n")
|
||||
}
|
||||
|
||||
// Load all packages
|
||||
list, err := NewPackageListFromRefList(p.snapshot.RefList(), packageCollection, nil)
|
||||
list, err := NewPackageListFromRefList(p.snapshot.RefList(), packageCollection, progress)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to load packages: %s", err)
|
||||
}
|
||||
@@ -126,8 +130,16 @@ func (p *PublishedRepo) Publish(packagePool aptly.PackagePool, publishedStorage
|
||||
|
||||
generatedFiles := map[string]utils.ChecksumInfo{}
|
||||
|
||||
if progress != nil {
|
||||
progress.Printf("Generating metadata files and linking package files...\n")
|
||||
}
|
||||
|
||||
// For all architectures, generate release file
|
||||
for _, arch := range p.Architectures {
|
||||
if progress != nil {
|
||||
progress.InitBar(int64(list.Len()), false)
|
||||
}
|
||||
|
||||
var relativePath string
|
||||
if arch == "source" {
|
||||
relativePath = filepath.Join(p.Component, "source", "Sources")
|
||||
@@ -147,6 +159,9 @@ func (p *PublishedRepo) Publish(packagePool aptly.PackagePool, publishedStorage
|
||||
bufWriter := bufio.NewWriter(packagesFile)
|
||||
|
||||
err = list.ForEach(func(pkg *Package) error {
|
||||
if progress != nil {
|
||||
progress.AddBar(1)
|
||||
}
|
||||
if pkg.MatchesArchitecture(arch) {
|
||||
err = pkg.LinkFromPool(publishedStorage, packagePool, p.Prefix, p.Component)
|
||||
if err != nil {
|
||||
@@ -205,6 +220,9 @@ func (p *PublishedRepo) Publish(packagePool aptly.PackagePool, publishedStorage
|
||||
}
|
||||
generatedFiles[relativePath+".bz2"] = checksumInfo
|
||||
|
||||
if progress != nil {
|
||||
progress.ShutdownBar()
|
||||
}
|
||||
}
|
||||
|
||||
release := make(Stanza)
|
||||
@@ -245,6 +263,11 @@ func (p *PublishedRepo) Publish(packagePool aptly.PackagePool, publishedStorage
|
||||
releaseFilename := releaseFile.Name()
|
||||
releaseFile.Close()
|
||||
|
||||
// Signing files might output to console, so flush progress writer first
|
||||
if progress != nil {
|
||||
progress.Flush()
|
||||
}
|
||||
|
||||
if signer != nil {
|
||||
err = signer.DetachedSign(releaseFilename, releaseFilename+".gpg")
|
||||
if err != nil {
|
||||
|
||||
4
debian/publish_test.go
vendored
4
debian/publish_test.go
vendored
@@ -154,7 +154,7 @@ func (s *PublishedRepoSuite) TestPrefixNormalization(c *C) {
|
||||
}
|
||||
|
||||
func (s *PublishedRepoSuite) TestPublish(c *C) {
|
||||
err := s.repo.Publish(s.packagePool, s.publishedStorage, s.packageCollection, &NullSigner{})
|
||||
err := s.repo.Publish(s.packagePool, s.publishedStorage, s.packageCollection, &NullSigner{}, nil)
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
c.Check(s.repo.Architectures, DeepEquals, []string{"i386"})
|
||||
@@ -191,7 +191,7 @@ func (s *PublishedRepoSuite) TestPublish(c *C) {
|
||||
}
|
||||
|
||||
func (s *PublishedRepoSuite) TestPublishNoSigner(c *C) {
|
||||
err := s.repo.Publish(s.packagePool, s.publishedStorage, s.packageCollection, nil)
|
||||
err := s.repo.Publish(s.packagePool, s.publishedStorage, s.packageCollection, nil, nil)
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
c.Check(filepath.Join(s.publishedStorage.PublicPath(), "ppa/dists/squeeze/Release"), PathExists)
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
Loading packages...
|
||||
Generating metadata files and linking package files...
|
||||
|
||||
Snapshot snap13 has been successfully published.
|
||||
Please setup your webserver to serve directory '${HOME}/.aptly/public' with autoindexing.
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
Loading packages...
|
||||
ERROR: unable to publish: snapshot is empty
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
Loading packages...
|
||||
Generating metadata files and linking package files...
|
||||
|
||||
Snapshot snap15 has been successfully published.
|
||||
Please setup your webserver to serve directory '${HOME}/.aptly/public' with autoindexing.
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
Loading packages...
|
||||
Generating metadata files and linking package files...
|
||||
Signing file '${HOME}/.aptly/public/dists/maverick/Release' with gpg, please enter your passphrase when prompted:
|
||||
Clearsigning file '${HOME}/.aptly/public/dists/maverick/Release' with gpg, please enter your passphrase when prompted:
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
Loading packages...
|
||||
Generating metadata files and linking package files...
|
||||
Signing file '${HOME}/.aptly/public/dists/maverick/Release' with gpg, please enter your passphrase when prompted:
|
||||
Clearsigning file '${HOME}/.aptly/public/dists/maverick/Release' with gpg, please enter your passphrase when prompted:
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
Loading packages...
|
||||
Generating metadata files and linking package files...
|
||||
Signing file '${HOME}/.aptly/public/dists/maverick/Release' with gpg, please enter your passphrase when prompted:
|
||||
Clearsigning file '${HOME}/.aptly/public/dists/maverick/Release' with gpg, please enter your passphrase when prompted:
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
Loading packages...
|
||||
Generating metadata files and linking package files...
|
||||
Signing file '${HOME}/.aptly/public/dists/squeeze/Release' with gpg, please enter your passphrase when prompted:
|
||||
Clearsigning file '${HOME}/.aptly/public/dists/squeeze/Release' with gpg, please enter your passphrase when prompted:
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
Loading packages...
|
||||
Generating metadata files and linking package files...
|
||||
Signing file '${HOME}/.aptly/public/dists/squeeze/Release' with gpg, please enter your passphrase when prompted:
|
||||
Clearsigning file '${HOME}/.aptly/public/dists/squeeze/Release' with gpg, please enter your passphrase when prompted:
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
Loading packages...
|
||||
Generating metadata files and linking package files...
|
||||
Signing file '${HOME}/.aptly/public/dists/squeeze/Release' with gpg, please enter your passphrase when prompted:
|
||||
Clearsigning file '${HOME}/.aptly/public/dists/squeeze/Release' with gpg, please enter your passphrase when prompted:
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
Loading packages...
|
||||
Generating metadata files and linking package files...
|
||||
Signing file '${HOME}/.aptly/public/ppa/smira/dists/squeeze/Release' with gpg, please enter your passphrase when prompted:
|
||||
Clearsigning file '${HOME}/.aptly/public/ppa/smira/dists/squeeze/Release' with gpg, please enter your passphrase when prompted:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user