/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.175.3 by John Arbash Meinel
Move guts into another file to improve startup time, fix bug when old revid is None.
17
"""Allow sending an email after a new commit.
18
19
This plugin provides a 'post_commit' hook, which is used to send an email (like
20
to a developer mailing list) with the basic contents of the change.
21
22
See the README file for basic information on how to configure this plugin.
23
"""
0.171.4 by Robert Collins
basics are all there
24
0.171.3 by Robert Collins
convert the switch basics to an email plugin
25
0.171.22 by John Arbash Meinel
Cleanup import logic, and use lazy importing
26
if __name__ != 'bzrlib.plugins.email':
27
    raise ImportError('The email plugin must be installed as'
28
                      ' bzrlib.plugins.email not %s'
29
                      % __name__)
30
31
0.171.21 by Robert Collins
Merge up with HEAD.
32
from bzrlib import errors
0.171.19 by Robert Collins
Update email plugin to support bzr 0.15 branch hooks.
33
from bzrlib.branch import Branch
0.171.22 by John Arbash Meinel
Cleanup import logic, and use lazy importing
34
from bzrlib.lazy_import import lazy_import
35
36
# lazy_import emailer so that it doesn't get loaded if it isn't used
37
lazy_import(globals(), """\
0.171.23 by John Arbash Meinel
Can't have a lazy imported object with the identical name as the actual module.
38
from bzrlib.plugins.email import emailer as _emailer
0.171.22 by John Arbash Meinel
Cleanup import logic, and use lazy importing
39
""")
0.171.4 by Robert Collins
basics are all there
40
0.171.3 by Robert Collins
convert the switch basics to an email plugin
41
42
def post_commit(branch, revision_id):
0.171.19 by Robert Collins
Update email plugin to support bzr 0.15 branch hooks.
43
    if not use_legacy:
44
        return
0.175.3 by John Arbash Meinel
Move guts into another file to improve startup time, fix bug when old revid is None.
45
    """This is the post_commit hook that should get run after commit."""
0.171.23 by John Arbash Meinel
Can't have a lazy imported object with the identical name as the actual module.
46
    _emailer.EmailSender(branch, revision_id, branch.get_config()).send_maybe()
0.171.3 by Robert Collins
convert the switch basics to an email plugin
47
48
0.171.19 by Robert Collins
Update email plugin to support bzr 0.15 branch hooks.
49
def branch_commit_hook(local, master, old_revno, old_revid, new_revno, new_revid):
0.171.21 by Robert Collins
Merge up with HEAD.
50
    """This is the post_commit hook that runs after commit."""
0.171.24 by John Arbash Meinel
Switch to using a local repository if available,
51
    _emailer.EmailSender(master, new_revid, master.get_config(),
52
                         local_branch=local).send_maybe()
0.171.19 by Robert Collins
Update email plugin to support bzr 0.15 branch hooks.
53
54
55
def install_hooks():
56
    """Install CommitSender to send after commits with bzr >= 0.15 """
57
    Branch.hooks.install_hook('post_commit', branch_commit_hook)
0.171.26 by Robert Collins
Name the email plugin for 0.18.
58
    if getattr(Branch.hooks, 'name_hook', None):
59
        Branch.hooks.name_hook(branch_commit_hook, "bzr-email")
0.171.19 by Robert Collins
Update email plugin to support bzr 0.15 branch hooks.
60
61
0.171.1 by Robert Collins
Start working toward publish - get a publishing_root option
62
def test_suite():
63
    from unittest import TestSuite
0.171.22 by John Arbash Meinel
Cleanup import logic, and use lazy importing
64
    import bzrlib.plugins.email.tests
0.171.1 by Robert Collins
Start working toward publish - get a publishing_root option
65
    result = TestSuite()
0.171.3 by Robert Collins
convert the switch basics to an email plugin
66
    result.addTest(bzrlib.plugins.email.tests.test_suite())
0.171.1 by Robert Collins
Start working toward publish - get a publishing_root option
67
    return result
68
0.171.19 by Robert Collins
Update email plugin to support bzr 0.15 branch hooks.
69
70
# setup the email plugin with > 0.15 hooks.
71
try:
72
    install_hooks()
73
    use_legacy = False
74
except AttributeError:
75
    # bzr < 0.15 - no Branch.hooks
76
    use_legacy = True
77
except errors.UnknownHook:
78
    # bzr 0.15 dev before post_commit was added
79
    use_legacy = True