Skip to content

Commit

Permalink
tinkering
Browse files Browse the repository at this point in the history
  • Loading branch information
SwampDragons committed Aug 14, 2018
1 parent 67d78ec commit dc0c2d1
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
11 changes: 2 additions & 9 deletions common/progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

// Default progress bar appearance
func GetNewProgressBar(ui *packer.Ui) pb.ProgressBar {
func GetNewProgressBar(ui *packer.Ui, uiWidth int) pb.ProgressBar {
bar := pb.New64(0)
bar.ShowPercent = true
bar.ShowCounters = true
Expand All @@ -29,14 +29,7 @@ func GetNewProgressBar(ui *packer.Ui) pb.ProgressBar {
UI := *ui

// Now check the UI's width to adjust the progress bar
uiWidth := UI.GetMinimumLength() + len("\n")

// If the UI's width is signed, then this interface doesn't really
// benefit from a progress bar
if uiWidth < 0 {
log.Println("Refusing to render progress-bar for unsupported UI.")
return *bar
}
uiWidth = uiWidth + len("\n")
bar.Callback = UI.Message

// Figure out the terminal width if possible
Expand Down
12 changes: 8 additions & 4 deletions common/step_download.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/hex"
"fmt"
"log"
"reflect"
"time"

"github.com/hashicorp/packer/helper/multistep"
Expand Down Expand Up @@ -47,7 +48,7 @@ type StepDownload struct {
Extension string
}

func (s *StepDownload) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
func (s *StepDownload) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
cache := state.Get("cache").(packer.Cache)
ui := state.Get("ui").(packer.Ui)

Expand All @@ -64,7 +65,9 @@ func (s *StepDownload) Run(_ context.Context, state multistep.StateBag) multiste
ui.Say(fmt.Sprintf("Downloading or copying %s", s.Description))

// Get a default-looking progress bar and connect it to the ui.
bar := GetNewProgressBar(&ui)
myConfig := reflect.Indirect(reflect.ValueOf(state.Get("config")))
packerConf := myConfig.FieldByName("PackerConfig").Interface().(PackerConfig)
bar := GetNewProgressBar(&ui, len(packerConf.PackerBuildName)+len("==> : \n")) // this is stolen from ui.Message's prefix function

// First try to use any already downloaded file
// If it fails, proceed to regular download logic
Expand Down Expand Up @@ -145,8 +148,9 @@ func (s *StepDownload) download(config *DownloadConfig, state multistep.StateBag
var path string
ui := state.Get("ui").(packer.Ui)

// Get a default-looking progress bar and connect it to the ui.
bar := GetNewProgressBar(&ui)
myConfig := reflect.Indirect(reflect.ValueOf(state.Get("config")))
packerConf := myConfig.FieldByName("PackerConfig").Interface().(PackerConfig)
bar := GetNewProgressBar(&ui, len(packerConf.PackerBuildName)+len("==> : \n")) // this is stolen from ui.Message's prefix function

// Create download client with config and progress bar
download := NewDownloadClient(config, bar)
Expand Down
4 changes: 2 additions & 2 deletions provisioner/file/provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (p *Provisioner) ProvisionDownload(ui packer.Ui, comm packer.Communicator)
defer f.Close()

// Get a default progress bar
pb := common.GetNewProgressBar(&ui)
pb := common.GetNewProgressBar(&ui, 10)
bar := pb.Start()
defer bar.Finish()

Expand Down Expand Up @@ -177,7 +177,7 @@ func (p *Provisioner) ProvisionUpload(ui packer.Ui, comm packer.Communicator) er
}

// Get a default progress bar
pb := common.GetNewProgressBar(&ui)
pb := common.GetNewProgressBar(&ui, 10)
bar := pb.Start()
defer bar.Finish()

Expand Down
2 changes: 1 addition & 1 deletion vendor/vendor.json
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@
"revisionTime": "2018-02-10T03:43:46Z"
},
{
"checksumSHA1": "Lf3uUXTkKK5DJ37BxQvxO1Fq+K8=",
"checksumSHA1": "dvabztWVQX8f6oMLRyv4dLH+TGY=",
"comment": "v1.0.0-3-g6d21280",
"path": "github.com/davecgh/go-spew/spew",
"revision": "346938d642f2ec3594ed81d874461961cd0faa76",
Expand Down

0 comments on commit dc0c2d1

Please sign in to comment.