diff options
author | René 'Necoro' Neumann <necoro@necoro.net> | 2009-08-13 13:31:36 +0200 |
---|---|---|
committer | René 'Necoro' Neumann <necoro@necoro.net> | 2009-08-13 13:31:36 +0200 |
commit | a4bad326bc4032ff257f964df6d86681654c1259 (patch) | |
tree | 746c1348825b0e8dff4b4e0ff9435d132e3396d7 | |
parent | 1ff4d3590fe8e788736e9ebf6700bdd6aa3773f3 (diff) | |
download | portato-a4bad326bc4032ff257f964df6d86681654c1259.tar.gz portato-a4bad326bc4032ff257f964df6d86681654c1259.tar.bz2 portato-a4bad326bc4032ff257f964df6d86681654c1259.zip |
Make plugins more exception aware and exception safe
Diffstat (limited to '')
-rw-r--r-- | plugins/package_details.py | 7 | ||||
-rw-r--r-- | portato/plugin.py | 33 |
2 files changed, 33 insertions, 7 deletions
diff --git a/plugins/package_details.py b/plugins/package_details.py index 6a17f1e..7d739a3 100644 --- a/plugins/package_details.py +++ b/plugins/package_details.py @@ -23,13 +23,20 @@ class Detail (WidgetPlugin): """ __author__ = "René 'Necoro' Neumann" + _view_ = None _old_pkg = None + _widget_ = None + _widget_name_ = None def init(self): + raise Exception, "e" self.add_call("update_table", self._update, type = "after") def widget_init (self): + if (self._widget_ is None) or (self._widget_name_ is None): + raise PluginLoadException, ("Has not set _widget_ or _widget_name_.") + self.add_widget("Package Notebook", (self._widget_, self._widget_name_)) # if the detail was updated before it was actually initialized, update it again :) diff --git a/portato/plugin.py b/portato/plugin.py index 0da14f1..23f382a 100644 --- a/portato/plugin.py +++ b/portato/plugin.py @@ -300,6 +300,11 @@ class Plugin (object): """ self.__calls.append(Call(self, hook, callable, type, dep)) + def __str__ (self): + return self.name + + __repr__ = __str__ + class WidgetPlugin (Plugin): def __init__ (self, *args, **kwargs): @@ -430,25 +435,33 @@ class PluginQueue (object): plugin_module.__builtins__["Plugin"] = Plugin plugin_module.__builtins__["WidgetPlugin"] = WidgetPlugin plugin_module.__builtins__["register"] = register + plugin_module.__builtins__["PluginLoadException"] = PluginLoadException for p in plugins: # import them try: exec "from portato.plugins import %s" % p in {} except PluginLoadException, e: - error(_("Loading plugin '%(plugin)s' failed: %(error)s"), {"plugin" : p, "error" : e.message}) + error(_("Loading plugin module '%(plugin)s' failed: %(error)s"), {"plugin" : p, "error" : e}) except: tb = traceback.format_exc() - error(_("Loading plugin '%(plugin)s' failed: %(error)s"), {"plugin" : p, "error" : tb}) + error(_("Loading plugin module '%(plugin)s' failed: %(error)s"), {"plugin" : p, "error" : tb}) self._organize() def load_widgets(self, window): for p in self.plugins: if isinstance(p, WidgetPlugin): - p._widget_init(window) - for w in p.widgets: - WidgetSlot.slots[w.slot].add_widget(w) - info(_("Widgets of plugin '%s' loaded."), p.name) + try: + p._widget_init(window) + except PluginLoadException, e: + error(_("Loading widgets plugin '%(plugin)s' failed: %(error)s"), {"plugin" : p, "error" : e}) + except: + tb = traceback.format_exc() + error(_("Loading widgets of plugin '%(plugin)s' failed: %(error)s"), {"plugin" : p, "error" : tb}) + else: + for w in p.widgets: + WidgetSlot.slots[w.slot].add_widget(w) + info(_("Widgets of plugin '%s' loaded."), p.name) def add (self, plugin, disable = False): """ @@ -683,4 +696,10 @@ def register (plugin, disable = False): :see: `PluginQueue.add` """ if __plugins is not None: - __plugins.add(plugin, disable) + try: + __plugins.add(plugin, disable) + except PluginLoadException, e: + error(_("Registrating plugin '%(plugin)s' failed: %(error)s"), {"plugin" : plugin, "error" : e}) + except: + tb = traceback.format_exc() + error(_("Registrating plugin '%(plugin)s' failed: %(error)s"), {"plugin" : plugin, "error" : tb}) |