[KSS-checkins] r48504 - in kukit/kss.zope/trunk/kss/zope: . tests

jvloothuis at codespeak.net jvloothuis at codespeak.net
Sat Nov 10 14:04:08 CET 2007


Author: jvloothuis
Date: Sat Nov 10 14:04:07 2007
New Revision: 48504

Added:
   kukit/kss.zope/trunk/kss/zope/registry.py
   kukit/kss.zope/trunk/kss/zope/registry.txt
   kukit/kss.zope/trunk/kss/zope/tests/
   kukit/kss.zope/trunk/kss/zope/tests/__init__.py
   kukit/kss.zope/trunk/kss/zope/tests/test_globalregistry.py
Modified:
   kukit/kss.zope/trunk/kss/zope/configure.zcml
   kukit/kss.zope/trunk/kss/zope/interfaces.py
Log:

Added a global utility which provides a way for querying the available
plugins and their resources.


Modified: kukit/kss.zope/trunk/kss/zope/configure.zcml
==============================================================================
--- kukit/kss.zope/trunk/kss/zope/configure.zcml	(original)
+++ kukit/kss.zope/trunk/kss/zope/configure.zcml	Sat Nov 10 14:04:07 2007
@@ -1,2 +1,6 @@
 <configure xmlns="http://namespaces.zope.org/zope">
+
+  <utility factory=".registry.GlobalPluginRegistry"
+           permission="zope.Public" />
+
 </configure>

Modified: kukit/kss.zope/trunk/kss/zope/interfaces.py
==============================================================================
--- kukit/kss.zope/trunk/kss/zope/interfaces.py	(original)
+++ kukit/kss.zope/trunk/kss/zope/interfaces.py	Sat Nov 10 14:04:07 2007
@@ -17,6 +17,32 @@
 
 from zope.interface import Interface, Attribute
 
+
+class IKSSPluginRegistry(Interface):
+    '''This registry can query the activate plugins and their
+    resources.
+    '''
+
+    def plugins():
+        '''Returns an iterator with all activate plugins.
+
+        Each item from the iterator is a tuple with (id, plugin_config).'''
+
+    def javascripts():
+        '''Return an iterable of filenames for all Javascripts.
+
+        The Javascripts are loaded from the registrations of activate plugins.'''
+
+    def extra_javascripts():
+        '''Return an iterable of filenames for all extra Javascripts.
+
+        The extra Javascripts are loaded from the registrations of activate plugins.'''
+
+    def lookup_commandset(id):
+        '''Return a commandset class for the given id'''
+
+
+# from kss.core
 class IKSSCommands(Interface):
     'KSS commands'
 

Added: kukit/kss.zope/trunk/kss/zope/registry.py
==============================================================================
--- (empty file)
+++ kukit/kss.zope/trunk/kss/zope/registry.py	Sat Nov 10 14:04:07 2007
@@ -0,0 +1,24 @@
+from zope import interface
+from kss.base.plugin import activated_plugins
+
+from kss.zope.interfaces import IKSSPluginRegistry
+
+class GlobalPluginRegistry(object):
+    interface.implements(IKSSPluginRegistry)
+
+    def plugins(self):
+        return activated_plugins()
+
+    def javascripts(self):
+        for id, config in self.plugins():
+            for javascript in config.javascripts:
+                yield javascript
+
+    def extra_javascripts(self):
+        for id, config in self.plugins():
+            for extra_javascript in config.extra_javascripts:
+                yield extra_javascript
+
+
+    def lookup_commandset(self, id):
+        pass

Added: kukit/kss.zope/trunk/kss/zope/registry.txt
==============================================================================
--- (empty file)
+++ kukit/kss.zope/trunk/kss/zope/registry.txt	Sat Nov 10 14:04:07 2007
@@ -0,0 +1,61 @@
+Plugin registries
+=================
+
+The plugin registries keep track of all available plugins. They also
+have a few methods for getting resources from the plugins.
+
+
+Global registry
+===============
+
+We ship with a default global registry.
+
+  >>> from kss.zope.registry import GlobalPluginRegistry
+
+All registries should implement the IKSSPluginRegistry interface.
+
+  >>> from kss.zope.interfaces import IKSSPluginRegistry
+  >>> IKSSPluginRegistry.implementedBy(GlobalPluginRegistry)
+  True
+
+No arguments are need to create the registry.
+
+  >>> registry = GlobalPluginRegistry()
+
+When we set it up all its methods should return the appropriate empty
+values. The examples below demonstrate the basic querying methods
+available.
+
+  >>> list(registry.plugins())
+  []
+
+  >>> list(registry.javascripts())
+  []
+
+  >>> list(registry.extra_javascripts())
+  []
+
+Since we depend on `kss.base` which has a plugin called `kss-core` we
+can use this to setup a more interesting registry.
+
+  >>> from kss.base import load_plugins
+  >>> load_plugins('kss-core')
+
+This should have activated the core plugin. Now let's look at the
+results.
+
+  >>> list(registry.plugins())
+  [('kss-core', <kss.base.config.KSSCore object at ...>)]
+
+  >>> list(registry.javascripts())
+  ['.../kukit/utils.js', '.../kukit/errors.js', ...]
+
+
+  >>> list(registry.extra_javascripts())
+  ['.../3rd_party/base2-dom-fp.js', '.../3rd_party/sarissa.js']
+
+Now we will unload the plugin again to clean up.
+
+  >>> from kss.base.plugin import unload_plugins
+  >>> unload_plugins('kss-core')
+ 

Added: kukit/kss.zope/trunk/kss/zope/tests/__init__.py
==============================================================================

Added: kukit/kss.zope/trunk/kss/zope/tests/test_globalregistry.py
==============================================================================
--- (empty file)
+++ kukit/kss.zope/trunk/kss/zope/tests/test_globalregistry.py	Sat Nov 10 14:04:07 2007
@@ -0,0 +1,12 @@
+import unittest
+
+from zope.testing import doctest
+
+def test_suite():
+    return unittest.TestSuite([
+        doctest.DocFileSuite(
+                'registry.txt',
+                package='kss.zope',
+                optionflags=doctest.ELLIPSIS|doctest.REPORT_ONLY_FIRST_FAILURE,
+)
+        ])


More information about the Kukit-checkins mailing list