[KSS-checkins] r48563 - in kukit/kss.zope/trunk/kss: core/pluginregistry zope zope/bbb

reebalazs at codespeak.net reebalazs at codespeak.net
Sun Nov 11 14:29:30 CET 2007


Author: reebalazs
Date: Sun Nov 11 14:29:27 2007
New Revision: 48563

Added:
   kukit/kss.zope/trunk/kss/zope/ttw.py
Removed:
   kukit/kss.zope/trunk/kss/core/pluginregistry/commandset.py
   kukit/kss.zope/trunk/kss/core/pluginregistry/registry.py
Modified:
   kukit/kss.zope/trunk/kss/core/pluginregistry/configure.py
   kukit/kss.zope/trunk/kss/core/pluginregistry/directives.py
   kukit/kss.zope/trunk/kss/core/pluginregistry/interfaces.py
   kukit/kss.zope/trunk/kss/core/pluginregistry/meta.zcml
   kukit/kss.zope/trunk/kss/zope/bbb/configure.py
   kukit/kss.zope/trunk/kss/zope/bbb/deprecated.py
   kukit/kss.zope/trunk/kss/zope/bbb/directives.py
   kukit/kss.zope/trunk/kss/zope/bbb/meta.zcml
   kukit/kss.zope/trunk/kss/zope/registry.py
   kukit/kss.zope/trunk/kss/zope/registry.txt
Log:
Add BBB for commandsets, and fix BBB for javascripts

Deleted: /kukit/kss.zope/trunk/kss/core/pluginregistry/commandset.py
==============================================================================
--- /kukit/kss.zope/trunk/kss/core/pluginregistry/commandset.py	Sun Nov 11 14:29:27 2007
+++ (empty file)
@@ -1,57 +0,0 @@
-# Copyright (c) 2005-2007
-# Authors: KSS Project Contributors (see docs/CREDITS.txt)
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License version 2 as published
-# by the Free Software Foundation.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-# 02111-1307, USA.
-
-from zope.interface import implements
-import zope.component as capi
-
-from plugin import KSSPluginError
-from plugin import registerPlugin
-from interfaces import ICommandSet
-
-def getRegisteredCommandSet(name):
-    'Get the command set'
-    try:
-        commandset = capi.getUtility(ICommandSet, name)
-    except capi.ComponentLookupError:
-        raise KSSPluginError, '"%s" is not a registered kss command set' % (name, )
-    return commandset
-
-class CommandSet(object):
-    '''The command set plugin
-
-    registers the command adapter interface
-    (like IKssCoreCommands), this makes possible
-    to look them up by name instead of by interface
-    '''
-
-    implements(ICommandSet)
-
-    def __init__(self, name, provides):
-        self.name = name
-        self.provides = provides
-
-def registerAndAllowCommandSet(class_, name, provides, *arg, **kw):
-    registerPlugin(CommandSet, ICommandSet, name, provides, *arg, **kw)
-    try:
-        import Products.Five
-    except ImportError:
-        pass
-    else:
-        # Allow TTW to use commandsets
-        from AccessControl import allow_class
-        allow_class(class_)
-    

Modified: kukit/kss.zope/trunk/kss/core/pluginregistry/configure.py
==============================================================================
--- kukit/kss.zope/trunk/kss/core/pluginregistry/configure.py	(original)
+++ kukit/kss.zope/trunk/kss/core/pluginregistry/configure.py	Sun Nov 11 14:29:27 2007
@@ -18,7 +18,6 @@
 from zope.component.zcml import adapter
 from interfaces import ISelectorType
 from selector_type import SelectorType
-from commandset import registerAndAllowCommandSet
 from plugin import registerPlugin
 
 def registerSelectorType(_context, name, jsfile=None):
@@ -33,13 +32,3 @@
         callable = registerPlugin,
         args = (SelectorType, ISelectorType, name, jsfile),
         )
-
-def registerCommandSet(_context, for_, class_, name, provides):
-    'Directive that registers a command set' 
-    
-    adapter(_context, [class_], provides, [for_])
-    _context.action(
-        discriminator = ('registerKssCommandSet', name),
-        callable = registerAndAllowCommandSet,
-        args = (class_, name, provides),
-        )

