def controller_scan(directory=None):
 if (directory is None):
  return []
 def find_controllers(dirname, prefix=''):
  'Locate controllers in a directory'
  controllers = []
  for fname in os.listdir(dirname):
   filename = os.path.join(dirname, fname)
   if (os.path.isfile(filename) and re.match('^[^_]{1,1}.*\\.py$', fname)):
    controllers.append((prefix + fname[:(-3)]))
   elif os.path.isdir(filename):
    controllers.extend(find_controllers(filename, prefix=((prefix + fname) + '/')))
  return controllers
 def longest_first(fst, lst):
  'Compare the length of one string to another, shortest goes first'
  return cmp(len(lst), len(fst))
 controllers = find_controllers(directory)
 controllers.sort(longest_first)
 return controllers

def controller_scan ( directory = None ) : if ( directory is None ) : return [ ] def find_controllers ( dirname , prefix = '' ) : controllers = [ ] for fname in os . listdir ( dirname ) : filename = os . path . join ( dirname , fname ) if ( os . path . isfile ( filename ) and re . match ( '^[^_]{1,1}.*\\.py$' , fname ) ) : controllers . append ( ( prefix + fname [ : ( - 3 ) ] ) ) elif os . path . isdir ( filename ) : controllers . extend ( find_controllers ( filename , prefix = ( ( prefix + fname ) + '/' ) ) ) return controllers def longest_first ( fst , lst ) : return cmp ( len ( lst ) , len ( fst ) ) controllers = find_controllers ( directory ) controllers . sort ( longest_first ) return controllers
scan a directory for python files and use them as controllers .