wget : Add progress bar to non verbose mode

by

Check this bug report for the problem I had with default mode.

wget has four levels of verbosity which are described as below in its man page —

-d --debug
Turn on debug output, meaning various information important to the developers of Wget if it does not work properly. Your system administrator may have chosen to compile Wget without debug support, in which case -d will not work. Please note that compiling with debug support is always safe---Wget compiled with the debug support will not print any debug info unless requested with -d.

-q --quiet
Turn off Wget's output.

-v --verbose
Turn on verbose output, with all the available data. The default output is verbose.

-nv –no-verbose

Turn off verbose without being completely quiet (use -q for that), which means that error messages and basic information still get
printed.

The problem with these is that the verbose mode prints too much info, quiet prints nothing and non-verbose prints info which is not useful in any way.


By default the non-verbose mode prints the output as follows —

$ wget -nv ftp://ftp.gnu.org/gnu/wget/wget-1.12.tar.bz2
2009-11-26 22:16:40 URL: ftp://ftp.gnu.org/gnu/wget/wget-1.12.tar.bz2 [1609032] -> "wget-1.12.tar.bz2" [1]

I wanted the non-verbose mode to print a progress bar for reasons which are similar to those mentioned in this bug report. The only difference being that instead of Gentoo, I use Arch and pacman. So, I took the diff provided in the bug report modified it a bit to work with v1.12 and also made a PKGBUILD for my Arch use. I am attaching both of them below. After using this patch the output with the -nv option is as follows —

$ wget -nv ftp://ftp.gnu.org/gnu/wget/wget-1.12.tar.bz2
38% [=============> ] 614,880 79.5K/s eta 13s

Problem solved 🙂

Patch — Save this as wget_nv_pbar.diff in the same folder as the PKGBUILD if you are building in Arch using the PKGBUILD given below. If you use normal patch, you can do it however you want 🙂

#Created by Chinmay Kamat <chinmaykamat@gmail.com>
--- wget-1.12.orig/src/main.c	2009-09-22 08:33:11.000000000 +0530
+++ wget-1.12/src/main.c	2009-11-26 12:21:15.156859000 +0530
@@ -1140,7 +1140,7 @@

   /* Initialize progress.  Have to do this after the options are
      processed so we know where the log file is.  */
-  if (opt.verbose)
+  if (!opt.quiet)
     set_progress_implementation (opt.progress_type);

   /* Fill in the arguments.  */

--- wget-1.12.orig/src/progress.c	2009-09-22 08:19:32.000000000 +0530
+++ wget-1.12/src/progress.c	2009-11-26 12:53:11.309295000 +0530
@@ -291,7 +291,7 @@
          been retrieved.  12.8% will round to 12% because the 13% mark
          has not yet been reached.  100% is only shown when done.  */
       int percentage = 100.0 * bytes_displayed / dp->total_length;
-      logprintf (LOG_VERBOSE, "%3d%%", percentage);
+      logprintf (LOG_NOTQUIET, "%3d%%", percentage);
     }

   {
@@ -325,7 +325,7 @@
           wgint bytes_sofar = bytes_displayed - dp->initial_length;
           double eta = dltime * bytes_remaining / bytes_sofar;
           if (eta < INT_MAX - 1)
-            logprintf (LOG_VERBOSE, " %s",
+            logprintf (LOG_NOTQUIET, " %s",
                        eta_to_human_short ((int) (eta + 0.5), true));
         }
     }
@@ -333,10 +333,10 @@
     {
       /* When done, print the total download time */
       if (dltime >= 10)
-        logprintf (LOG_VERBOSE, "=%s",
+        logprintf (LOG_NOTQUIET, "=%s",
                    eta_to_human_short ((int) (dltime + 0.5), true));
       else
-        logprintf (LOG_VERBOSE, "=%ss", print_decimal (dltime));
+        logprintf (LOG_NOTQUIET, "=%ss", print_decimal (dltime));
     }
 }

@@ -652,7 +652,7 @@
   create_image (bp, dltime, true);
   display_image (bp->buffer);

-  logputs (LOG_VERBOSE, "\n\n");
+  logputs (LOG_NOTQUIET, "\n\n");

   xfree (bp->buffer);
   xfree (bp);
@@ -1071,8 +1071,8 @@
 display_image (char *buf)
 {
   bool old = log_set_save_context (false);
-  logputs (LOG_VERBOSE, "\r");
-  logputs (LOG_VERBOSE, buf);
+  logputs (LOG_NOTQUIET, "\r");
+  logputs (LOG_NOTQUIET, buf);
   log_set_save_context (old);
 }

--- wget-1.12.orig/src/retr.c	2009-09-04 22:01:54.000000000 +0530
+++ wget-1.12/src/retr.c	2009-11-26 12:21:15.167860000 +0530
@@ -234,7 +234,7 @@
   if (flags & rb_skip_startpos)
     skip = startpos;

-  if (opt.verbose)
+  if (!opt.quiet)
     {
       /* If we're skipping STARTPOS bytes, pass 0 as the INITIAL
          argument to progress_create because the indicator doesn't

PKGBUILD

# $Id: PKGBUILD 52882 2009-09-23 03:39:20Z allan $
# Maintainer: Allan McRae <allan@archlinux.org>
# Contributor: Judd Vinet <jvinet@zeroflux.org>
# Modified By:  Chinmay Kamat <chinmaykamat@gmail.com>
pkgname=wget
pkgver=1.12
pkgrel=1
pkgdesc="A network utility to retrieve files from the Web"
arch=('i686' 'x86_64')
url="http://www.gnu.org/software/wget/wget.html"
license=('GPL3')
groups=('base')
depends=('glibc' 'openssl')
optdepends=('ca-certificates: HTTPS downloads')
backup=('etc/wgetrc')
install=wget.install
source=(ftp://ftp.gnu.org/gnu/$pkgname/$pkgname-$pkgver.tar.gz)
md5sums=('141461b9c04e454dc8933c9d1f2abf83')

build() {
  patch -Np0 -i $startdir/wget_nv_pbar.diff || return 1
  cd ${srcdir}/$pkgname-$pkgver
  ./configure --prefix=/usr --sysconfdir=/etc
  make || return 1
  make DESTDIR=${pkgdir} install
}

Get the wget.install from here.

Advertisements

8 Responses to “wget : Add progress bar to non verbose mode”

  1. Jitesh Says:

    cool stuff this!
    you atleast have one user in me for this patch. I would be really happy to see this upstream with a “–progress-only” kind of an option.
    (If you need a volunteer you can always ping me)

  2. Amod Says:

    Bharich !!! 🙂

    CDK turning into a h4x0r 😀

  3. Gabriel Casella (gbc921) Says:

    Great work man! Really useful with pacman!

    I just made it up-to-date again, using the wget-git package from aur [1].
    If you want to publish the PKGBUILD on AUR [2] feel free to do so, as you came with the idea on the first place. Otherwise, if you agree, I will publish it on AUR as I think it’s a good contribution.

    BTW, it seems that your wget.install[3] link is down.

    Sincerely,

    [1]: https://aur.archlinux.org/packages/wget-git/
    [2]: https://github.com/gbc921/aur/tree/master/done/wget-git-progress-bar-patch
    [3]: http://repos.archlinux.org/wsvn/packages/wget/repos/core-i686/wget.install?op=dl&rev=0

  4. Facundo Bianco (vando) Says:

    Awesome patch, it’s great for the Slackware’s package managers that use wget.

    And I just made a SlackBuild for your patch: https://github.com/vando/slackbuilds/tree/master/wget-progressbar

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: