~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/hooks.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-04-02 00:59:52 UTC
  • mfrom: (5622.4.4 uninstall-hook)
  • Revision ID: pqm@pqm.ubuntu.com-20110402005952-kxcwbwdk6jagtfwm
(jelmer) Add Hooks.uninstall_named_hook(). (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
246
264
    def name_hook(self, a_callable, name):
247
265
        """Associate name with a_callable to show users what is running."""
248
266
        self._callable_names[a_callable] = name
328
346
        obj_getter = registry._ObjectGetter(callback)
329
347
        self._callbacks.append((obj_getter, callback_label))
330
348
 
 
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
 
331
364
    def __iter__(self):
332
365
        return (callback.get_obj() for callback, name in self._callbacks)
333
366