Modified: kukit/kss.zope/trunk/kss/core/pluginregistry/directives.py
==============================================================================
--- kukit/kss.zope/trunk/kss/core/pluginregistry/directives.py	(original)
+++ kukit/kss.zope/trunk/kss/core/pluginregistry/directives.py	Sun Nov 11 14:29:27 2007
@@ -1,10 +1,6 @@
 from zope.interface import Interface
 from zope.schema import TextLine
-from zope.configuration.fields import (
-    Path, 
-    GlobalInterface, 
-    GlobalObject,
-    )
+from zope.configuration.fields import Path
 
 class IRegisterSelectorTypeDirective(Interface):
     'Register a KSS selector type'
@@ -20,30 +16,3 @@
          description=u"The path of the javascript file that defines the plugin",
          required=False,
          )
-
-class IRegisterCommandSetDirective(Interface):
-    'Register a KSS command set'
-    
-    for_ = GlobalInterface(
-         title=u"For",
-         description=u"The interface of view that can be adapted to this commandset",
-         required=True,
-         )
-    
-    class_ = GlobalObject(
-         title=u"Class",
-         description=u"The class that implements the commandset",
-         required=True,
-         )
-
-    name = TextLine(
-         title=u"Name",
-         description=u"The name of the command set component.",
-         required=True,
-         )
-
-    provides = GlobalInterface(
-         title=u"Provides",
-         description=u"The interface that does the adaptation on the view for this set",
-         required=True,
-         )

Modified: kukit/kss.zope/trunk/kss/core/pluginregistry/interfaces.py
==============================================================================
--- kukit/kss.zope/trunk/kss/core/pluginregistry/interfaces.py	(original)
+++ kukit/kss.zope/trunk/kss/core/pluginregistry/interfaces.py	Sun Nov 11 14:29:27 2007
@@ -25,6 +25,3 @@
 
 class ISelectorType(IKSSPlugin):
     '''Selector type plugin'''
-
-class ICommandSet(Interface):
-    '''Command set plugin'''

Modified: kukit/kss.zope/trunk/kss/core/pluginregistry/meta.zcml
==============================================================================
--- kukit/kss.zope/trunk/kss/core/pluginregistry/meta.zcml	(original)
+++ kukit/kss.zope/trunk/kss/core/pluginregistry/meta.zcml	Sun Nov 11 14:29:27 2007
@@ -9,12 +9,6 @@
        handler=".configure.registerSelectorType"
        />
 
-    <directive
-       name="commandset"
-       schema=".directives.IRegisterCommandSetDirective"
-       handler=".configure.registerCommandSet"
-       />
-
    </directives>
 
 </configure>

Deleted: /kukit/kss.zope/trunk/kss/core/pluginregistry/registry.py
==============================================================================
--- /kukit/kss.zope/trunk/kss/core/pluginregistry/registry.py	Sun Nov 11 14:29:27 2007
+++ (empty file)
@@ -1,32 +0,0 @@
-# Copyright (c) 2005-2007
-# Authors: KSS Project Contributors (see docs/CREDITS.txt)
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License version 2 as published
-# by the Free Software Foundation.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-# 02111-1307, USA.
-
-import zope.component as capi
-from zope.interface import implements
-from concatresource.interfaces import IConcatResourceAddon
-from kss.zope.interfaces import IKSSPluginRegistry
-
-class KSSConcatResourceAddon(object):
-    implements(IConcatResourceAddon)
-    
-    def getAddonFiles(self):
-        registry = capi.getUtility(IKSSPluginRegistry)
-        files = []
-        files.extend(registry.javascripts())
-        return files
-
-kssConcatResourceAddon = KSSConcatResourceAddon()

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 14:29:27 2007
@@ -1,10 +1,43 @@
 
 from deprecated import deprecated_directive
+from kss.zope.ttw import allowCommandset
+from kss.zope.registry import BBB_register_javascript, BBB_register_commandset
 
-def nothing(*arg, **ks):
-    pass
+when = 'after 2008-08-01'
+
+def doRegisterJavascript(jsfile):
+    if jsfile:
+        BBB_register_javascript(jsfile)
+
+def registerFor(directive):
+    def registerJavascript(_context, name, jsfile=None, **kwargs):
+        'Directive that registers a javascript' 
+        _context.action(
+            discriminator = ('registerKssJavascript', directive, name),
+            callable = doRegisterJavascript,
+            args = (jsfile, ),
+            )
+    return registerJavascript
 
 # XXX TODO more meaningful messages here?
