~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/hooks.py

(jelmer) Use the absolute_import feature everywhere in bzrlib,
 and add a source test to make sure it's used everywhere. (Jelmer Vernooij)

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
 
 
18
17
"""Support for plugin hooking logic."""
19
18
 
 
19
from __future__ import absolute_import
 
20
 
20
21
from bzrlib import (
21
22
    registry,
22
23
    symbol_versioning,
127
128
        """
128
129
        dict.__init__(self)
129
130
        self._callable_names = {}
 
131
        self._lazy_callable_names = {}
130
132
        self._module = module
131
133
        self._member_name = member_name
132
134
 
196
198
        the code names are rarely meaningful for end users and this is not
197
199
        intended for debugging.
198
200
        """
199
 
        return self._callable_names.get(a_callable, "No hook name")
 
201
        name = self._callable_names.get(a_callable, None)
 
202
        if name is None and a_callable is not None:
 
203
            name = self._lazy_callable_names.get((a_callable.__module__,
 
204
                                                  a_callable.__name__),
 
205
                                                 None)
 
206
        if name is None:
 
207
            return 'No hook name'
 
208
        return name
 
209
 
200
210
 
201
211
    def install_named_hook_lazy(self, hook_name, callable_module,
202
212
        callable_member, name):
221
231
                self)
222
232
        else:
223
233
            hook_lazy(callable_module, callable_member, name)
 
234
        if name is not None:
 
235
            self.name_hook_lazy(callable_module, callable_member, name)
224
236
 
225
237
    def install_named_hook(self, hook_name, a_callable, name):
226
238
        """Install a_callable in to the hook hook_name, and label it name.
266
278
        """Associate name with a_callable to show users what is running."""
267
279
        self._callable_names[a_callable] = name
268
280
 
 
281
    def name_hook_lazy(self, callable_module, callable_member, callable_name):
 
282
        self._lazy_callable_names[(callable_module, callable_member)]= \
 
283
            callable_name
 
284
 
269
285
 
270
286
class HookPoint(object):
271
287
    """A single hook that clients can register to be called back when it fires.