patchbomb: show progress when sending emails or writing mbox
authorYuya Nishihara <yuya@tcha.org>
Sun, 12 Sep 2010 16:10:41 +0900
changeset 12265 1ed2dc9d4368
parent 12264 b8146231c3de
child 12266 00658492e2aa
patchbomb: show progress when sending emails or writing mbox
hgext/patchbomb.py
--- a/hgext/patchbomb.py	Sat Sep 11 18:08:00 2010 +0200
+++ b/hgext/patchbomb.py	Sun Sep 12 16:10:41 2010 +0900
@@ -438,7 +438,7 @@
     sender_addr = email.Utils.parseaddr(sender)[1]
     sender = mail.addressencode(ui, sender, _charsets, opts.get('test'))
     sendmail = None
-    for m, subj, ds in msgs:
+    for i, (m, subj, ds) in enumerate(msgs):
         try:
             m['Message-Id'] = genmsgid(m['X-Mercurial-Node'])
         except TypeError:
@@ -480,6 +480,7 @@
                 fp.close()
         elif mbox:
             ui.status(_('Writing '), subj, ' ...\n')
+            ui.progress(_('writing'), i, item=subj, total=len(msgs))
             fp = open(mbox, 'In-Reply-To' in m and 'ab+' or 'wb+')
             generator = email.Generator.Generator(fp, mangle_from_=True)
             # Should be time.asctime(), but Windows prints 2-characters day
@@ -494,6 +495,7 @@
             if not sendmail:
                 sendmail = mail.connect(ui)
             ui.status(_('Sending '), subj, ' ...\n')
+            ui.progress(_('sending'), i, item=subj, total=len(msgs))
             # Exim does not remove the Bcc field
             del m['Bcc']
             fp = cStringIO.StringIO()
@@ -501,6 +503,9 @@
             generator.flatten(m, 0)
             sendmail(sender, to + bcc + cc, fp.getvalue())
 
+    ui.progress(_('writing'), None)
+    ui.progress(_('sending'), None)
+
 emailopts = [
           ('a', 'attach', None, _('send patches as attachments')),
           ('i', 'inline', None, _('send patches as inline attachments')),