#NEWLINE# def find_modules( ) : #NEWLINE# #INDENT# '\n    Find modules and return a dict module instances.\n\n    :return: dict with modules instaces as format: dict(str: IModule)\n    :rtype: dict(str: IModule)\n\n    ' #NEWLINE# import os #NEWLINE# import os.path #NEWLINE# import inspect #NEWLINE# base_dir = os . path . abspath ( os . path . dirname ( __file__ ) ) #NEWLINE# results = dict ( ) #NEWLINE# for ( root , dirs , files ) in os . walk ( base_dir ) : #NEWLINE# #INDENT# if ( '__init__.py' not in files ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if any ( ( True for x in root . split ( '/' ) if x . startswith ( '_' ) ) ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# for filename in files : #NEWLINE# #INDENT# if ( filename . endswith ( '.py' ) and ( not filename . startswith ( 'celery' ) ) and ( not filename . startswith ( 'test_' ) ) ) : #NEWLINE# #INDENT# if filename . startswith ( '_' ) : #NEWLINE# #INDENT# if ( filename != '__init__.py' ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# #UNINDENT# loop_file = os . path . join ( root , filename ) . replace ( base_dir , '' ) . replace ( os . path . sep , '.' ) . replace ( '.py' , '' ) #NEWLINE# loop_file = ( loop_file [ 1 : ] if loop_file . startswith ( '.' ) else loop_file ) #NEWLINE# try : #NEWLINE# #INDENT# classes = __import__ ( ( '%s.%s' % ( __package__ , loop_file ) ) , globals = globals ( ) , locals = locals ( ) , level = loop_file . count ( '.' ) ) #NEWLINE# #UNINDENT# except ImportError : #NEWLINE# #INDENT# classes = __import__ ( loop_file , globals = globals ( ) , locals = locals ( ) , level = loop_file . count ( '.' ) ) #NEWLINE# #UNINDENT# for m in dir ( classes ) : #NEWLINE# #INDENT# _loaded_module = getattr ( classes , m ) #NEWLINE# if ( inspect . isclass ( _loaded_module ) and ( _loaded_module . __name__ != 'IModule' ) ) : #NEWLINE# #INDENT# for c in inspect . getmro ( _loaded_module ) : #NEWLINE# #INDENT# if ( c . __name__ == 'IModule' ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# results [ _loaded_module . name ] = m #NEWLINE# #UNINDENT# except AttributeError : #NEWLINE# #INDENT# log . warning ( ( "Module '%s' has not attribute 'name' and can't be loaded." % _loaded_module . __name__ ) ) #NEWLINE# #UNINDENT# break #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# return results