~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/hooks.py

  • Committer: Jelmer Vernooij
  • Date: 2011-02-21 15:09:19 UTC
  • mto: This revision was merged to the branch mainline in revision 5675.
  • Revision ID: jelmer@samba.org-20110221150919-v7nnbontcuhi1dmu
Move Repository._find_text_key_references_from_xml_inventory_lines onto the serializer.

Show diffs side-by-side

added added

removed removed

Lines of Context:
145
145
        else:
146
146
            callbacks = None
147
147
        hookpoint = HookPoint(name=name, doc=doc, introduced=introduced,
148
 
                              deprecated=deprecated, callbacks=callbacks)
 
148
                              deprecated=deprecated,
 
149
                              callbacks=callbacks)
149
150
        self[name] = hookpoint
150
151
 
151
 
    @symbol_versioning.deprecated_method(symbol_versioning.deprecated_in((2, 4)))
152
152
    def create_hook(self, hook):
153
153
        """Create a hook which can have callbacks registered for it.
154
154
 
243
243
        if name is not None:
244
244
            self.name_hook(a_callable, name)
245
245
 
246
 
    def uninstall_named_hook(self, hook_name, label):
247
 
        """Uninstall named hooks.
248
 
 
249
 
        :param hook_name: Hook point name
250
 
        :param label: Label of the callable to uninstall
251
 
        """
252
 
        try:
253
 
            hook = self[hook_name]
254
 
        except KeyError:
255
 
            raise errors.UnknownHook(self.__class__.__name__, hook_name)
256
 
        try:
257
 
            uninstall = getattr(hook, "uninstall")
258
 
        except AttributeError:
259
 
            raise errors.UnsupportedOperation(self.install_named_hook_lazy,
260
 
                self)
261
 
        else:
262
 
            uninstall(label)
263
 
 
264
246
    def name_hook(self, a_callable, name):
265
247
        """Associate name with a_callable to show users what is running."""
266
248
        self._callable_names[a_callable] = name
346
328
        obj_getter = registry._ObjectGetter(callback)
347
329
        self._callbacks.append((obj_getter, callback_label))
348
330
 
349
 
    def uninstall(self, label):
350
 
        """Uninstall the callback with the specified label.
351
 
 
352
 
        :param label: Label of the entry to uninstall
353
 
        """
354
 
        entries_to_remove = []
355
 
        for entry in self._callbacks:
356
 
            (entry_callback, entry_label) = entry
357
 
            if entry_label == label:
358
 
                entries_to_remove.append(entry)
359
 
        if entries_to_remove == []:
360
 
            raise KeyError("No entry with label %r" % label)
361
 
        for entry in entries_to_remove:
362
 
            self._callbacks.remove(entry)
363
 
 
364
331
    def __iter__(self):
365
332
        return (callback.get_obj() for callback, name in self._callbacks)
366
333
 
425
392
    return '\n'.join(segments)
426
393
 
427
394
 
428
 
# Lazily registered hooks. Maps (module, name, hook_name) tuples
429
 
# to lists of tuples with objectgetters and names
430
395
_lazy_hooks = {}
431
396
 
432
397