mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-01-11 03:11:50 +00:00
Add publish output progress counting remaining number of packages
This commit is contained in:
committed by
Lorenzo Bolla
parent
3cd168c44d
commit
f09a273ad7
@@ -4,6 +4,8 @@ import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"github.com/aptly-dev/aptly/aptly"
|
||||
)
|
||||
|
||||
// Output represents a safe standard output of task
|
||||
@@ -13,6 +15,13 @@ type Output struct {
|
||||
output *bytes.Buffer
|
||||
}
|
||||
|
||||
// PublishOutput specific output for publishing api
|
||||
type PublishOutput struct {
|
||||
*Output
|
||||
PublishDetail
|
||||
barType *aptly.BarType
|
||||
}
|
||||
|
||||
// NewOutput creates new output
|
||||
func NewOutput() *Output {
|
||||
return &Output{mu: &sync.Mutex{}, output: &bytes.Buffer{}}
|
||||
@@ -54,20 +63,43 @@ func (t *Output) Flush() {
|
||||
}
|
||||
|
||||
// InitBar is needed for progress compatibility
|
||||
func (t *Output) InitBar(count int64, isBytes bool) {
|
||||
func (t *Output) InitBar(count int64, isBytes bool, barType aptly.BarType) {
|
||||
// Not implemented
|
||||
}
|
||||
|
||||
// InitBar publish output specific
|
||||
func (t *PublishOutput) InitBar(count int64, isBytes bool, barType aptly.BarType) {
|
||||
t.barType = &barType
|
||||
if barType == aptly.BarPublishGeneratePackageFiles {
|
||||
t.TotalNumberOfPackages = count
|
||||
t.RemainingNumberOfPackages = count
|
||||
t.Store(t)
|
||||
}
|
||||
}
|
||||
|
||||
// ShutdownBar is needed for progress compatibility
|
||||
func (t *Output) ShutdownBar() {
|
||||
// Not implemented
|
||||
}
|
||||
|
||||
// ShutdownBar publish output specific
|
||||
func (t *PublishOutput) ShutdownBar() {
|
||||
t.barType = nil
|
||||
}
|
||||
|
||||
// AddBar is needed for progress compatibility
|
||||
func (t *Output) AddBar(count int) {
|
||||
// Not implemented
|
||||
}
|
||||
|
||||
// AddBar publish output specific
|
||||
func (t *PublishOutput) AddBar(count int) {
|
||||
if t.barType != nil && *t.barType == aptly.BarPublishGeneratePackageFiles {
|
||||
t.RemainingNumberOfPackages--
|
||||
t.Store(t)
|
||||
}
|
||||
}
|
||||
|
||||
// SetBar sets current position for progress bar
|
||||
func (t *Output) SetBar(count int) {
|
||||
// Not implemented
|
||||
|
||||
@@ -12,6 +12,13 @@ type Detail struct {
|
||||
atomic.Value
|
||||
}
|
||||
|
||||
// PublishDetail represents publish task details
|
||||
type PublishDetail struct {
|
||||
*Detail
|
||||
TotalNumberOfPackages int64
|
||||
RemainingNumberOfPackages int64
|
||||
}
|
||||
|
||||
// Process is a function implementing the actual task logic
|
||||
type Process func(out *Output, detail *Detail) error
|
||||
|
||||
|
||||
Reference in New Issue
Block a user