00001
00002 """
00003 KEYSTONE CLASS
00004 """
00005
00006 __copyright__ = """
00007 Copyright 2008 Sean Ross-Ross
00008 """
00009 __license__ = """
00010 This file is part of SLIMpy .
00011
00012 SLIMpy is free software: you can redistribute it and/or modify
00013 it under the terms of the GNU Lesser General Public License as published by
00014 the Free Software Foundation, either version 3 of the License, or
00015 (at your option) any later version.
00016
00017 SLIMpy is distributed in the hope that it will be useful,
00018 but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00020 GNU Lesser General Public License for more details.
00021
00022 You should have received a copy of the GNU Lesser General Public License
00023 along with SLIMpy . If not, see <http://www.gnu.org/licenses/>.
00024 """
00025
00026
00027 from slimpy_base.Core.Interface.ContainerBase import DataContainer
00028 from slimpy_base.api.Plugins.pluginLoader import loader as PluginLoader
00029
00030 from slimpy_base.Environment.Singleton import Singleton
00031
00032
00033 class KeyStone( Singleton ):
00034 """
00035 Singleton Class to be used to connect all the moduals of SLIMpy together
00036 """
00037
00038 def __new_instance__( self, name ):
00039 """
00040 Initialize Class note that this constructor returns a shared state instance
00041 """
00042 Singleton.__new_instance__(self, name)
00043
00044 self.setplugins( )
00045
00046 def setplugins( self, *par, **kw ):
00047 """
00048 sets the woking plugins to kargs
00049 """
00050
00051 pl = PluginLoader()
00052
00053 plugins = pl.load()
00054
00055
00056 plugins['adc'] = DataContainer
00057
00058
00059 plugins.update( *par, **kw )
00060
00061
00062 self.PLUGINS = plugins
00063
00064
00065
00066 def getplugin( self, plugin ):
00067 """
00068 get a single plugin from a string
00069 """
00070 try:
00071 return self.PLUGINS[plugin]
00072 except KeyError:
00073 plugins = self.PLUGINS.keys()
00074 msg = ( "plugin '%(plugin)s' does not exist. Available "
00075 "plugins are: - %(plugins)s" )
00076
00077 raise KeyError( msg % vars() )
00078
00079
00080 def getplugins( self ):
00081 """
00082 returns all plugins
00083 """
00084 return self.PLUGINS
00085
00086
00087 def listPlugins( self ):
00088 """
00089 list all available plugins
00090 """
00091 print 'List Plugins:'
00092 for plugin in self.PLUGINS.keys():
00093 print ' -', plugin
00094
00095 def __repr__( self ):
00096 return "<SLIMpy: " + self.__class__.__name__ + " object>"
00097