You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@spamassassin.apache.org by Michael Parker <pa...@pobox.com> on 2004/12/30 21:49:48 UTC

ProgressBar Code

Howdy,

A small little itch I've been scratching is to add the capability of
showing a progress bar for sa-learn and spamassassin.  So, now I've
done that, it looks a little like this for sa-learn (note that the
seperate lines are there just to show how it behaves, normally the
progress bar would overwrite itself):

 27% [============                                ] 18.66 msgs/sec 01m22s LEFT
100% [============================================] 16.97 msgs/sec 01m57s DONE
Learned from 2000 message(s) (2000 message(s) examined).



 16% [=======                                     ]  5.25 msgs/sec 06m08s LEFT
 50% [======================                      ]  3.55 msgs/sec 03m36s LEFT
 73% [================================            ]  2.35 msgs/sec 01m55s LEFT
100% [============================================]  4.52 msgs/sec 07m22s DONE
Learned from 2000 message(s) (2000 message(s) examined).

And this is how it looks when run with spamassassin:

spamassassin --progress --mbox hambucket1.mbox > blah.scanned
  5% [=            ]   0.32 msgs/sec 37m47s LEFT

spamassassin --progress -L --mbox hambucket1.mbox > blah.scanned
100% [=============]  10.37 msgs/sec 03m12s DONE

The smaller progress bar is due to the fact that Term::ReadKey is
unable to determine the terminal size when redirecting STDOUT that way
(if you know of a solution, speak up).

If STDERR doesn't have a terminal (ie redirect to a file) then we'll
behave very similar to --showdots, printing a . for each message
processed and following up with a final status line:

.......................................................................................................................
100% Completed 113.51 msgs/sec in 00m17s
Learned from 0 message(s) (2000 message(s) examined).

In fact, I've contemplated replacing the --showdots functionality with
this, only issue is that it behaves slightly differently.

So, thoughts? Comments?

It seems to work well, at least in all of the tests I've done.  I'm
gonna try and extend it just a bit to cover more functions (ie restore
and sync).

I'm including the diff for folks to look over.

Michael