-registerEventType = deprecated_directive(nothing, 'kss:eventtype', 'use python level registry instead')
-registerAction = deprecated_directive(nothing, 'kss:action', 'use python level registry instead')
-registerParamProvider = deprecated_directive(nothing, 'kss:paramprovider', 'use python level registry instead')
+registerEventType = deprecated_directive('kss:eventtype', 'use python level registry instead', when)(registerFor('eventtype'))
+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'))
+
+def doRegisterCommandSet(class_, name, provides, *arg, **kw):
+    # provides is ignored
+    provides                    # to satisfy pyflakes
+    # register the commandset on python level
+    BBB_register_commandset(name, class_)
+    # Allow the commandset for ttw
+    allowCommandset(class_)
+
+# XXX TODO more meaningful message here?
+ at deprecated_directive('kss:commandset', 'use python level registry instead', when)
+def registerCommandSet(_context, for_, class_, name, provides):
+    'Directive that registers a command set' 
+    _context.action(
+        discriminator = ('registerKssCommandSet', name),
+        callable = doRegisterCommandSet,
+        args = (class_, name, provides),
+        )

Modified: kukit/kss.zope/trunk/kss/zope/bbb/deprecated.py
==============================================================================
--- kukit/kss.zope/trunk/kss/zope/bbb/deprecated.py	(original)
+++ kukit/kss.zope/trunk/kss/zope/bbb/deprecated.py	Sun Nov 11 14:29:27 2007
@@ -27,17 +27,19 @@
         return method(self, *args, **kw)
     return deprecated_method
 
-def deprecated_directive(method, directive, message):
-    def deprecated_method(_context, *args, **kw):
-        warnings.warn(message, DeprecationWarning, 2)
-        warnings.warn(textwrap.dedent('''\
+def deprecated_directive(directive, message, when='any time'):
+    def f(method):
+        def deprecated_method(_context, *args, **kw):
+            warnings.warn(message, DeprecationWarning, 2)
+            warnings.warn(textwrap.dedent('''\
 
 
-              %s
-            The directive %s is deprecated and will be removed any time,
-            %s
-            '''
-            % (_context.info, directive, message)),
-        DeprecationWarning, 2)
-        return method(_context, *args, **kw)
-    return deprecated_method
+                  %s
+                The directive %s is deprecated and will be removed %s,
+                %s
+                '''
+                % (_context.info, directive, when, message)),
+            DeprecationWarning, 2)
+            return method(_context, *args, **kw)
+        return deprecated_method
+    return f

Modified: kukit/kss.zope/trunk/kss/zope/bbb/directives.py
==============================================================================
--- kukit/kss.zope/trunk/kss/zope/bbb/directives.py	(original)
+++ kukit/kss.zope/trunk/kss/zope/bbb/directives.py	Sun Nov 11 14:29:27 2007
@@ -1,6 +1,12 @@
 from zope.interface import Interface
 from zope.schema import TextLine, Choice
-from zope.configuration.fields import Path, Tokens, PythonIdentifier
+from zope.configuration.fields import (
+    Path, 
+    Tokens, 
+    PythonIdentifier,
+    GlobalInterface, 
+    GlobalObject,
+    )
 
 class IRegisterEventTypeDirective(Interface):
     'Register a KSS event type'
@@ -73,3 +79,30 @@
          description=u"The path of the javascript file that defines the plugin",
          required=False,
          )
+
+class IRegisterCommandSetDirective(Interface):
+    'Register a KSS command set'
+    
+    for_ = GlobalInterface(
+         title=u"For",
+         description=u"The interface of view that can be adapted to this commandset",
+         required=True,
+         )
+    
+    class_ = GlobalObject(
+         title=u"Class",
+         description=u"The class that implements the commandset",
+         required=True,
+         )
+
+    name = TextLine(
+         title=u"Name",
+         description=u"The name of the command set component.",
+         required=True,
+         )
+
+    provides = GlobalInterface(
+         title=u"Provides",
+         description=u"The interface that does the adaptation on the view for this set",
+         required=True,
+         )

Modified: kukit/kss.zope/trunk/kss/zope/bbb/meta.zcml
==============================================================================
--- kukit/kss.zope/trunk/kss/zope/bbb/meta.zcml	(original)
+++ kukit/kss.zope/trunk/kss/zope/bbb/meta.zcml	Sun Nov 11 14:29:27 2007
@@ -21,6 +21,12 @@
        handler=".configure.registerParamProvider"
        />
 
