mirror of
https://github.com/chromebrew/chromebrew.git
synced 2026-01-10 07:57:59 -05:00
lib/downloader: Add an option for disabling progress bar (#7116)
* Add `CREW_DOWNLOADER_SHOW_PROGBAR` option * Add `CREW_DOWNLOADER_SHOW_PROGBAR` variable * Change to `CREW_HIDE_PROGBAR` * Bump version
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# Defines common constants used in different parts of crew
|
||||
|
||||
CREW_VERSION = '1.23.18'
|
||||
CREW_VERSION = '1.23.19'
|
||||
|
||||
ARCH_ACTUAL = `uname -m`.chomp
|
||||
# This helps with virtualized builds on aarch64 machines
|
||||
@@ -81,7 +81,7 @@ else
|
||||
end
|
||||
|
||||
# If CREW_USE_CURL environment variable exists use curl in lieu of net/http.
|
||||
CREW_USE_CURL = ENV['CREW_USE_CURL'] == '1'
|
||||
CREW_USE_CURL = ENV['CREW_USE_CURL'].eql?('1')
|
||||
|
||||
# Use an external downloader instead of net/http if CREW_DOWNLOADER is set, see lib/downloader.rb for more info
|
||||
# About the format of the CREW_DOWNLOADER variable, see line 130-133 in lib/downloader.rb
|
||||
@@ -89,6 +89,8 @@ CREW_DOWNLOADER = ( ENV['CREW_DOWNLOADER'].to_s.empty? ) ? nil : ENV['CREW_DOWNL
|
||||
|
||||
# Downloader maximum retry count
|
||||
CREW_DOWNLOADER_RETRY = ( ENV['CREW_DOWNLOADER_RETRY'].to_s.empty? ) ? 3 : ENV['CREW_DOWNLOADER_RETRY'].to_i
|
||||
# show download progress bar or not (only applied when using the default ruby downloader)
|
||||
CREW_HIDE_PROGBAR = ENV['CREW_HIDE_PROGBAR'].eql?('1')
|
||||
|
||||
# set certificate file location for lib/downloader.rb
|
||||
SSL_CERT_FILE = if ENV['SSL_CERT_FILE'].to_s.empty? || !File.exist?(ENV['SSL_CERT_FILE'])
|
||||
|
||||
@@ -133,15 +133,17 @@ def http_downloader (url, filename = File.basename(url), verbose = false)
|
||||
# read file chunks from server, write it to filesystem
|
||||
File.open(filename, 'wb') do |io|
|
||||
response.read_body do |chunk|
|
||||
downloaded_size += chunk.size # record downloaded size, used for showing progress bar
|
||||
if file_size.positive?
|
||||
# calculate downloading progress percentage with the given file size
|
||||
percentage = (downloaded_size / file_size) * 100
|
||||
# show progress bar, file size and progress percentage
|
||||
printf "\r""[%-#{@progBarW}.#{@progBarW}s] %9.9s %3d%%",
|
||||
'#' * ( @progBarW * (percentage / 100) ),
|
||||
human_size(file_size),
|
||||
percentage
|
||||
unless CREW_HIDE_PROGBAR
|
||||
downloaded_size += chunk.size # record downloaded size, used for showing progress bar
|
||||
if file_size.positive?
|
||||
# calculate downloading progress percentage with the given file size
|
||||
percentage = (downloaded_size / file_size) * 100
|
||||
# show progress bar, file size and progress percentage
|
||||
printf "\r""[%-#{@progBarW}.#{@progBarW}s] %9.9s %3d%%",
|
||||
'#' * ( @progBarW * (percentage / 100) ),
|
||||
human_size(file_size),
|
||||
percentage
|
||||
end
|
||||
end
|
||||
io.write(chunk) # write to file
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user