/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.171.1 by Robert Collins
Start working toward publish - get a publishing_root option
1
#
2
# This program is free software; you can redistribute it and/or modify
3
# it under the terms of the GNU General Public License as published by
4
# the Free Software Foundation; either version 2 of the License, or
5
# (at your option) any later version.
6
#
7
# This program is distributed in the hope that it will be useful,
8
# but WITHOUT ANY WARRANTY; without even the implied warranty of
9
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
# GNU General Public License for more details.
11
#
12
# You should have received a copy of the GNU General Public License
13
# along with this program; if not, write to the Free Software
14
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
0.171.39 by Robert Collins
Draft support for mailing on push/pull.
16
"""Sending emails for commits and branch changes.
0.171.27 by Robert Collins
Documentation overhaul.
17
18
To have bzr send an email you need to configure an address to send mail
19
to for that branch. To do this set the configuration option ``post_commit_to``
20
and the address to send the mail from is read from the configuration option
21
``post_commit_sender`` (if not supplied defaults to the email address reported
22
by ``bzr whoami``).
23
0.179.1 by James Teh
Clarify documentation about setting difflimit to 0 to disable sending of diffs.
24
By default, the diff for the commit will be included in the email if the
25
length is less than 1000 lines. This limit can be changed by setting the
26
configuration option 'post_commit_difflimit' to the number of lines you wish
27
it to be limited to. Set it to 0 to unconditionally disable sending of diffs.
0.171.27 by Robert Collins
Documentation overhaul.
28
0.171.39 by Robert Collins
Draft support for mailing on push/pull.
29
By default bzr-email only emails when a commit occurs, not when a push or
30
pull operation occurs. To email on push or pull set post_commit_push_pull=True
31
in the configuration.
32
0.171.27 by Robert Collins
Documentation overhaul.
33
If you are using a bzr release from before 0.15, you need to manually tell
34
bzr about the commit action, by setting
6740.1.1 by Jelmer Vernooij
Rename bazaar.conf to breezy.conf.
35
post_commit=breezy.plugins.email.post_commit in breezy.conf or locations.conf.
0.171.27 by Robert Collins
Documentation overhaul.
36
37
The URL of the branch is determined from the following checks (in order):
38
 - If the configuration value 'post_commit_url' is set, it is used.
39
 - If the configuration value 'public_branch' is set, it is used.
40
 - The URL of the branch itself.
41
42
Setting public_branch is highly recommended if you commit via a protocol which
0.171.35 by Jelmer Vernooij
Fix typo: pricate -> private.
43
has a private address (e.g. bzr+ssh but anonymous access might be bzr:// or
0.171.27 by Robert Collins
Documentation overhaul.
44
http://).
45
46
How emails are sent is determined by the value of the configuration option
47
'post_commit_mailer':
48
 - Unset: use ``/usr/bin/mail``.
49
 - ``smtplib``: Use python's smtplib to send the mail. If you use 'smtplib' you
50
   can also configure the settings "smtp_server=host[:port]",
51
   "smtp_username=userid", "smtp_password". If "smtp_username" is set but
0.171.36 by Jelmer Vernooij
Fix another typo pointed out by Elmo.
52
   "smtp_password" is not, you will be prompted for a password.
0.171.27 by Robert Collins
Documentation overhaul.
53
54
   Also, if using 'smtplib', the messages will be sent as a UTF-8 text message,
55
   with a 8-bit text diff attached (rather than all-as-one). Work has also been
56
   done to make sure usernames do not have to be ascii.
57
 - Any other value: Run the value expecting it to behave like ``/usr/bin/mail``
58
   - in particular supporting the -s and -a options.
59
0.178.3 by Steve Langasek
change option name to 'revision_mail_headers' per Robert, and document the
60
When using smtplib, you can specify additional headers to be included in the
6649.1.1 by Jelmer Vernooij
Merge bzr-email plugin.
61
mail by setting the 'revision_mail_headers' configuration option - something
62
like::
0.178.3 by Steve Langasek
change option name to 'revision_mail_headers' per Robert, and document the
63
0.171.42 by Robert Collins
Merge patch from Steve Langasek adding support for arbitrary headers on revision notification emails.
64
  revision_mail_headers=X-Cheese: to the rescue!
0.175.3 by John Arbash Meinel
Move guts into another file to improve startup time, fix bug when old revid is None.
65
"""
0.171.4 by Robert Collins
basics are all there
66
7290.33.2 by Jelmer Vernooij
Add version_info to some plugins.
67
from ... import version_info  # noqa: F401
6649.1.1 by Jelmer Vernooij
Merge bzr-email plugin.
68
from ...config import option_registry
0.171.4 by Robert Collins
basics are all there
69
0.171.3 by Robert Collins
convert the switch basics to an email plugin
70
71
def post_commit(branch, revision_id):
0.171.27 by Robert Collins
Documentation overhaul.
72
    """This is the post_commit hook that should get run after commit."""
6674.1.1 by Jelmer Vernooij
Clean up email plugin.
73
    from . import emailer
7143.15.2 by Jelmer Vernooij
Run autopep8.
74
    emailer.EmailSender(branch, revision_id,
75
                        branch.get_config_stack()).send_maybe()
