[Rubygems-developers] progressbar for remote installs

Henrik Horneber ryco at gmx.net
Fri Oct 8 13:29:31 EDT 2004


I sent a similar version yesterday evening, but since I was not on the 
list, it got stuck on moderator approval, pls ignore that message, if it 
ever arrives. Stupid me. Anyway:

Remote installations take some time, when you have p2p using flatmates 
like I have. In order to see the progress of the download, I hacked 
remote_installer.rb to include a progressbar, from the 'progressbar' gem 
(d'uh).  It's a pretty straight adoption of code from the open-uri docs.

Nevertheless, beware, I am a nuby.

I thought I'd share it, just in case anyone is interested. :)

Just wondering, because it was pretty esay to implement after I found 
the right section of code and the right file, why there was no progress 
bar in the first place. Some license issues? UI Code too far down in the 
application? Am I the only one who likes progressbars? :)

gems are a great way to handle libraries, thanks for the effort!

-------------- next part --------------
--- remote_installer_old.rb	2004-10-07 18:35:03.250000000 +0200
+++ remote_installer.rb	2004-10-08 18:51:29.250000000 +0200
@@ -219,9 +219,25 @@
     def fetch( uri_str )
       require 'rubygems/open-uri'
-      open(uri_str, :proxy => @http_proxy) do |input|
-        input.read
+      require 'progressbar'
+      pbar = nil
+      opts = {
+        :content_length_proc => lambda {|total_size|
+          if total_size && 0 < total_size
+            pbar = ProgressBar.new("transfer", total_size)          
+          end
+        },
+        :progress_proc => lambda {|fetched_size|
+          pbar.set fetched_size if pbar
+        },
+	:proxy => @http_proxy
+      }
+      data = nil
+      open(uri_str, opts ) do |input|
+        data = input.read
+      pbar.finish if pbar
+      data
     def new_installer(gem)

More information about the Rubygems-developers mailing list