add a way for callback to disable itself

The idea is that some plugin would not be called in some
specific case, and the callback should decide by itself.

Having a way to globally disable it is much cleaner than
disabling every method one by one on the plugin side.

My use case is for fedora-infrastructure that cannot be run
from git checkout since it try to connect to the message bus,
but another case would be to bootstrap infrastructure, or to
run the code on a test servers without having all the callback
infrastructure setup.
This commit is contained in:
Michael Scherer 2013-08-12 22:16:32 +02:00
parent 10a0f03cdc
commit 12bf9a8b69
3 changed files with 20 additions and 2 deletions

View file

@ -144,6 +144,10 @@ def display(msg, color=None, stderr=False, screen_only=False, log_only=False, ru
def call_callback_module(method_name, *args, **kwargs):
for callback_plugin in callback_plugins:
# a plugin that set self.disabled to True will not be called
# see osx_say.py example for such a plugin
if getattr(callback_plugin, 'disabled', False):
continue
methods = [
getattr(callback_plugin, method_name, None),
getattr(callback_plugin, 'on_any', None)