Back to index

plone3  3.1.7
commandset.py
Go to the documentation of this file.
00001 # Copyright (c) 2005-2007
00002 # Authors: KSS Project Contributors (see docs/CREDITS.txt)
00003 #
00004 # This program is free software; you can redistribute it and/or modify
00005 # it under the terms of the GNU General Public License version 2 as published
00006 # by the Free Software Foundation.
00007 #
00008 # This program is distributed in the hope that it will be useful,
00009 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 # GNU General Public License for more details.
00012 #
00013 # You should have received a copy of the GNU General Public License
00014 # along with this program; if not, write to the Free Software
00015 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
00016 # 02111-1307, USA.
00017 
00018 from zope.interface import implements
00019 import zope.component as capi
00020 
00021 from plugin import KSSPluginError
00022 from plugin import registerPlugin
00023 from interfaces import ICommandSet
00024 
00025 def getRegisteredCommandSet(name):
00026     'Get the command set'
00027     try:
00028         commandset = capi.getUtility(ICommandSet, name)
00029     except capi.ComponentLookupError:
00030         raise KSSPluginError, '"%s" is not a registered kss command set' % (name, )
00031     return commandset
00032 
00033 class CommandSet(object):
00034     '''The command set plugin
00035 
00036     registers the command adapter interface
00037     (like IKssCoreCommands), this makes possible
00038     to look them up by name instead of by interface
00039     '''
00040 
00041     implements(ICommandSet)
00042 
00043     def __init__(self, name, provides):
00044         self.name = name
00045         self.provides = provides
00046 
00047 def registerAndAllowCommandSet(class_, name, provides, *arg, **kw):
00048     registerPlugin(CommandSet, ICommandSet, name, provides, *arg, **kw)
00049     try:
00050         import Products.Five
00051     except ImportError:
00052         pass
00053     else:
00054         # Allow TTW to use commandsets
00055         from AccessControl import allow_class
00056         allow_class(class_)
00057