diff --git a/aptly/interfaces.go b/aptly/interfaces.go index b6535dbf..c98395b6 100644 --- a/aptly/interfaces.go +++ b/aptly/interfaces.go @@ -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 diff --git a/cmd/publish_snapshot.go b/cmd/publish_snapshot.go index 87549c8e..bc327702 100644 --- a/cmd/publish_snapshot.go +++ b/cmd/publish_snapshot.go @@ -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 } diff --git a/console/progress.go b/console/progress.go index bdbc3553..772be48d 100644 --- a/console/progress.go +++ b/console/progress.go @@ -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 diff --git a/debian/publish.go b/debian/publish.go index 43695fa1..4d72435d 100644 --- a/debian/publish.go +++ b/debian/publish.go @@ -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 { diff --git a/debian/publish_test.go b/debian/publish_test.go index cb53198b..6770c56c 100644 --- a/debian/publish_test.go +++ b/debian/publish_test.go @@ -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) diff --git a/system/t06_publish/PublishSnapshot13Test_gold b/system/t06_publish/PublishSnapshot13Test_gold index 0cd0786d..848cd407 100644 --- a/system/t06_publish/PublishSnapshot13Test_gold +++ b/system/t06_publish/PublishSnapshot13Test_gold @@ -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. diff --git a/system/t06_publish/PublishSnapshot14Test_gold b/system/t06_publish/PublishSnapshot14Test_gold index 09708965..8505db9d 100644 --- a/system/t06_publish/PublishSnapshot14Test_gold +++ b/system/t06_publish/PublishSnapshot14Test_gold @@ -1 +1,2 @@ +Loading packages... ERROR: unable to publish: snapshot is empty diff --git a/system/t06_publish/PublishSnapshot15Test_gold b/system/t06_publish/PublishSnapshot15Test_gold index 05d4489b..e0fafd8c 100644 --- a/system/t06_publish/PublishSnapshot15Test_gold +++ b/system/t06_publish/PublishSnapshot15Test_gold @@ -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. diff --git a/system/t06_publish/PublishSnapshot16Test_gold b/system/t06_publish/PublishSnapshot16Test_gold index 8dcc3594..8c57a81c 100644 --- a/system/t06_publish/PublishSnapshot16Test_gold +++ b/system/t06_publish/PublishSnapshot16Test_gold @@ -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: diff --git a/system/t06_publish/PublishSnapshot17Test_gold b/system/t06_publish/PublishSnapshot17Test_gold index 3e1ca01c..b5812293 100644 --- a/system/t06_publish/PublishSnapshot17Test_gold +++ b/system/t06_publish/PublishSnapshot17Test_gold @@ -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: diff --git a/system/t06_publish/PublishSnapshot1Test_gold b/system/t06_publish/PublishSnapshot1Test_gold index f0d80dad..c5129aed 100644 --- a/system/t06_publish/PublishSnapshot1Test_gold +++ b/system/t06_publish/PublishSnapshot1Test_gold @@ -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: diff --git a/system/t06_publish/PublishSnapshot2Test_gold b/system/t06_publish/PublishSnapshot2Test_gold index bbcb32f2..684a8a5f 100644 --- a/system/t06_publish/PublishSnapshot2Test_gold +++ b/system/t06_publish/PublishSnapshot2Test_gold @@ -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: diff --git a/system/t06_publish/PublishSnapshot3Test_gold b/system/t06_publish/PublishSnapshot3Test_gold index 03355c52..01578782 100644 --- a/system/t06_publish/PublishSnapshot3Test_gold +++ b/system/t06_publish/PublishSnapshot3Test_gold @@ -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: diff --git a/system/t06_publish/PublishSnapshot4Test_gold b/system/t06_publish/PublishSnapshot4Test_gold index feb7ed31..ca6f235a 100644 --- a/system/t06_publish/PublishSnapshot4Test_gold +++ b/system/t06_publish/PublishSnapshot4Test_gold @@ -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: diff --git a/system/t06_publish/PublishSnapshot5Test_gold b/system/t06_publish/PublishSnapshot5Test_gold index 3f650169..e5b0a8c2 100644 --- a/system/t06_publish/PublishSnapshot5Test_gold +++ b/system/t06_publish/PublishSnapshot5Test_gold @@ -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: