Properly accumulate and parse cURL output for progress
This commit is contained in:
parent
05c6379abb
commit
d1e2596ce5
|
@ -42,38 +42,50 @@ module Vagrant
|
||||||
# tell us output so we can parse it out.
|
# tell us output so we can parse it out.
|
||||||
options << { :notify => :stderr }
|
options << { :notify => :stderr }
|
||||||
|
|
||||||
|
progress_data = ""
|
||||||
|
progress_regexp = /(\r(.+?))\r/
|
||||||
|
|
||||||
# Setup the proc that'll receive the real-time data from
|
# Setup the proc that'll receive the real-time data from
|
||||||
# the downloader.
|
# the downloader.
|
||||||
data_proc = Proc.new do |type, data|
|
data_proc = Proc.new do |type, data|
|
||||||
# Type will always be "stderr" because that is the only
|
# Type will always be "stderr" because that is the only
|
||||||
# type of data we're subscribed for notifications.
|
# type of data we're subscribed for notifications.
|
||||||
|
|
||||||
# If the data doesn't start with a \r then it isn't a progress
|
# Accumulate progress_data
|
||||||
# notification, so ignore it.
|
progress_data << data
|
||||||
next if data[0] != "\r"
|
|
||||||
|
|
||||||
# Ignore the first \r and split by whitespace to grab the columns
|
while true
|
||||||
columns = data[1..-1].split(/\s+/)
|
# If we have a full amount of column data (two "\r") then
|
||||||
|
# we report new progress reports. Otherwise, just keep
|
||||||
|
# accumulating.
|
||||||
|
match = progress_regexp.match(progress_data)
|
||||||
|
break if !match
|
||||||
|
data = match[2]
|
||||||
|
progress_data.gsub!(match[1], "")
|
||||||
|
|
||||||
# COLUMN DATA:
|
# Ignore the first \r and split by whitespace to grab the columns
|
||||||
#
|
columns = data[1..-1].split(/\s+/)
|
||||||
# 0 - blank
|
|
||||||
# 1 - % total
|
|
||||||
# 2 - Total size
|
|
||||||
# 3 - % received
|
|
||||||
# 4 - Received size
|
|
||||||
# 5 - % transferred
|
|
||||||
# 6 - Transferred size
|
|
||||||
# 7 - Average download speed
|
|
||||||
# 8 - Average upload speed
|
|
||||||
# 9 - Total time
|
|
||||||
# 10 - Time spent
|
|
||||||
# 11 - Time left
|
|
||||||
# 12 - Current speed
|
|
||||||
|
|
||||||
output = "Progress: #{columns[1]}% (Rate: #{columns[12]}/s, Estimated time remaining: #{columns[11]})"
|
# COLUMN DATA:
|
||||||
@ui.clear_line
|
#
|
||||||
@ui.info(output, :new_line => false)
|
# 0 - blank
|
||||||
|
# 1 - % total
|
||||||
|
# 2 - Total size
|
||||||
|
# 3 - % received
|
||||||
|
# 4 - Received size
|
||||||
|
# 5 - % transferred
|
||||||
|
# 6 - Transferred size
|
||||||
|
# 7 - Average download speed
|
||||||
|
# 8 - Average upload speed
|
||||||
|
# 9 - Total time
|
||||||
|
# 10 - Time spent
|
||||||
|
# 11 - Time left
|
||||||
|
# 12 - Current speed
|
||||||
|
|
||||||
|
output = "Progress: #{columns[1]}% (Rate: #{columns[12]}/s, Estimated time remaining: #{columns[11]})"
|
||||||
|
@ui.clear_line
|
||||||
|
@ui.info(output, :new_line => false)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue