def find_management_module(app_name):
 parts = app_name.split('.')
 parts.append('management')
 parts.reverse()
 part = parts.pop()
 path = None
 try:
  (f, path, descr) = imp.find_module(part, path)
 except ImportError as e:
  if (os.path.basename(os.getcwd()) != part):
   raise e
 while parts:
  part = parts.pop()
  (f, path, descr) = imp.find_module(part, ((path and [path]) or None))
 return path

def find_management_module ( app_name ) : parts = app_name . split ( '.' ) parts . append ( 'management' ) parts . reverse ( ) part = parts . pop ( ) path = None try : ( f , path , descr ) = imp . find_module ( part , path ) except ImportError as e : if ( os . path . basename ( os . getcwd ( ) ) != part ) : raise e while parts : part = parts . pop ( ) ( f , path , descr ) = imp . find_module ( part , ( ( path and [ path ] ) or None ) ) return path
determines the path to the management module for the given app_name .