Author: reebalazs
Date: Sun Nov 11 16:00:20 2007
New Revision: 48570

Modified:
   kukit/kss.zope/trunk/kss/core/plugins/core/configure.zcml
   kukit/kss.zope/trunk/kss/zope/bbb/configure.py
   kukit/kss.zope/trunk/kss/zope/registry.py
   kukit/kss.zope/trunk/kss/zope/registry.txt
Log:
Fix BBB for comandsets, javascript

Modified: kukit/kss.zope/trunk/kss/core/plugins/core/configure.zcml
==============================================================================
--- kukit/kss.zope/trunk/kss/core/plugins/core/configure.zcml   (original)
+++ kukit/kss.zope/trunk/kss/core/plugins/core/configure.zcml   Sun Nov 11 
16:00:20 2007
@@ -416,11 +416,13 @@
 
     <!-- Command sets -->
     
+    <!-- XXX is already in kss.base
     <kss:commandset
         name="core"
         for="kss.core.interfaces.IKSSView"
         provides=".interfaces.IKSSCoreCommands"
         class=".commands.KSSCoreCommands"
         />
+    -->
 
 </configure>

Modified: kukit/kss.zope/trunk/kss/zope/bbb/configure.py
==============================================================================
--- kukit/kss.zope/trunk/kss/zope/bbb/configure.py      (original)
+++ kukit/kss.zope/trunk/kss/zope/bbb/configure.py      Sun Nov 11 16:00:20 2007
@@ -1,7 +1,11 @@
 
 from deprecated import deprecated_directive
 from kss.zope.ttw import allowCommandset
-from kss.zope.registry import BBB_register_javascript, BBB_register_commandset
+from kss.zope.registry import (
+    BBB_register_javascript, 
+    BBB_get_commandsets,
+    BBB_register_commandset,
+    )
 
 when = 'after 2008-08-01'
 
@@ -24,6 +28,9 @@
 registerAction = deprecated_directive('kss:action', 'use python level registry 
instead', when)(registerFor('action'))
 registerParamProvider = deprecated_directive('kss:paramprovider', 'use python 
level registry instead', when)(registerFor('paramprovider'))
 
+class BBBKSSRegistrationError(Exception):
+    pass
+
 def doRegisterCommandSet(class_, name, provides, *arg, **kw):
     # provides is ignored
     provides                    # to satisfy pyflakes
@@ -36,6 +43,18 @@
 @deprecated_directive('kss:commandset', 'use python level registry instead', 
when)
 def registerCommandSet(_context, for_, class_, name, provides):
     'Directive that registers a command set' 
+    # check the commandset on python level
+    python_commandsets = BBB_get_commandsets()
+    if name in python_commandsets:
+        # duplicate name
+        klass = python_commandsets[name]
+        classname = klass.__module__ + '.' + klass.__name__
+        if classname != class_:
+            raise BBBKSSRegistrationError, \
+                'The commandset "%s" is already registered on the python 
level, ' \
+                'and classes differ %s != %s' % \
+                (name, classname, class_)
+ 
     _context.action(
         discriminator = ('registerKssCommandSet', name),
         callable = doRegisterCommandSet,

Modified: kukit/kss.zope/trunk/kss/zope/registry.py
==============================================================================
--- kukit/kss.zope/trunk/kss/zope/registry.py   (original)
+++ kukit/kss.zope/trunk/kss/zope/registry.py   Sun Nov 11 16:00:20 2007
@@ -42,14 +42,28 @@
 #=============================================
 # Stuff needed for compatibility features
 #=============================================
+
+def BBB_get_commandsets():
+    '''Returns python level registered commandsets
+    allows to avoid double registration'''
+    # XXX a direct method for returninf the dict would be better
+    commandsets = {}
+    for plugin_id, config in available_plugins():
+        commandsets.update(config.commandsets)
+    return commandsets
+           
 def BBB_register_commandset(id, factory):
-    # make sure we only register when we do not have a better
-    # (new-style plugin) commandset
-    if not id in BBB_commandsets:
-        BBB_commandsets[id] = factory
+    # Caller should check for duplicates.
+    BBB_commandsets[id] = factory
 
 def BBB_register_javascript(filename):
-    if filename not in BBB_javascripts:
+    # XXX a direct call to get them would be better.
+    javascripts = []
+    for id, config in available_plugins():
+        for javascript in config.javascripts:
+            javascripts.append(javascript)
+    #
+    if filename not in javascripts:
         BBB_javascripts.append(filename)
 
 def BBB_clear_out():

Modified: kukit/kss.zope/trunk/kss/zope/registry.txt
==============================================================================
--- kukit/kss.zope/trunk/kss/zope/registry.txt  (original)
+++ kukit/kss.zope/trunk/kss/zope/registry.txt  Sun Nov 11 16:00:20 2007
@@ -62,7 +62,6 @@
 
   >>> from kss.zope.registry import BBB_register_commandset
   >>> from kss.zope.registry import BBB_register_javascript
-  >>> from kss.zope.registry import BBB_register_extra_javascript
 
 Next to automatically discovering commandsets (using the plugin
 system) there is support for registering a specific set. The
@@ -76,19 +75,18 @@
   >>> registry.lookup_commandset('cheese')
   <class 'CheeseCommandSet'>
 
-If we register an already available one it will silently ignore the
-request. It will also keep the existing one.
-
-  >>> BBB_register_commandset('core', CheeseCommandSet)
-  >>> registry.lookup_commandset('core')
-  <class 'kss.base.corecommands.KSSCoreCommands'>
-
 We can also add Javascript files.
 
   >>> BBB_register_javascript('/some/path.js')
   >>> list(registry.javascripts())
   [..., '/some/path.js']
 
+A duplicate file does not appear again.
+
+  >>> saved = list(registry.javascripts())
+  >>> BBB_register_javascript(saved[0])
+  >>> registry.javascripts() == saved
+  True
 
 Now we can reset the BBB registry to be empty again.
 
_______________________________________________
Kukit-checkins mailing list
[email protected]
http://codespeak.net/mailman/listinfo/kukit-checkins

Reply via email to