mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-19 05:37:51 +00:00
Integrate new progress bar
This commit is contained in:
parent
2d5549873a
commit
03c6c72df6
@ -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) ->
|
||||
|
@ -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?
|
||||
|
@ -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) ->
|
||||
|
@ -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"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user