[kupfer] core: Allow unloading / disabling plugins at runtime
- From: Ulrik Sverdrup <usverdrup src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [kupfer] core: Allow unloading / disabling plugins at runtime
- Date: Sun, 9 May 2010 15:55:53 +0000 (UTC)
commit 88cbe4fdef4fb0d187aa7b745c6ee71e2534952a
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date: Sun May 9 16:25:25 2010 +0100
core: Allow unloading / disabling plugins at runtime
kupfer/core/data.py | 20 ++++++++++++++++++--
kupfer/core/pluginload.py | 3 +++
kupfer/core/plugins.py | 4 ++++
kupfer/core/sources.py | 2 +-
4 files changed, 26 insertions(+), 3 deletions(-)
---
diff --git a/kupfer/core/data.py b/kupfer/core/data.py
index 9fe1f2a..a0865d6 100644
--- a/kupfer/core/data.py
+++ b/kupfer/core/data.py
@@ -492,7 +492,7 @@ class DataController (gobject.GObject, pretty.OutputMixin):
sc.add(None, D_s, toplevel=True)
sc.add(None, d_s, toplevel=False)
sc.initialize()
- self.source_pane.source_rebase(sc.root)
+ self._reload_source_root()
learn.load()
def _get_directory_sources(self):
@@ -559,7 +559,23 @@ class DataController (gobject.GObject, pretty.OutputMixin):
from kupfer.core import plugins
if enabled and not plugins.is_plugin_loaded(plugin_id):
sources = self._load_plugin(plugin_id)
- self._insert_sources(plugin_id, sources)
+ self._insert_sources(plugin_id, sources, initialize=True)
+ elif not enabled:
+ self._remove_plugin(plugin_id)
+
+ def _remove_plugin(self, plugin_id):
+ sc = GetSourceController()
+ if sc.remove_objects_for_plugin_id(plugin_id):
+ self._reload_source_root()
+ pluginload.remove_plugin(plugin_id)
+
+ def _reload_source_root(self):
+ self.output_debug("Reloading source root")
+ sc = GetSourceController()
+ self.source_pane.source_rebase(sc.root)
+
+ def _plugin_catalog_changed(self, setctl, plugin_id, toplevel):
+ self._reload_source_root()
def _insert_sources(self, plugin_id, sources, initialize=True):
if not sources:
diff --git a/kupfer/core/pluginload.py b/kupfer/core/pluginload.py
index 03fb5e1..75e1d33 100644
--- a/kupfer/core/pluginload.py
+++ b/kupfer/core/pluginload.py
@@ -66,3 +66,6 @@ def exception_guard(name, callback=None, *args):
pretty.print_error(__name__, "Please file a bug report")
if callback is not None:
callback(*args)
+
+def remove_plugin(plugin_id):
+ plugins.unimport_plugin(plugin_id)
diff --git a/kupfer/core/plugins.py b/kupfer/core/plugins.py
index e5de73a..7470862 100644
--- a/kupfer/core/plugins.py
+++ b/kupfer/core/plugins.py
@@ -367,6 +367,10 @@ def initialize_plugin(plugin_name):
return
settings_dict.initialize(plugin_name)
+def unimport_plugin(plugin_name):
+ del _imported_plugins[plugin_name]
+ sys.modules.pop(".".join(_plugin_path(plugin_name)))
+
def get_plugin_error(plugin_name):
"""
Return None if plugin is loaded without error, else
diff --git a/kupfer/core/sources.py b/kupfer/core/sources.py
index 590e828..9957c7e 100644
--- a/kupfer/core/sources.py
+++ b/kupfer/core/sources.py
@@ -322,7 +322,7 @@ class SourceController (pretty.OutputMixin):
for typ in self.action_decorators:
remove_matching_objects(self.action_decorators[typ], plugin_id)
- remove_matching_objects(self.action_generators[typ], plugin_id)
+ remove_matching_objects(self.action_generators, plugin_id)
return removed_source
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]