/brz/remove-bazaar

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