[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Bug-wget] [PATCH] [BUG-33838] - A way to turn off verbosity but sti
From: |
Sasikanth babu |
Subject: |
Re: [Bug-wget] [PATCH] [BUG-33838] - A way to turn off verbosity but still have a progress bar |
Date: |
Wed, 16 May 2012 00:32:01 +0530 |
Attached patch
Thanks
Sasi
On Wed, May 16, 2012 at 12:29 AM, Sasikantha babu
<address@hidden>wrote:
> Fix of defect 33838 - https://savannah.gnu.org/bugs/?33838
>
> OutPut Logs
> ----------
>
> address@hidden wget]#
> address@hidden wget]# ./src/wget
> http://ftp.gnu.org/gnu/wget/wget-1.5.3.tar.gz --progress=dot -q
>
> 0K .......... .......... .......... .......... .......... 11% 80.2K 5s
> 50K .......... .......... .......... .......... .......... 22% 80.5K 4s
> 100K .......... .......... .......... .......... .......... 34% 239K 3s
> 150K .......... .......... .......... .......... .......... 45% 80.6K 2s
> 200K .......... .......... .......... .......... .......... 57% 120K 2s
> 250K .......... .......... .......... .......... .......... 68% 80.4K 1s
> 300K .......... .......... .......... .......... .......... 80% 120K 1s
> 350K .......... .......... .......... .......... .......... 91% 80.2K 0s
> 400K .......... .......... .......... ...... 100%
> 58.7K=4.8s
>
> address@hidden wget]# ./src/wget
> http://ftp.gnu.org/gnu/wget/wget-1.5.3.tar.gz --progress=bar -q
>
> 100%[===================================================================================================================>]
> 446,966 56.0KB/s in 8.2s
>
> address@hidden wget]# ./src/wget
> http://ftp.gnu.org/gnu/wget/wget-1.5.3.tar.gz --progress=bar -q -nv
>
> 100%[===================================================================================================================>]
> 446,966 43.8KB/s in 9.9s
>
> address@hidden wget]# ./src/wget
> http://ftp.gnu.org/gnu/wget/wget-1.5.3.tar.gz --progress=dot
> --2012-05-16 00:26:29-- http://ftp.gnu.org/gnu/wget/wget-1.5.3.tar.gz
> Resolving ftp.gnu.org (ftp.gnu.org)... 208.118.235.20, 2001:4830:134:3::b
> Connecting to ftp.gnu.org (ftp.gnu.org)|208.118.235.20|:80... connected.
> HTTP request sent, awaiting response... 200 OK
> Length: 446966 (436K) [application/x-gzip]
> Saving to: ‘wget-1.5.3.tar.gz.3’
>
> 0K .......... .......... .......... .......... .......... 11% 39.3K 10s
> 50K .......... .......... .......... .......... .......... 22% 56.5K 7s
> 100K .......... .......... .......... .......... .......... 34% 59.1K 6s
> 150K .......... .......... .......... .......... .......... 45% 45.5K 5s
> 200K .......... .......... .......... .......... .......... 57% 47.4K 4s
> 250K .......... .......... .......... .......... .......... 68% 107K 3s
> 300K .......... .......... .......... .......... .......... 80% 49.0K 2s
> 350K .......... .......... .......... .......... .......... 91% 65.0K 1s
> 400K .......... .......... .......... ...... 100%
> 48.8K=8.2s
>
> 2012-05-16 00:26:38 (53.5 KB/s) - ‘wget-1.5.3.tar.gz.3’ saved
> [446966/446966]
>
> address@hidden wget]#
>
>
> Signed-off-by: Sasikantha babu <address@hidden>
> ---
> src/ChangeLog | 13 +++++++++++++
> src/init.c | 1 +
> src/log.c | 38 ++++++++++++++++++++++++++++++++++++++
> src/log.h | 2 ++
> src/main.c | 2 +-
> src/options.h | 2 ++
> src/progress.c | 40 ++++++++++++++++++++--------------------
> src/retr.c | 2 +-
> 8 files changed, 78 insertions(+), 22 deletions(-)
>
> diff --git a/src/ChangeLog b/src/ChangeLog
> index 68df65b..b9e0b06 100644
> --- a/src/ChangeLog
> +++ b/src/ChangeLog
> @@ -1,3 +1,16 @@
> +2012-05-16 Sasikantha Babu <address@hidden>
> + * init.c (cmd_spec_progress): initialized opt.progress to true.
> + * log.c (logprogress): Added new function +logprogress to
> + log progess status. It is similar to logprintf, but it overrides
> + the option -q and -nv, if --progress mentioned explicit.
> + * log.h: Added function prototype for logprogress.
> + * main.c (main) : Initialize progress for --progress option.
> + * options.h (struct opt): Added option bool variable for progress.
> + * retr.c (fd_read_body): Create progress for --progress option
> + * progress.c (dot_create, print_row_stats, dot_update, dot_finish
> + , bar_create, bar_finish, display_image): Used logprogress to
> + override -q and -nv option over logprintf
> +
> 2012-05-14 Tim Ruehsen <address@hidden>
>
> * gnutls.c (wgnutls_read_timeout): removed warnings, moved fcntl
> stuff
> diff --git a/src/init.c b/src/init.c
> index 57a4f00..2a8c8c5 100644
> --- a/src/init.c
> +++ b/src/init.c
> @@ -1358,6 +1358,7 @@ cmd_spec_progress (const char *com, const char *val,
> void *place_ignored)
> /* Don't call set_progress_implementation here. It will be called
> in main() when it becomes clear what the log output is. */
> opt.progress_type = xstrdup (val);
> + opt.progress = true;
> return true;
> }
>
> diff --git a/src/log.c b/src/log.c
> index 0185df1..5b4f61a 100644
> --- a/src/log.c
> +++ b/src/log.c
> @@ -548,6 +548,44 @@ logprintf (enum log_options o, const char *fmt, ...)
> while (!done);
> }
>
> +/* Print a message to the screen or to the log. The first argument
> + defines the verbosity of the message, and the rest are as in
> + printf(3). Call this function only to log progress.
> +
> + This function ignores -q and -nv options if we pass --progress=<xxx>
> + along with them (xxx = bar or dot) i.e explicit --progress overrides
> + -q and(or) -nv.
> + */
> +
> +void
> +logprogress (enum log_options o, const char *fmt, ...)
> +{
> + va_list args;
> + struct logvprintf_state lpstate;
> + bool done;
> +
> + check_redirect_output ();
> + if (inhibit_logging)
> + return;
> +
> + /*If progress bar flag is set Ignore -q or -nv*/
> + if (!opt.progress)
> + CHECK_VERBOSE (o);
> +
> + xzero (lpstate);
> + do
> + {
> + va_start (args, fmt);
> + done = log_vprintf_internal (&lpstate, fmt, args);
> + va_end (args);
> +
> + if (done && errno == EPIPE)
> + exit (1);
> + }
> + while (!done);
> +}
> +
> +
> #ifdef ENABLE_DEBUG
> /* The same as logprintf(), but does anything only if opt.debug is
> true. */
> diff --git a/src/log.h b/src/log.h
> index d74ca53..023cf7f 100644
> --- a/src/log.h
> +++ b/src/log.h
> @@ -42,6 +42,8 @@ void log_set_warc_log_fp (FILE *);
>
> void logprintf (enum log_options, const char *, ...)
> GCC_FORMAT_ATTR (2, 3);
> +void logprogress (enum log_options, const char *, ...)
> + GCC_FORMAT_ATTR (2, 3);
> void debug_logprintf (const char *, ...) GCC_FORMAT_ATTR (1, 2);
> void logputs (enum log_options, const char *);
> void logflush (void);
> diff --git a/src/main.c b/src/main.c
> index aac01ac..462c2c7 100644
> --- a/src/main.c
> +++ b/src/main.c
> @@ -1407,7 +1407,7 @@ for details.\n\n"));
>
> /* Initialize progress. Have to do this after the options are
> processed so we know where the log file is. */
> - if (opt.verbose)
> + if (opt.verbose || opt.progress)
> set_progress_implementation (opt.progress_type);
>
> /* Fill in the arguments. */
> diff --git a/src/options.h b/src/options.h
> index 0da7937..edcc2a2 100644
> --- a/src/options.h
> +++ b/src/options.h
> @@ -280,6 +280,8 @@ struct options
> bool show_all_dns_entries; /* Show all the DNS entries when resolving a
> name. */
> bool bits_fmt; /*Output bandwidth in bits format*/
> +
> + bool progress; /*Progress bar*/
> };
>
> extern struct options opt;
> diff --git a/src/progress.c b/src/progress.c
> index f61c95e..ce01bd1 100644
> --- a/src/progress.c
> +++ b/src/progress.c
> @@ -237,18 +237,18 @@ dot_create (wgint initial, wgint total)
> /* Align the [ skipping ... ] line with the dots. To do
> that, insert the number of spaces equal to the number of
> digits in the skipped amount in K. */
> - logprintf (LOG_VERBOSE, _("\n%*s[ skipping %sK ]"),
> + logprogress (LOG_VERBOSE, _("\n%*s[ skipping %sK ]"),
> 2 + skipped_k_len, "",
> number_to_static_string (skipped_k));
> }
>
> - logprintf (LOG_VERBOSE, "\n%6sK",
> + logprogress (LOG_VERBOSE, "\n%6sK",
> number_to_static_string (skipped / 1024));
> for (; remainder >= dot_bytes; remainder -= dot_bytes)
> {
> if (dp->dots % opt.dot_spacing == 0)
> - logputs (LOG_VERBOSE, " ");
> - logputs (LOG_VERBOSE, ",");
> + logprogress (LOG_VERBOSE, " ");
> + logprogress (LOG_VERBOSE, ",");
> ++dp->dots;
> }
> assert (dp->dots < opt.dots_in_line);
> @@ -289,7 +289,7 @@ print_row_stats (struct dot_progress *dp, double
> dltime, bool last)
> 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);
> + logprogress (LOG_VERBOSE, "%3d%%", percentage);
> }
>
> {
> @@ -306,7 +306,7 @@ print_row_stats (struct dot_progress *dp, double
> dltime, bool last)
> if (dp->rows == dp->initial_length / ROW_BYTES)
> bytes_this_row -= dp->initial_length % ROW_BYTES;
> rate = calc_rate (bytes_this_row, dltime - dp->last_timer_value,
> &units);
> - logprintf (LOG_VERBOSE, " %4.*f%c",
> + logprogress (LOG_VERBOSE, " %4.*f%c",
> rate >= 99.95 ? 0 : rate >= 9.995 ? 1 : 2,
> rate, names[units]);
> dp->last_timer_value = dltime;
> @@ -323,7 +323,7 @@ print_row_stats (struct dot_progress *dp, double
> dltime, bool last)
> wgint bytes_sofar = bytes_displayed - dp->initial_length;
> double eta = dltime * bytes_remaining / bytes_sofar;
> if (eta < INT_MAX - 1)
> - logprintf (LOG_VERBOSE, " %s",
> + logprogress (LOG_VERBOSE, " %s",
> eta_to_human_short ((int) (eta + 0.5), true));
> }
> }
> @@ -331,10 +331,10 @@ print_row_stats (struct dot_progress *dp, double
> dltime, bool last)
> {
> /* When done, print the total download time */
> if (dltime >= 10)
> - logprintf (LOG_VERBOSE, "=%s",
> + logprogress (LOG_VERBOSE, "=%s",
> eta_to_human_short ((int) (dltime + 0.5), true));
> else
> - logprintf (LOG_VERBOSE, "=%ss", print_decimal (dltime));
> + logprogress (LOG_VERBOSE, "=%ss", print_decimal (dltime));
> }
> }
>
> @@ -353,12 +353,12 @@ dot_update (void *progress, wgint howmuch, double
> dltime)
> for (; dp->accumulated >= dot_bytes; dp->accumulated -= dot_bytes)
> {
> if (dp->dots == 0)
> - logprintf (LOG_VERBOSE, "\n%6sK",
> + logprogress (LOG_VERBOSE, "\n%6sK",
> number_to_static_string (dp->rows * ROW_BYTES / 1024));
>
> if (dp->dots % opt.dot_spacing == 0)
> - logputs (LOG_VERBOSE, " ");
> - logputs (LOG_VERBOSE, ".");
> + logprogress (LOG_VERBOSE, " ");
> + logprogress (LOG_VERBOSE, ".");
>
> ++dp->dots;
> if (dp->dots >= opt.dots_in_line)
> @@ -385,17 +385,17 @@ dot_finish (void *progress, double dltime)
> log_set_flush (false);
>
> if (dp->dots == 0)
> - logprintf (LOG_VERBOSE, "\n%6sK",
> + logprogress (LOG_VERBOSE, "\n%6sK",
> number_to_static_string (dp->rows * ROW_BYTES / 1024));
> for (i = dp->dots; i < opt.dots_in_line; i++)
> {
> if (i % opt.dot_spacing == 0)
> - logputs (LOG_VERBOSE, " ");
> - logputs (LOG_VERBOSE, " ");
> + logprogress (LOG_VERBOSE, " ");
> + logprogress (LOG_VERBOSE, " ");
> }
>
> print_row_stats (dp, dltime, true);
> - logputs (LOG_VERBOSE, "\n\n");
> + logprogress (LOG_VERBOSE, "\n\n");
> log_set_flush (false);
>
> xfree (dp);
> @@ -581,7 +581,7 @@ bar_create (wgint initial, wgint total)
> * for multibyte characters. */
> bp->buffer = xmalloc (bp->width + 100);
>
> - logputs (LOG_VERBOSE, "\n");
> + logprogress (LOG_VERBOSE, "\n");
>
> create_image (bp, 0, false);
> display_image (bp->buffer);
> @@ -650,7 +650,7 @@ bar_finish (void *progress, double dltime)
> create_image (bp, dltime, true);
> display_image (bp->buffer);
>
> - logputs (LOG_VERBOSE, "\n\n");
> + logprogress (LOG_VERBOSE, "\n\n");
>
> xfree (bp->buffer);
> xfree (bp);
> @@ -1070,8 +1070,8 @@ static void
> display_image (char *buf)
> {
> bool old = log_set_save_context (false);
> - logputs (LOG_VERBOSE, "\r");
> - logputs (LOG_VERBOSE, buf);
> + logprogress (LOG_VERBOSE, "\r");
> + logprogress (LOG_VERBOSE, buf);
> log_set_save_context (old);
> }
>
> diff --git a/src/retr.c b/src/retr.c
> index 5f33c7a..935ea2d 100644
> --- a/src/retr.c
> +++ b/src/retr.c
> @@ -259,7 +259,7 @@ fd_read_body (int fd, FILE *out, wgint toread, wgint
> startpos,
> if (flags & rb_skip_startpos)
> skip = startpos;
>
> - if (opt.verbose)
> + if (opt.verbose || opt.progress)
> {
> /* If we're skipping STARTPOS bytes, pass 0 as the INITIAL
> argument to progress_create because the indicator doesn't
> --
> 1.7.3.4
>
>
0001-BUG-33838-A-way-to-turn-off-verbosity-but-still-have.txt
Description: Text document