+    <directive
+       name="commandset"
+       schema=".directives.IRegisterCommandSetDirective"
+       handler=".configure.registerCommandSet"
+       />
+
    </directives>
 
 </configure>

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 14:29:27 2007
@@ -4,9 +4,8 @@
 from kss.zope.interfaces import IKSSPluginRegistry
 
 # BBB registries for configuration of plugins through ZCML
-bbb_commandsets = {}
-bbb_javascripts = []
-bbb_extra_javascripts = []
+BBB_commandsets = {}
+BBB_javascripts = []
 
 class GlobalPluginRegistry(object):
     interface.implements(IKSSPluginRegistry)
@@ -30,39 +29,33 @@
         return available_plugins()
 
     def javascripts(self):
-        return self._javascripts + bbb_javascripts
+        return self._javascripts + BBB_javascripts
 
     def extra_javascripts(self):
-        return self._extra_javascripts + bbb_extra_javascripts
+        return self._extra_javascripts
 
     def lookup_commandset(self, id):
-        commandsets = bbb_commandsets.copy()
+        commandsets = BBB_commandsets.copy()
         commandsets.update(self._commandsets)
         return commandsets[id]
 
 #=============================================
 # Stuff needed for compatibility features
 #=============================================
-def bbb_register_commandset(id, factory):
+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
+    if not id in BBB_commandsets:
+        BBB_commandsets[id] = factory
 
-def bbb_register_javascript(filename):
-    if filename not in bbb_javascripts:
-        bbb_javascripts.append(filename)
-
-def bbb_register_extra_javascript(filename):
-    if filename not in bbb_extra_javascripts:
-        bbb_extra_javascripts.append(filename)
-
-def bbb_clear_out():
-    global bbb_commandsets
-    bbb_commandsets = {}
-    global bbb_javascripts
-    bbb_javascripts = []
-    global bbb_extra_javascripts
-    bbb_extra_javascripts = []
-    
-        
+def BBB_register_javascript(filename):
+    if filename not in BBB_javascripts:
+        BBB_javascripts.append(filename)
+
+def BBB_clear_out():
+    global BBB_commandsets
+    BBB_commandsets = {}
+    global BBB_javascripts
+    BBB_javascripts = []
+    global BBB_extra_javascripts
+    BBB_extra_javascripts = []

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 14:29:27 2007
@@ -60,9 +60,9 @@
 The code below is only used for backwards compatibility. It will be
 removed in a future release.
 
-  >>> 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
+  >>> 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
@@ -72,39 +72,32 @@
   >>> from kss.base.commands import KSSCommandSet
   >>> class CheeseCommandSet(KSSCommandSet):
   ...     pass
-  >>> bbb_register_commandset('cheese', CheeseCommandSet)
+  >>> BBB_register_commandset('cheese', CheeseCommandSet)
   >>> 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)
+  >>> 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')
+  >>> BBB_register_javascript('/some/path.js')
   >>> list(registry.javascripts())
   [..., '/some/path.js']
 
 
-  >>> bbb_register_extra_javascript('/some_other/path.js')
-  >>> list(registry.extra_javascripts())
-  [..., '/some_other/path.js']
+Now we can reset the BBB registry to be empty again.
 
-Now we can reset the bbb registry to be empty again.
-
-  >>> from kss.zope.registry import bbb_clear_out
-  >>> bbb_clear_out()
+  >>> from kss.zope.registry import BBB_clear_out
+  >>> BBB_clear_out()
   
   >>> 'some/path.js' in list(registry.javascripts())
   False
 
-  >>> 'some_other/path.js' in list(registry.extra_javascripts())
-  False
-
   >>> registry.lookup_commandset('cheese')
   Traceback (most recent call last):
   ...

Added: kukit/kss.zope/trunk/kss/zope/ttw.py
==============================================================================
--- (empty file)
+++ kukit/kss.zope/trunk/kss/zope/ttw.py	Sun Nov 11 14:29:27 2007
@@ -0,0 +1,17 @@
+
+try:
+    import Products.Five
+    Products.Five       # satisfy pyflakes
+    __have_five__ = True
+    from AccessControl import allow_class
+except ImportError:
+    __have_five__ = False
+
+if __have_five__:
+    def allowCommandset(klass):
+        "Allow restricted execution for the commandset class"
+        # Allow TTW to use commandsets
+        allow_class(klass)
+else:
+    def allowCommandset(klass):
+        pass


More information about the Kukit-checkins mailing list