[Rubygems-developers] progressbar for remote installs
Austin Ziegler
halostatue at gmail.com
Fri Oct 8 14:09:39 EDT 2004
A couple of things: I'm not sure that this belongs as a core part of
the code, but perhaps as a wrapper, because the progress bar used by
the text form will not be that used by a GUI. The way to handle this
is similar to the way that I did it in Archive::Tar::Minitar or in
RTidy/CD (not a great example, but it has a dual UI), as a callback.
You've got the callback -- sort of -- in the call to open(), but it
should be passed as a parameter to fetch().
-austin
On Fri, 08 Oct 2004 19:29:31 +0200, Henrik Horneber <ryco at gmx.net> wrote:
> Hi!
>
> 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!
>
> regards,
> Henrik
>
>
> --- 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
> end
> + pbar.finish if pbar
> + data
> end
>
> def new_installer(gem)
>
>
> _______________________________________________
> Rubygems-developers mailing list
> Rubygems-developers at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rubygems-developers
>
>
>
--
Austin Ziegler * halostatue at gmail.com
* Alternate: austin at halostatue.ca
: as of this email, I have [ 6 ] Gmail invitations
More information about the Rubygems-developers
mailing list