Skip to content

Commit

Permalink
Add progress bar instead of spamming screen w/ dot
Browse files Browse the repository at this point in the history
  • Loading branch information
kdm9 committed Aug 7, 2016
1 parent 7a206ec commit f5275e0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
13 changes: 10 additions & 3 deletions maildir_deduplicate/deduplicate.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@
import time
from difflib import unified_diff
from mailbox import Maildir
from progressbar import (
Bar,
ProgressBar,
Percentage,
)


from . import (
HEADERS,
Expand Down Expand Up @@ -80,7 +86,10 @@ def add_maildir(self, maildir_path):
# Collate folders by hash.
logger.info(
"Processing {} mails in {}".format(len(maildir), maildir._path))
for mail_id, message in maildir.iteritems():
bar = ProgressBar(widgets=[Percentage(), Bar()], max_value=len(maildir),
redirect_stderr=True, redirect_stdout=True)

for mail_id, message in bar(maildir.iteritems()):
mail_file = os.path.join(maildir._path, maildir._lookup(mail_id))
try:
mail_hash, header_text = self.compute_hash(
Expand All @@ -89,8 +98,6 @@ def add_maildir(self, maildir_path):
logger.warning(
"Ignoring problematic {}: {}".format(mail_file, e.args[0]))
else:
if self.mail_count > 0 and self.mail_count % 100 == 0:
logger.info(".")
logger.debug(
"Hash is {} for mail {!r}.".format(mail_hash, mail_id))
if mail_hash not in self.mails:
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def get_long_description():
install_requires=[
'click >= 5.0',
'click_log',
'progressbar2',
],

packages=find_packages(),
Expand Down

0 comments on commit f5275e0

Please sign in to comment.