00001 """
00002 load pluging from enclosed folders
00003 does not import on a NotImplementedError
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 import os
00027
00028
00029 class loader( object ):
00030 """
00031 Class to load pluging from enclosed folders,
00032 replaces same as import * as list
00033 """
00034
00035
00036 def __init__( self ):
00037 pass
00038
00039 def load( self ):
00040 """
00041 reutrns a dictionary of modules
00042 """
00043
00044 plugins = {}
00045
00046
00047 modnames = self.getModules()
00048 warn = ( "Warning: Plugin module `%(module)s` could not be loaded: "
00049 "to debug try importing the modual on its own\n\t--%(msg)s" )
00050 for module in modnames:
00051 try:
00052 mod = __import__( module, globals(), locals() )
00053
00054
00055 plugins.update( mod.get_containers() )
00056
00057
00058 except NotImplementedError:
00059 continue
00060
00061 return plugins
00062
00063 def getModules( self ):
00064 """
00065 Returns the names of all of the modules in the
00066 directory of this file
00067
00068 """
00069 dir = os.path.dirname( __file__ )
00070
00071 files = os.listdir( dir )
00072
00073 List = []
00074 for file in files:
00075 path = os.path.join( dir, file )
00076
00077 if ( os.path.isfile( path )
00078 and path.endswith( '.py' )
00079 and not path.endswith( "__init__.py" )
00080 and not path == __file__.split( '.py' )[0]+".py" ) :
00081 List.append( file.split( '.py' )[0] )
00082
00083
00084 elif os.path.isdir( path ):
00085 if os.path.isfile( os.path.join( path, '__init__.py' ) ):
00086 List.append( file )
00087
00088
00089 return List