/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: 2019-05-29 03:22:34 UTC
  • mfrom: (7303 work)
  • mto: This revision was merged to the branch mainline in revision 7306.
  • Revision ID: jelmer@jelmer.uk-20190529032234-mt3fuws8gq03tapi
Merge trunk.

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((revid_new, revid_old))
 
129
            tree_new, tree_old = self.repository.revision_trees(
 
130
                (revid_new, revid_old))
130
131
        else:
131
132
            # revision_trees() doesn't allow None or 'null:' to be passed as a
132
133
            # revision. So we need to call revision_tree() twice.
140
141
        diff_content = StringIO()
141
142
        diff_options = self.config.get('post_commit_diffoptions')
142
143
        show_diff_trees(tree_old, tree_new, diff_content, None, diff_options)
143
 
        numlines = diff_content.getvalue().count('\n')+1
 
144
        numlines = diff_content.getvalue().count('\n') + 1
144
145
        if numlines <= difflimit:
145
146
            return diff_content.getvalue()
146
147
        else:
158
159
 
159
160
    def _command_line(self):
160
161
        cmd = [self.mailer(), '-s', self.subject(), '-a',
161
 
                "From: " + self.from_address()]
 
162
               "From: " + self.from_address()]
162
163
        cmd.extend(self.to())
163
164
        return cmd
164
165
 
222
223
            msgfile.seek(0)
223
224
 
224
225
            process = subprocess.Popen(self._command_line(),
225
 
                stdin=msgfile.fileno())
 
226
                                       stdin=msgfile.fileno())
226
227
 
227
228
            rc = process.wait()
228
229
            if rc != 0:
229
 
                raise errors.BzrError("Failed to send email: exit status %s" % (rc,))
 
230
                raise errors.BzrError(
 
231
                    "Failed to send email: exit status %s" % (rc,))
230
232
        finally:
231
233
            msgfile.close()
232
234
 
245
247
            msg.add_inline_attachment(diff, self.diff_filename())
246
248
 
247
249
        # Add revision_mail_headers to the headers
248
 
        if header != None:
 
250
        if header is None:
249
251
            for k, v in header.items():
250
252
                msg[k] = v
251
253
 
269
271
    def subject(self):
270
272
        _subject = self.config.get('post_commit_subject')
271
273
        if _subject is None:
272
 
            _subject = ("Rev %d: %s in %s" % 
273
 
                (self.revno,
274
 
                 self.revision.get_summary(),
275
 
                 self.url()))
 
274
            _subject = ("Rev %d: %s in %s" %
 
275
                        (self.revno,
 
276
                         self.revision.get_summary(),
 
277
                         self.url()))
276
278
        return self._format(_subject)
277
279
 
278
280
    def diff_filename(self):
280
282
 
281
283
 
282
284
opt_post_commit_body = Option("post_commit_body",
283
 
    help="Body for post commit emails.")
 
285
                              help="Body for post commit emails.")
284
286
opt_post_commit_subject = Option("post_commit_subject",
285
 
    help="Subject for post commit emails.")
 
287
                                 help="Subject for post commit emails.")
286
288
opt_post_commit_log_format = Option('post_commit_log_format',
287
 
    default='long', help="Log format for option.")
 
289
                                    default='long', help="Log format for option.")
288
290
opt_post_commit_difflimit = Option('post_commit_difflimit',
289
 
    default=1000, from_unicode=int_from_store,
290
 
    help="Maximum number of lines in diffs.")
 
291
                                   default=1000, from_unicode=int_from_store,
 
292
                                   help="Maximum number of lines in diffs.")
291
293
opt_post_commit_push_pull = Option('post_commit_push_pull',
292
 
    from_unicode=bool_from_store,
293
 
    help="Whether to send emails on push and pull.")
 
294
                                   from_unicode=bool_from_store,
 
295
                                   help="Whether to send emails on push and pull.")
294
296
opt_post_commit_diffoptions = Option('post_commit_diffoptions',
295
 
    help="Diff options to use.")
 
297
                                     help="Diff options to use.")
296
298
opt_post_commit_sender = Option('post_commit_sender',
297
 
    help='From address to use for emails.')
 
299
                                help='From address to use for emails.')
298
300
opt_post_commit_to = ListOption('post_commit_to',
299
 
    help='Address to send commit emails to.')
 
301
                                help='Address to send commit emails to.')
300
302
opt_post_commit_mailer = Option('post_commit_mailer',
301
 
    help='Mail client to use.', default='mail')
 
303
                                help='Mail client to use.', default='mail')
302
304
opt_post_commit_url = Option('post_commit_url',
303
 
    help='URL to mention for branch in post commit messages.')
 
305
                             help='URL to mention for branch in post commit messages.')
304
306
opt_revision_mail_headers = ListOption('revision_mail_headers',
305
 
    help="Extra revision headers.")
 
307
                                       help="Extra revision headers.")