#NEWLINE# def controller_scan( directory = None ) : #NEWLINE# #INDENT# 'Scan a directory for python files and use them as controllers' #NEWLINE# if ( directory is None ) : #NEWLINE# #INDENT# return [ ] #NEWLINE# #UNINDENT# def find_controllers( dirname , prefix = '' ) : #NEWLINE# #INDENT# 'Locate controllers in a directory' #NEWLINE# controllers = [ ] #NEWLINE# for fname in os . listdir ( dirname ) : #NEWLINE# #INDENT# filename = os . path . join ( dirname , fname ) #NEWLINE# if ( os . path . isfile ( filename ) and re . match ( '^[^_]{1,1}.*\\.py$' , fname ) ) : #NEWLINE# #INDENT# controllers . append ( ( prefix + fname [ : ( - 3 ) ] ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if os . path . isdir ( filename ) : #NEWLINE# #INDENT# controllers . extend ( find_controllers ( filename , prefix = ( ( prefix + fname ) + '/' ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return controllers #NEWLINE# #UNINDENT# controllers = find_controllers ( directory ) #NEWLINE# controllers . sort ( key = len , reverse = True ) #NEWLINE# return controllers