mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-02-21 17:56:57 +00:00
Draw a progress bar for upload progress
Change-Type: patch
This commit is contained in:
parent
db9225f00a
commit
fc5640c79d
@ -1,5 +1,5 @@
|
||||
// Generated by CoffeeScript 1.12.5
|
||||
var Promise, dockerUtils, formatImageName, getBuilderLogPushEndpoint, getBuilderPushEndpoint, getBundleInfo, parseInput, performUpload, pushProgress, uploadLogs, uploadToPromise;
|
||||
var Promise, dockerUtils, formatImageName, getBuilderLogPushEndpoint, getBuilderPushEndpoint, getBundleInfo, parseInput, performUpload, pushProgress, renderProgress, uploadLogs, uploadToPromise;
|
||||
|
||||
Promise = require('bluebird');
|
||||
|
||||
@ -51,6 +51,19 @@ parseInput = Promise.method(function(params, options) {
|
||||
return [appName, options.build, source, image];
|
||||
});
|
||||
|
||||
renderProgress = function(percentage, stepCount) {
|
||||
var _, bar, barCount, spaceCount;
|
||||
if (stepCount == null) {
|
||||
stepCount = 50;
|
||||
}
|
||||
_ = require('lodash');
|
||||
percentage = Math.max(0, Math.min(percentage, 100));
|
||||
barCount = Math.floor(stepCount * percentage / 100);
|
||||
spaceCount = stepCount - barCount;
|
||||
bar = "[" + (_.repeat('=', barCount)) + ">" + (_.repeat(' ', spaceCount)) + "]";
|
||||
return bar + " " + (percentage.toFixed(1)) + "%";
|
||||
};
|
||||
|
||||
pushProgress = function(imageSize, request, logStreams, timeout) {
|
||||
var ansiEscapes, logging, progressReporter;
|
||||
if (timeout == null) {
|
||||
@ -58,7 +71,7 @@ pushProgress = function(imageSize, request, logStreams, timeout) {
|
||||
}
|
||||
logging = require('../utils/logging');
|
||||
ansiEscapes = require('ansi-escapes');
|
||||
logging.logInfo(logStreams, 'Initialising...');
|
||||
logging.logInfo(logStreams, 'Initializing...');
|
||||
return progressReporter = setInterval(function() {
|
||||
var percent, sent;
|
||||
sent = request.req.connection._bytesDispatched;
|
||||
@ -70,7 +83,7 @@ pushProgress = function(imageSize, request, logStreams, timeout) {
|
||||
process.stdout.write(ansiEscapes.cursorUp(1));
|
||||
process.stdout.clearLine();
|
||||
process.stdout.cursorTo(0);
|
||||
return logging.logInfo(logStreams, "Uploaded " + (percent.toFixed(1)) + "%");
|
||||
return logging.logInfo(logStreams, renderProgress(percent));
|
||||
}, timeout);
|
||||
};
|
||||
|
||||
|
@ -31,11 +31,21 @@ parseInput = Promise.method (params, options) ->
|
||||
|
||||
return [appName, options.build, source, image]
|
||||
|
||||
# Builds and returns a Docker-like progress bar like this:
|
||||
# [==================================> ] 64%
|
||||
renderProgress = (percentage, stepCount = 50) ->
|
||||
_ = require('lodash')
|
||||
percentage = Math.max(0, Math.min(percentage, 100))
|
||||
barCount = stepCount * percentage // 100
|
||||
spaceCount = stepCount - barCount
|
||||
bar = "[#{_.repeat('=', barCount)}>#{_.repeat(' ', spaceCount)}]"
|
||||
return "#{bar} #{percentage.toFixed(1)}%"
|
||||
|
||||
pushProgress = (imageSize, request, logStreams, timeout = 250) ->
|
||||
logging = require('../utils/logging')
|
||||
ansiEscapes = require('ansi-escapes')
|
||||
|
||||
logging.logInfo(logStreams, 'Initialising...')
|
||||
logging.logInfo(logStreams, 'Initializing...')
|
||||
progressReporter = setInterval ->
|
||||
sent = request.req.connection._bytesDispatched
|
||||
percent = (sent / imageSize) * 100
|
||||
@ -45,7 +55,7 @@ pushProgress = (imageSize, request, logStreams, timeout = 250) ->
|
||||
process.stdout.write(ansiEscapes.cursorUp(1))
|
||||
process.stdout.clearLine()
|
||||
process.stdout.cursorTo(0)
|
||||
logging.logInfo(logStreams, "Uploaded #{percent.toFixed(1)}%")
|
||||
logging.logInfo(logStreams, renderProgress(percent))
|
||||
, timeout
|
||||
|
||||
getBundleInfo = (options) ->
|
||||
|
Loading…
x
Reference in New Issue
Block a user