~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/hooks.py

show names for lazy loaded hooks

Show diffs side-by-side

added added

removed removed

Lines of Context:
127
127
        """
128
128
        dict.__init__(self)
129
129
        self._callable_names = {}
 
130
        self._lazy_callable_names = {}
130
131
        self._module = module
131
132
        self._member_name = member_name
132
133
 
196
197
        the code names are rarely meaningful for end users and this is not
197
198
        intended for debugging.
198
199
        """
199
 
        return self._callable_names.get(a_callable, "No hook name")
 
200
        name = self._callable_names.get(a_callable, None)
 
201
        if name is None and a_callable is not None:
 
202
            name = self._lazy_callable_names.get((a_callable.__module__,
 
203
                                                  a_callable.__name__),
 
204
                                                 None)
 
205
        if name is None:
 
206
            return 'No hook name'
 
207
        return name
 
208
 
200
209
 
201
210
    def install_named_hook_lazy(self, hook_name, callable_module,
202
211
        callable_member, name):
221
230
                self)
222
231
        else:
223
232
            hook_lazy(callable_module, callable_member, name)
 
233
        if name is not None:
 
234
            self.name_hook_lazy(callable_module, callable_member, name)
224
235
 
225
236
    def install_named_hook(self, hook_name, a_callable, name):
226
237
        """Install a_callable in to the hook hook_name, and label it name.
266
277
        """Associate name with a_callable to show users what is running."""
267
278
        self._callable_names[a_callable] = name
268
279
 
 
280
    def name_hook_lazy(self, callable_module, callable_member, callable_name):
 
281
        self._lazy_callable_names[(callable_module, callable_member)]= \
 
282
            callable_name
 
283
 
269
284
 
270
285
class HookPoint(object):
271
286
    """A single hook that clients can register to be called back when it fires.