aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authorGravatar Mason Larobina <mason.larobina@gmail.com>2010-04-04 20:17:30 +0800
committerGravatar Mason Larobina <mason.larobina@gmail.com>2010-04-04 20:17:30 +0800
commit49b32de5e537009e718b7422404e984bad6be007 (patch)
treeba63465ce8fa4b481833fdc0f6c22a00dbc2d23f /examples
parentd3cbe16bf16ff63c0e3db15d645e958712bd02d8 (diff)
Require plugins have either a init, after or cleanup hook.
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/data/scripts/uzbl-event-manager17
1 files changed, 12 insertions, 5 deletions
diff --git a/examples/data/scripts/uzbl-event-manager b/examples/data/scripts/uzbl-event-manager
index 75a1c13..ab13fbb 100755
--- a/examples/data/scripts/uzbl-event-manager
+++ b/examples/data/scripts/uzbl-event-manager
@@ -189,7 +189,8 @@ class Plugin(object):
self.handlers = set([])
# Plugins init hook
- self.init = getattr(plugin, 'init')
+ init = getattr(plugin, 'init', None)
+ self.init = init if callable(init) else None
# Plugins optional after hook
after = getattr(plugin, 'after', None)
@@ -199,6 +200,8 @@ class Plugin(object):
cleanup = getattr(plugin, 'cleanup', None)
self.cleanup = cleanup if callable(cleanup) else None
+ assert init or after or cleanup, "missing hooks in plugin"
+
# Export plugin's instance methods to plugin namespace
for attr in self.special_functions:
plugin.__dict__[attr] = getattr(self, attr)
@@ -328,8 +331,9 @@ class Uzbl(object):
# Initialise each plugin with the current uzbl instance.
for plugin in self.parent.plugins.values():
- self.logger.debug('calling %r plugin init hook' % plugin.name)
- plugin.init(self)
+ if plugin.init:
+ self.logger.debug('calling %r plugin init hook' % plugin.name)
+ plugin.init(self)
# Allow plugins to use exported features of other plugins by calling an
# optional `after` function in the plugins namespace.
@@ -518,8 +522,11 @@ class UzblEventDaemon(object):
info = imp.find_module(name, [dir,])
module = imp.load_module(name, *info)
- assert callable(getattr(module, 'init', None)),\
- "plugin missing init function: %r" % module
+
+ # Check if the plugin has a callable hook.
+ hooks = filter(callable, [getattr(module, attr, None) \
+ for attr in ['init', 'after', 'cleanup']])
+ assert hooks, "no hooks in plugin %r" % module
logger.debug('creating plugin instance for %r plugin' % name)
plugin = Plugin(self, name, path, module)