Back to index

plone3  3.1.7
action.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 plugin import KSSPlugin, KSSPluginError
00019 from interfaces import IAction
00020 from zope.interface import implements
00021 import zope.component as capi
00022 
00023 def checkRegisteredCommand(name):
00024     'Check if it is a registered command.'
00025     try:
00026         command = capi.getUtility(IAction, name)
00027     except capi.ComponentLookupError:
00028         raise KSSPluginError, '"%s" is not a registered kss command' % (name, )
00029     # check if the action has a valid command factory
00030     if command.command_factory == 'none':
00031         raise KSSPluginError, '"%s" kss command has missing command_factory' % (name, )
00032     # issue deprecation warning, if necessary
00033     command.check_deprecation()
00034 
00035 class Action(KSSPlugin):
00036     '''The action plugin
00037 
00038     '''
00039 
00040     implements(IAction)
00041 
00042     def __init__(self, name, jsfile, command_factory, 
00043             params_mandatory, params_optional, deprecated):
00044         KSSPlugin.__init__(self, name, jsfile)
00045         self.command_factory = command_factory
00046         self.params_mandatory = params_mandatory
00047         self.params_optional = params_optional
00048         self.deprecated = deprecated
00049 
00050     def check_deprecation(self):
00051         if self.deprecated:
00052             import warnings, textwrap
00053             warnings.warn(textwrap.dedent('''\
00054             The usage of the kss command "%s" is deprecated,
00055             %s''' % (self.name, self.deprecated)), DeprecationWarning, 2)