~jteh/bzr-email/pushPullEnhancements

« back to all changes in this revision

Viewing changes to __init__.py

  • Committer: James Teh
  • Date: 2011-06-08 07:08:58 UTC
  • mfrom: (40.2.9 trunk)
  • Revision ID: jamie@jantrid.net-20110608070858-mmmg2in7iobmzp28
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
58
58
 - Any other value: Run the value expecting it to behave like ``/usr/bin/mail``
59
59
   - in particular supporting the -s and -a options.
60
60
 
 
61
When using smtplib, you can specify additional headers to be included in the
 
62
mail by setting the 'revision_mail_headers' configuration option - something like::
 
63
 
 
64
  revision_mail_headers=X-Cheese: to the rescue!
61
65
"""
62
66
 
63
67
 
80
84
 
81
85
def post_commit(branch, revision_id):
82
86
    """This is the post_commit hook that should get run after commit."""
83
 
    if not use_legacy:
84
 
        return
85
87
    _emailer.EmailSender(branch, revision_id, branch.get_config()).send_maybe()
86
88
 
87
89
 
105
107
            params.branch.get_config(), local_branch=None, op='change').send_maybe()
106
108
 
107
109
 
108
 
def install_hooks():
109
 
    """Install CommitSender to send after commits with bzr >= 0.15 """
110
 
    install_named_hook = getattr(Branch.hooks, 'install_named_hook', None)
111
 
    if install_named_hook is not None:
112
 
        install_named_hook('post_commit', branch_commit_hook, 'bzr-email')
113
 
        if 'post_change_branch_tip' in Branch.hooks:
114
 
            install_named_hook('post_change_branch_tip',
115
 
                branch_post_change_hook, 'bzr-email')
116
 
    else:
117
 
        Branch.hooks.install_hook('post_commit', branch_commit_hook)
118
 
        if getattr(Branch.hooks, 'name_hook', None) is not None:
119
 
            Branch.hooks.name_hook(branch_commit_hook, "bzr-email")
120
 
 
121
 
 
122
110
def test_suite():
123
111
    from unittest import TestSuite
124
112
    import bzrlib.plugins.email.tests
127
115
    return result
128
116
 
129
117
 
130
 
# setup the email plugin with > 0.15 hooks.
131
 
try:
132
 
    install_hooks()
133
 
    use_legacy = False
134
 
except AttributeError:
135
 
    # bzr < 0.15 - no Branch.hooks
136
 
    use_legacy = True
137
 
except errors.UnknownHook:
138
 
    # bzr 0.15 dev before post_commit was added
139
 
    use_legacy = True
 
118
Branch.hooks.install_named_hook('post_commit', branch_commit_hook, 'bzr-email')
 
119
Branch.hooks.install_named_hook('post_change_branch_tip', branch_post_change_hook,
 
120
    'bzr-email')