0.171.3 by Robert Collins
convert the switch basics to an email plugin
76
77
0.171.19 by Robert Collins
Update email plugin to support bzr 0.15 branch hooks.
78
def branch_commit_hook(local, master, old_revno, old_revid, new_revno, new_revid):
0.171.21 by Robert Collins
Merge up with HEAD.
79
    """This is the post_commit hook that runs after commit."""
6674.1.1 by Jelmer Vernooij
Clean up email plugin.
80
    from . import emailer
81
    emailer.EmailSender(master, new_revid, master.get_config_stack(),
82
                        local_branch=local).send_maybe()
0.171.19 by Robert Collins
Update email plugin to support bzr 0.15 branch hooks.
83
84
0.171.39 by Robert Collins
Draft support for mailing on push/pull.
85
def branch_post_change_hook(params):
86
    """This is the post_change_branch_tip hook."""
87
    # (branch, old_revno, new_revno, old_revid, new_revid)
6674.1.1 by Jelmer Vernooij
Clean up email plugin.
88
    from . import emailer
89
    emailer.EmailSender(params.branch, params.new_revid,
7143.15.2 by Jelmer Vernooij
Run autopep8.
90
                        params.branch.get_config_stack(), local_branch=None, op='change').send_maybe()
0.171.39 by Robert Collins
Draft support for mailing on push/pull.
91
92
0.171.1 by Robert Collins
Start working toward publish - get a publishing_root option
93
def test_suite():
94
    from unittest import TestSuite
6649.1.1 by Jelmer Vernooij
Merge bzr-email plugin.
95
    from .tests import test_suite
0.171.1 by Robert Collins
Start working toward publish - get a publishing_root option
96
    result = TestSuite()
6649.1.1 by Jelmer Vernooij
Merge bzr-email plugin.
97
    result.addTest(test_suite())
0.171.1 by Robert Collins
Start working toward publish - get a publishing_root option
98
    return result
99
0.171.19 by Robert Collins
Update email plugin to support bzr 0.15 branch hooks.
100
0.171.55 by Jelmer Vernooij
Use config stacks.
101
option_registry.register_lazy("post_commit_body",
7143.15.2 by Jelmer Vernooij
Run autopep8.
102
                              "breezy.plugins.email.emailer", "opt_post_commit_body")
0.171.55 by Jelmer Vernooij
Use config stacks.
103
option_registry.register_lazy("post_commit_subject",
7143.15.2 by Jelmer Vernooij
Run autopep8.
104
                              "breezy.plugins.email.emailer", "opt_post_commit_subject")
0.171.55 by Jelmer Vernooij
Use config stacks.
105
option_registry.register_lazy("post_commit_log_format",
7143.15.2 by Jelmer Vernooij
Run autopep8.
106
                              "breezy.plugins.email.emailer", "opt_post_commit_log_format")
0.171.55 by Jelmer Vernooij
Use config stacks.
107
option_registry.register_lazy("post_commit_difflimit",
7143.15.2 by Jelmer Vernooij
Run autopep8.
108
                              "breezy.plugins.email.emailer", "opt_post_commit_difflimit")
0.171.55 by Jelmer Vernooij
Use config stacks.
109
option_registry.register_lazy("post_commit_push_pull",
7143.15.2 by Jelmer Vernooij
Run autopep8.
110
                              "breezy.plugins.email.emailer", "opt_post_commit_push_pull")
0.171.55 by Jelmer Vernooij
Use config stacks.
111
option_registry.register_lazy("post_commit_diffoptions",
7143.15.2 by Jelmer Vernooij
Run autopep8.
112
                              "breezy.plugins.email.emailer", "opt_post_commit_diffoptions")
0.171.55 by Jelmer Vernooij
Use config stacks.
113
option_registry.register_lazy("post_commit_sender",
7143.15.2 by Jelmer Vernooij
Run autopep8.
114
                              "breezy.plugins.email.emailer", "opt_post_commit_sender")
0.171.55 by Jelmer Vernooij
Use config stacks.
115
option_registry.register_lazy("post_commit_to",
7143.15.2 by Jelmer Vernooij
Run autopep8.
116
                              "breezy.plugins.email.emailer", "opt_post_commit_to")
0.171.55 by Jelmer Vernooij
Use config stacks.
117
option_registry.register_lazy("post_commit_mailer",
7143.15.2 by Jelmer Vernooij
Run autopep8.
118
                              "breezy.plugins.email.emailer", "opt_post_commit_mailer")
0.171.55 by Jelmer Vernooij
Use config stacks.
119
option_registry.register_lazy("revision_mail_headers",
7143.15.2 by Jelmer Vernooij
Run autopep8.
120
                              "breezy.plugins.email.emailer", "opt_revision_mail_headers")
0.171.57 by Jelmer Vernooij
Install hook lazily, remove unused import
121
6674.1.1 by Jelmer Vernooij
Clean up email plugin.
122
from ...hooks import install_lazy_named_hook
123
install_lazy_named_hook("breezy.branch", "Branch.hooks", 'post_commit',
7143.15.2 by Jelmer Vernooij
Run autopep8.
124
                        branch_commit_hook, 'bzr-email')
6674.1.1 by Jelmer Vernooij
Clean up email plugin.
125
install_lazy_named_hook("breezy.branch", "Branch.hooks",
7143.15.2 by Jelmer Vernooij
Run autopep8.
126
                        'post_change_branch_tip', branch_post_change_hook, 'bzr-email')