~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/hooks.py

  • Committer: Samuel Bronson
  • Date: 2012-08-30 20:36:18 UTC
  • mto: (6015.57.3 2.4)
  • mto: This revision was merged to the branch mainline in revision 6558.
  • Revision ID: naesten@gmail.com-20120830203618-y2dzw91nqpvpgxvx
Update INSTALL for switch to Python 2.6 and up.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
 
17
 
17
18
"""Support for plugin hooking logic."""
18
19
 
19
 
from __future__ import absolute_import
20
 
 
21
20
from bzrlib import (
22
21
    registry,
23
22
    symbol_versioning,
31
30
    errors,
32
31
    pyutils,
33
32
    )
34
 
from bzrlib.i18n import gettext
35
33
""")
36
34
 
37
35
 
72
70
 
73
71
_builtin_known_hooks = (
74
72
    ('bzrlib.branch', 'Branch.hooks', 'BranchHooks'),
75
 
    ('bzrlib.controldir', 'ControlDir.hooks', 'ControlDirHooks'),
 
73
    ('bzrlib.bzrdir', 'BzrDir.hooks', 'BzrDirHooks'),
76
74
    ('bzrlib.commands', 'Command.hooks', 'CommandHooks'),
77
75
    ('bzrlib.config', 'ConfigHooks', '_ConfigHooks'),
78
76
    ('bzrlib.info', 'hooks', 'InfoHooks'),
83
81
    ('bzrlib.smart.client', '_SmartClient.hooks', 'SmartClientHooks'),
84
82
    ('bzrlib.smart.server', 'SmartTCPServer.hooks', 'SmartServerHooks'),
85
83
    ('bzrlib.status', 'hooks', 'StatusHooks'),
86
 
    ('bzrlib.transport', 'Transport.hooks', 'TransportHooks'),
87
84
    ('bzrlib.version_info_formats.format_rio', 'RioVersionInfoBuilder.hooks',
88
85
        'RioVersionInfoBuilderHooks'),
89
86
    ('bzrlib.merge_directive', 'BaseMergeDirective.hooks',
129
126
        """
130
127
        dict.__init__(self)
131
128
        self._callable_names = {}
132
 
        self._lazy_callable_names = {}
133
129
        self._module = module
134
130
        self._member_name = member_name
135
131
 
199
195
        the code names are rarely meaningful for end users and this is not
200
196
        intended for debugging.
201
197
        """
202
 
        name = self._callable_names.get(a_callable, None)
203
 
        if name is None and a_callable is not None:
204
 
            name = self._lazy_callable_names.get((a_callable.__module__,
205
 
                                                  a_callable.__name__),
206
 
                                                 None)
207
 
        if name is None:
208
 
            return 'No hook name'
209
 
        return name
210
 
 
 
198
        return self._callable_names.get(a_callable, "No hook name")
211
199
 
212
200
    def install_named_hook_lazy(self, hook_name, callable_module,
213
201
        callable_member, name):
232
220
                self)
233
221
        else:
234
222
            hook_lazy(callable_module, callable_member, name)
235
 
        if name is not None:
236
 
            self.name_hook_lazy(callable_module, callable_member, name)
237
223
 
238
224
    def install_named_hook(self, hook_name, a_callable, name):
239
225
        """Install a_callable in to the hook hook_name, and label it name.
279
265
        """Associate name with a_callable to show users what is running."""
280
266
        self._callable_names[a_callable] = name
281
267
 
282
 
    def name_hook_lazy(self, callable_module, callable_member, callable_name):
283
 
        self._lazy_callable_names[(callable_module, callable_member)]= \
284
 
            callable_name
285
 
 
286
268
 
287
269
class HookPoint(object):
288
270
    """A single hook that clients can register to be called back when it fires.
328
310
            introduced_string = _format_version_tuple(self.introduced)
329
311
        else:
330
312
            introduced_string = 'unknown'
331
 
        strings.append(gettext('Introduced in: %s') % introduced_string)
 
313
        strings.append('Introduced in: %s' % introduced_string)
332
314
        if self.deprecated:
333
315
            deprecated_string = _format_version_tuple(self.deprecated)
334
 
            strings.append(gettext('Deprecated in: %s') % deprecated_string)
 
316
            strings.append('Deprecated in: %s' % deprecated_string)
335
317
        strings.append('')
336
318
        strings.extend(textwrap.wrap(self.__doc__,
337
319
            break_long_words=False))