[kupfer] core: Separate plugin loading to its own module
- From: Ulrik Sverdrup <usverdrup src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [kupfer] core: Separate plugin loading to its own module
- Date: Thu, 4 Feb 2010 09:56:51 +0000 (UTC)
commit 40c0e2df78b0771a1dd42a76a4c2bcde3096dd45
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date: Thu Feb 4 00:08:55 2010 +0100
core: Separate plugin loading to its own module
kupfer/core/data.py | 38 ++++++++++++++----------------------
kupfer/core/pluginload.py | 46 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 61 insertions(+), 23 deletions(-)
---
diff --git a/kupfer/core/data.py b/kupfer/core/data.py
index 6cf48e0..17dd628 100644
--- a/kupfer/core/data.py
+++ b/kupfer/core/data.py
@@ -13,6 +13,7 @@ from kupfer import datatools
from kupfer.core import search, learn
from kupfer.core import settings
from kupfer.core import qfurl
+from kupfer.core import pluginload
from kupfer.core.sources import GetSourceController
@@ -527,36 +528,20 @@ class DataController (gobject.GObject, pretty.OutputMixin):
@s_souces as just as subitems
"""
from kupfer.core import plugins
- from kupfer.core.plugins import (load_plugin_sources, sources_attribute,
- action_decorators_attribute, text_sources_attribute,
- content_decorators_attribute,
- initialize_plugin)
s_sources = []
S_sources = []
setctl = settings.GetSettingsController()
- text_sources = []
- action_decorators = []
- content_decorators = []
-
for item in plugins.get_plugin_ids():
if not setctl.get_plugin_enabled(item):
continue
- initialize_plugin(item)
- text_sources.extend(load_plugin_sources(item, text_sources_attribute))
- action_decorators.extend(load_plugin_sources(item,
- action_decorators_attribute))
- # Register all Sources as (potential) content decorators
- content_decorators.extend(load_plugin_sources(item,
- sources_attribute, instantiate=False))
- content_decorators.extend(load_plugin_sources(item,
- content_decorators_attribute, instantiate=False))
+ sources = self._load_plugin(item)
if setctl.get_plugin_is_toplevel(item):
- S_sources.extend(load_plugin_sources(item))
+ S_sources.extend(sources)
else:
- s_sources.extend(load_plugin_sources(item))
+ s_sources.extend(sources)
D_dirs, d_dirs = self._get_directory_sources()
S_sources.extend(D_dirs)
@@ -564,12 +549,19 @@ class DataController (gobject.GObject, pretty.OutputMixin):
if not S_sources and not s_sources:
pretty.print_info(__name__, "No sources found!")
-
- self.register_text_sources(text_sources)
- self.register_action_decorators(action_decorators)
- self.register_content_decorators(content_decorators)
return S_sources, s_sources
+ def _load_plugin(self, plugin_id):
+ """
+ Load @plugin_id, register all its Actions, Content and TextSources.
+ Return its sources.
+ """
+ plugin = pluginload.load_plugin(plugin_id)
+ self.register_text_sources(plugin.text_sources)
+ self.register_action_decorators(plugin.action_decorators)
+ self.register_content_decorators(plugin.content_decorators)
+ return set(plugin.sources)
+
def _finish(self, sched):
self.output_info("Saving data...")
learn.finish()
diff --git a/kupfer/core/pluginload.py b/kupfer/core/pluginload.py
new file mode 100644
index 0000000..1b4f91e
--- /dev/null
+++ b/kupfer/core/pluginload.py
@@ -0,0 +1,46 @@
+from kupfer.core import plugins
+from kupfer.core.plugins import (load_plugin_sources, sources_attribute,
+ action_decorators_attribute, text_sources_attribute,
+ content_decorators_attribute,
+ initialize_plugin)
+
+class PluginDescription (object):
+ text_sources = ()
+ action_decorators = ()
+ content_decorators = ()
+ sources = ()
+
+def load_plugin(plugin_id):
+ """
+ @S_sources are to be included directly in the catalog,
+ @s_souces as just as subitems
+ """
+ sources = []
+ text_sources = []
+ action_decorators = []
+ content_decorators = []
+
+ item = plugin_id
+
+ initialize_plugin(item)
+ if not plugins.is_plugin_loaded(item):
+ return PluginDescription()
+ text_sources.extend(load_plugin_sources(item, text_sources_attribute))
+ action_decorators.extend(load_plugin_sources(item,
+ action_decorators_attribute))
+
+ # Register all Sources as (potential) content decorators
+ content_decorators.extend(load_plugin_sources(item,
+ sources_attribute, instantiate=False))
+ content_decorators.extend(load_plugin_sources(item,
+ content_decorators_attribute, instantiate=False))
+ sources.extend(load_plugin_sources(item))
+
+ desc = PluginDescription()
+
+ desc.text_sources = text_sources
+ desc.action_decorators = action_decorators
+ desc.content_decorators = content_decorators
+ desc.sources = sources
+ return desc
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]