/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/plugins/email/emailer.py

  • Committer: Jelmer Vernooij
  • Date: 2018-05-06 11:48:54 UTC
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@jelmer.uk-20180506114854-h4qd9ojaqy8wxjsd
Move .mailmap to root.

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
    _smtplib_implementation = SMTPConnection
41
41
 
42
42
    def __init__(self, branch, revision_id, config, local_branch=None,
43
 
                 op='commit'):
 
43
        op='commit'):
44
44
        self.config = config
45
45
        self.branch = branch
46
46
        self.repository = branch.repository
47
47
        if (local_branch is not None and
48
 
                local_branch.repository.has_revision(revision_id)):
 
48
            local_branch.repository.has_revision(revision_id)):
49
49
            self.repository = local_branch.repository
50
50
        self._revision_id = revision_id
51
51
        self.revision = None
126
126
        revid_new = self.revision.revision_id
127
127
        if self.revision.parent_ids:
128
128
            revid_old = self.revision.parent_ids[0]
129
 
            tree_new, tree_old = self.repository.revision_trees(
130
 
                (revid_new, revid_old))
 
129
            tree_new, tree_old = self.repository.revision_trees((revid_new, revid_old))
131
130
        else:
132
131
            # revision_trees() doesn't allow None or 'null:' to be passed as a
133
132
            # revision. So we need to call revision_tree() twice.
141
140
        diff_content = StringIO()
142
141
        diff_options = self.config.get('post_commit_diffoptions')
143
142
        show_diff_trees(tree_old, tree_new, diff_content, None, diff_options)
144
 
        numlines = diff_content.getvalue().count('\n') + 1
 
143
        numlines = diff_content.getvalue().count('\n')+1
145
144
        if numlines <= difflimit:
146
145
            return diff_content.getvalue()
147
146
        else:
159
158
 
160
159
    def _command_line(self):
161
160
        cmd = [self.mailer(), '-s', self.subject(), '-a',
162
 
               "From: " + self.from_address()]
 
161
                "From: " + self.from_address()]
163
162
        cmd.extend(self.to())
164
163
        return cmd
165
164
 
213
212
        """Spawn a 'mail' subprocess to send the email."""
214
213
        # TODO think up a good test for this, but I think it needs
215
214
        # a custom binary shipped with. RBC 20051021
216
 
        with tempfile.NamedTemporaryFile() as msgfile:
 
215
        msgfile = tempfile.NamedTemporaryFile()
 
216
        try:
217
217
            msgfile.write(self.body().encode('utf8'))
218
218
            diff = self.get_diff()
219
219
            if diff:
222
222
            msgfile.seek(0)
223
223
 
224
224
            process = subprocess.Popen(self._command_line(),
225
 
                                       stdin=msgfile.fileno())
 
225
                stdin=msgfile.fileno())
226
226
 
227
227
            rc = process.wait()
228
228
            if rc != 0:
229
 
                raise errors.BzrError(
230
 
                    "Failed to send email: exit status %s" % (rc,))
 
229
                raise errors.BzrError("Failed to send email: exit status %s" % (rc,))
 
230
        finally:
 
231
            msgfile.close()
231
232
 
232
233
    def _send_using_smtplib(self):
233
234
        """Use python's smtplib to send the email."""
244
245
            msg.add_inline_attachment(diff, self.diff_filename())
245
246
 
246
247
        # Add revision_mail_headers to the headers
247
 
        if header is None:
 
248
        if header != None:
248
249
            for k, v in header.items():
249
250
                msg[k] = v
250
251
 
268
269
    def subject(self):
269
270
        _subject = self.config.get('post_commit_subject')
270
271
        if _subject is None:
271
 
            _subject = ("Rev %d: %s in %s" %
272
 
                        (self.revno,
273
 
                         self.revision.get_summary(),
274
 
                         self.url()))
 
272
            _subject = ("Rev %d: %s in %s" % 
 
273
                (self.revno,
 
274
                 self.revision.get_summary(),
 
275
                 self.url()))
275
276
        return self._format(_subject)
276
277
 
277
278
    def diff_filename(self):
279
280
 
280
281
 
281
282
opt_post_commit_body = Option("post_commit_body",
282
 
                              help="Body for post commit emails.")
 
283
    help="Body for post commit emails.")
283
284
opt_post_commit_subject = Option("post_commit_subject",
284
 
                                 help="Subject for post commit emails.")
 
285
    help="Subject for post commit emails.")
285
286
opt_post_commit_log_format = Option('post_commit_log_format',
286
 
                                    default='long', help="Log format for option.")
 
287
    default='long', help="Log format for option.")
287
288
opt_post_commit_difflimit = Option('post_commit_difflimit',
288
 
                                   default=1000, from_unicode=int_from_store,
289
 
                                   help="Maximum number of lines in diffs.")
 
289
    default=1000, from_unicode=int_from_store,
 
290
    help="Maximum number of lines in diffs.")
290
291
opt_post_commit_push_pull = Option('post_commit_push_pull',
291
 
                                   from_unicode=bool_from_store,
292
 
                                   help="Whether to send emails on push and pull.")
 
292
    from_unicode=bool_from_store,
 
293
    help="Whether to send emails on push and pull.")
293
294
opt_post_commit_diffoptions = Option('post_commit_diffoptions',
294
 
                                     help="Diff options to use.")
 
295
    help="Diff options to use.")
295
296
opt_post_commit_sender = Option('post_commit_sender',
296
 
                                help='From address to use for emails.')
 
297
    help='From address to use for emails.')
297
298
opt_post_commit_to = ListOption('post_commit_to',
298
 
                                help='Address to send commit emails to.')
 
299
    help='Address to send commit emails to.')
299
300
opt_post_commit_mailer = Option('post_commit_mailer',
300
 
                                help='Mail client to use.', default='mail')
 
301
    help='Mail client to use.', default='mail')
301
302
opt_post_commit_url = Option('post_commit_url',
302
 
                             help='URL to mention for branch in post commit messages.')
 
303
    help='URL to mention for branch in post commit messages.')
303
304
opt_revision_mail_headers = ListOption('revision_mail_headers',
304
 
                                       help="Extra revision headers.")
 
305
    help="Extra revision headers.")