hgext/patchbomb.py
changeset 1827 26dd4ae77b7b
parent 1702 e291d9a30bef
child 1845 cfe689ab3f06
equal deleted inserted replaced
1826:f3abe0bdccdd 1827:26dd4ae77b7b
    47 # [patchbomb]
    47 # [patchbomb]
    48 # from = My Name <my@email>
    48 # from = My Name <my@email>
    49 # to = recipient1, recipient2, ...
    49 # to = recipient1, recipient2, ...
    50 # cc = cc1, cc2, ...
    50 # cc = cc1, cc2, ...
    51 
    51 
    52 from email.MIMEMultipart import MIMEMultipart
    52 from mercurial.demandload import *
    53 from email.MIMEText import MIMEText
    53 demandload(globals(), '''email.MIMEMultipart email.MIMEText email.Utils
    54 from email.Utils import parseaddr
    54                          mercurial:commands,hg,ui
    55 from mercurial import commands
    55                          os popen2 smtplib socket sys tempfile time''')
    56 from mercurial import hg
       
    57 from mercurial import ui
       
    58 from mercurial.i18n import gettext as _
    56 from mercurial.i18n import gettext as _
    59 import os
       
    60 import popen2
       
    61 import smtplib
       
    62 import socket
       
    63 import sys
       
    64 import tempfile
       
    65 import time
       
    66 
    57 
    67 try:
    58 try:
    68     # readline gives raw_input editing capabilities, but is not
    59     # readline gives raw_input editing capabilities, but is not
    69     # present on windows
    60     # present on windows
    70     import readline
    61     import readline
   147             if patch: patch.pop(0)
   138             if patch: patch.pop(0)
   148             while patch and not patch[0].strip(): patch.pop(0)
   139             while patch and not patch[0].strip(): patch.pop(0)
   149         if opts['diffstat']:
   140         if opts['diffstat']:
   150             body += cdiffstat('\n'.join(desc), patch) + '\n\n'
   141             body += cdiffstat('\n'.join(desc), patch) + '\n\n'
   151         body += '\n'.join(patch)
   142         body += '\n'.join(patch)
   152         msg = MIMEText(body)
   143         msg = email.MIMEText.MIMEText(body)
   153         subj = '[PATCH %d of %d] %s' % (idx, total, desc[0].strip())
   144         subj = '[PATCH %d of %d] %s' % (idx, total, desc[0].strip())
   154         if subj.endswith('.'): subj = subj[:-1]
   145         if subj.endswith('.'): subj = subj[:-1]
   155         msg['Subject'] = subj
   146         msg['Subject'] = subj
   156         msg['X-Mercurial-Node'] = node
   147         msg['X-Mercurial-Node'] = node
   157         return msg
   148         return msg
   192     ui.write(_('\nWrite the introductory message for the patch series.\n\n'))
   183     ui.write(_('\nWrite the introductory message for the patch series.\n\n'))
   193 
   184 
   194     sender = (opts['from'] or ui.config('patchbomb', 'from') or
   185     sender = (opts['from'] or ui.config('patchbomb', 'from') or
   195               prompt('From', ui.username()))
   186               prompt('From', ui.username()))
   196 
   187 
   197     msg = MIMEMultipart()
   188     msg = email.MIMEMultipart.MIMEMultipart()
   198     msg['Subject'] = '[PATCH 0 of %d] %s' % (
   189     msg['Subject'] = '[PATCH 0 of %d] %s' % (
   199         len(patches),
   190         len(patches),
   200         opts['subject'] or
   191         opts['subject'] or
   201         prompt('Subject:', rest = ' [PATCH 0 of %d] ' % len(patches)))
   192         prompt('Subject:', rest = ' [PATCH 0 of %d] ' % len(patches)))
   202 
   193 
   215         try: l = raw_input()
   206         try: l = raw_input()
   216         except EOFError: break
   207         except EOFError: break
   217         if l == '.': break
   208         if l == '.': break
   218         body.append(l)
   209         body.append(l)
   219 
   210 
   220     msg.attach(MIMEText('\n'.join(body) + '\n'))
   211     msg.attach(email.MIMEText.MIMEText('\n'.join(body) + '\n'))
   221 
   212 
   222     ui.write('\n')
   213     ui.write('\n')
   223 
   214 
   224     if opts['diffstat']:
   215     if opts['diffstat']:
   225         d = cdiffstat(_('Final summary:\n'), jumbo)
   216         d = cdiffstat(_('Final summary:\n'), jumbo)
   226         if d: msg.attach(MIMEText(d))
   217         if d: msg.attach(email.MIMEText.MIMEText(d))
   227 
   218 
   228     msgs.insert(0, msg)
   219     msgs.insert(0, msg)
   229 
   220 
   230     if not opts['test'] and not opts['mbox']:
   221     if not opts['test'] and not opts['mbox']:
   231         s = smtplib.SMTP()
   222         s = smtplib.SMTP()
   239         password = ui.config('smtp', 'password')
   230         password = ui.config('smtp', 'password')
   240         if username and password:
   231         if username and password:
   241             s.login(username, password)
   232             s.login(username, password)
   242     parent = None
   233     parent = None
   243     tz = time.strftime('%z')
   234     tz = time.strftime('%z')
   244     sender_addr = parseaddr(sender)[1]
   235     sender_addr = email.Utils.parseaddr(sender)[1]
   245     for m in msgs:
   236     for m in msgs:
   246         try:
   237         try:
   247             m['Message-Id'] = genmsgid(m['X-Mercurial-Node'])
   238             m['Message-Id'] = genmsgid(m['X-Mercurial-Node'])
   248         except TypeError:
   239         except TypeError:
   249             m['Message-Id'] = genmsgid('patchbomb')
   240             m['Message-Id'] = genmsgid('patchbomb')