167
167
return self._callable_names.get(a_callable, "No hook name")
169
def install_named_hook_lazy(self, hook_name, callable_module,
170
callable_member, name):
171
"""Install a_callable in to the hook hook_name lazily, and label it.
173
:param hook_name: A hook name. See the __init__ method for the complete
175
:param callable_module: Name of the module in which the callable is
177
:param callable_member: Member name of the callable.
178
:param name: A name to associate the callable with, to show users what
182
hook = self[hook_name]
184
raise errors.UnknownHook(self.__class__.__name__, hook_name)
186
hook_lazy = getattr(hook, "hook_lazy")
187
except AttributeError:
188
raise errors.UnsupportedOperation(self.install_named_hook_lazy,
191
hook_lazy(callable_module, callable_member, name)
169
193
def install_named_hook(self, hook_name, a_callable, name):
170
194
"""Install a_callable in to the hook hook_name, and label it name.
172
:param hook_name: A hook name. See the __init__ method of BranchHooks
173
for the complete list of hooks.
196
:param hook_name: A hook name. See the __init__ method for the complete
174
198
:param a_callable: The callable to be invoked when the hook triggers.
175
199
The exact signature will depend on the hook - see the __init__
176
method of BranchHooks for details on each hook.
200
method for details on each hook.
177
201
:param name: A name to associate a_callable with, to show users what is
250
274
return (type(other) == type(self) and
251
275
other.__dict__ == self.__dict__)
277
def hook_lazy(self, callback_module, callback_member, callback_label):
278
"""Lazily register a callback to be called when this HookPoint fires.
280
:param callback_module: Module of the callable to use when this
282
:param callback_member: Member name of the callback.
283
:param callback_label: A label to show in the UI while this callback is
286
obj_getter = registry._LazyObjectGetter(callback_module,
288
self._callbacks.append(obj_getter)
289
if callback_label is not None:
290
self._callback_names[obj_getter] = callback_label
253
292
def hook(self, callback, callback_label):
254
293
"""Register a callback to be called when this HookPoint fires.
257
296
:param callback_label: A label to show in the UI while this callback is
260
self._callbacks.append(callback)
299
obj_getter = registry._ObjectGetter(callback)
300
self._callbacks.append(obj_getter)
261
301
if callback_label is not None:
262
self._callback_names[callback] = callback_label
302
self._callback_names[obj_getter] = callback_label
264
304
def __iter__(self):
265
return iter(self._callbacks)
305
return (callback.get_obj() for callback in self._callbacks)
267
307
def __len__(self):
268
308
return len(self._callbacks)
272
312
strings.append("<%s(" % type(self).__name__)
273
313
strings.append(self.name)
274
314
strings.append("), callbacks=[")
275
for callback in self._callbacks:
276
strings.append(repr(callback))
315
callbacks = self._callbacks
316
for callback in callbacks:
317
strings.append(repr(callback.get_obj()))
277
318
strings.append("(")
278
319
strings.append(self._callback_names[callback])
279
320
strings.append("),")
280
if len(self._callbacks) == 1:
321
if len(callbacks) == 1:
281
322
strings[-1] = ")"
282
323
strings.append("]>")
283
324
return ''.join(strings)
322
363
hooks = known_hooks_key_to_object(hook_key)
323
364
segments.append(hooks.docs())
324
365
return '\n'.join(segments)
371
def install_lazy_named_hook(hookpoints_module, hookpoints_name, hook_name,
373
"""Install a callable in to a hook lazily, and label it name.
375
:param hookpoints_module: Module name of the hook points.
376
:param hookpoints_name: Name of the hook points.
377
:param hook_name: A hook name.
378
:param callable: a callable to call for the hook.
379
:param name: A name to associate a_callable with, to show users what is
382
key = (hookpoints_module, hookpoints_name, hook_name)
383
_lazy_hooks.setdefault(key, []).append((a_callable, name))