lib/fog/octocloud/requests/compute/convert_cube.rb
# Download remote file from URL and optionally print progress.
#
# If the progressbar gem is installed it will be automatically used
# to display the download progress, gracefully degrading to a simple
# progress animation otherwise.
#
# @param [String] url file URL
# @param [Boolean] show_progress display progress when true
#
Download remote file from URL and optionally print progress.
If the progressbar gem is installed it will be automatically used
to display the download progress, gracefully degrading to a simple
progress animation otherwise.
Download remote file from URL and optionally print progress . If the progressbar gem is installed it will be automatically used to display the download progress gracefully degrading to a simple progress animation otherwise .
def download_file(url, show_progress = false)
          if show_progress
            pbar = nil
            begin
              require 'progressbar'
            rescue LoadError => e
              Fog::Logger.warning "progressbar rubygem not found. Install it for fancier progress."
              pbar = :noop
            end
            open(
              url,
              :content_length_proc => lambda { |total|
                if pbar != :noop
                  if total && 0 < total
                    pbar = ProgressBar.new("Downloading", total)
                    pbar.file_transfer_mode
                  end
                end
              },
              :progress_proc => lambda { |read_size|
                if pbar != :noop
                  pbar.set read_size if pbar
                else
                  print "\rDownloading... #{"%.2f" % (read_size/1024.0**2)} MB"
                end
              }
            )
          else
            open(url)
          end
        end
def download_file ( url , show_progress = false ) if show_progress pbar = nil begin require 'progressbar' rescue LoadError => e Fog :: Logger . warning "progressbar rubygem not found. Install it for fancier progress." pbar = :noop end open ( url , :content_length_proc => lambda { | total | if pbar != :noop if total && 0 < total pbar = ProgressBar . new ( "Downloading" , total ) pbar . file_transfer_mode end end } , :progress_proc => lambda { | read_size | if pbar != :noop pbar . set read_size if pbar else print "\rDownloading... #{"%.2f" % (read_size/1024.0**2)} MB" end } ) else open ( url ) end end
Download remote file from URL and optionally print progress.
Download remote file from URL and optionally print progress .
url
<not_specific>
show_progress
<not_specific>
<not_specific>
show_progress display progress when true
show_progress display progress when true