Integrate new progress bar

This commit is contained in:
Juan Cruz Viotti 2015-01-29 14:59:57 -04:00
parent 2d5549873a
commit 03c6c72df6
4 changed files with 16 additions and 16 deletions

View File

@ -4,7 +4,6 @@ async = require('async')
resin = require('resin-sdk')
os = require('os')
visuals = require('resin-cli-visuals')
ProgressBarFormatter = require('progress-bar-formatter')
commandOptions = require('./command-options')
drive = require('../drive/drive')
@ -179,12 +178,12 @@ exports.init =
(confirmed, callback) ->
return done() if not confirmed
bar = new ProgressBarFormatter()
bar = new visuals.widgets.Progress('Writing Device OS')
drive.writeImage params.device, params.image,
progress: not options.quiet
onProgress: (status) ->
console.log("Writing Device OS [#{bar.format(status.percentage / 100)}] #{Math.floor(status.percentage)}% eta #{status.eta}s")
console.log(bar.tick(status.percentage, status.eta))
, callback
], (error) ->

View File

@ -73,20 +73,26 @@ exports.download =
return callback(error)
(callback) ->
console.info("Destination file: #{outputFile}")
console.info("Destination file: #{outputFile}\n")
bar = null
bar = new visuals.widgets.Progress('Downloading Device OS')
time = new Date().getTime()
received = 0
resin.models.os.download osParams, outputFile, callback, (state) ->
return if options.quiet
return if options.quiet or not state?
bar ?= new visuals.widgets.Progress('Downloading device OS', state.total)
newTime = new Date().getTime()
timeDelta = newTime - time
receivedDelta = state.received - received
return if bar.complete or not state?
remaining = state.total - state.received
remainingTicks = remaining / receivedDelta
bar.tick(state.received - received)
received = state.received
eta = Math.floor(remainingTicks * timeDelta)
console.log(bar.tick(state.percent, eta))
time = newTime
], (error) ->
return done(error) if error?

View File

@ -76,11 +76,7 @@ exports.writeImage = (devicePath, imagePath, options = {}, callback = _.noop) ->
imageFileStream
.pipe(progress)
.pipe(deviceFileStream)
# TODO: We should make use of nodewindows.elevate()
# if we get an EPERM error.
.on('error', _.unary(callback))
.on('close', _.unary(callback))
(callback) ->

View File

@ -55,9 +55,8 @@
"mkdirp": "~0.5.0",
"nplugm": "^1.0.1",
"open": "0.0.5",
"progress-bar-formatter": "^2.0.1",
"progress-stream": "^0.5.0",
"resin-cli-visuals": "0.0.2",
"resin-cli-visuals": "0.0.3",
"resin-sdk": "git+https://git@github.com/resin-io/resin-sdk.git",
"underscore.string": "~2.4.0"
}