def locate_dir(path, dir_name):
 paths = []
 for (root, sub_dirs, files) in os.walk(path):
  for sub_dir in sub_dirs:
   if (dir_name == sub_dir):
    result = os.path.abspath(os.path.join(root, sub_dir))
    if (sub_dir == 'WEB-INF'):
     logging.info('Found WEB-INF/ at: {0}'.format(result))
     paths.append(result)
    elif ((sub_dir == 'lib') and (result.count(os.sep) <= (path.count(os.sep) + 2)) and result.endswith('/WEB-INF/{0}'.format(sub_dir))):
     logging.info('Found lib/ at: {0}'.format(result))
     paths.append(result)
 if (len(paths) > 0):
  sorted_paths = sorted(paths, key=(lambda s: len(s)))
  return sorted_paths[0]
 else:
  return None

def locate_dir ( path , dir_name ) : paths = [ ] for ( root , sub_dirs , files ) in os . walk ( path ) : for sub_dir in sub_dirs : if ( dir_name == sub_dir ) : result = os . path . abspath ( os . path . join ( root , sub_dir ) ) if ( sub_dir == 'WEB-INF' ) : logging . info ( 'Found WEB-INF/ at: {0}' . format ( result ) ) paths . append ( result ) elif ( ( sub_dir == 'lib' ) and ( result . count ( os . sep ) <= ( path . count ( os . sep ) + 2 ) ) and result . endswith ( '/WEB-INF/{0}' . format ( sub_dir ) ) ) : logging . info ( 'Found lib/ at: {0}' . format ( result ) ) paths . append ( result ) if ( len ( paths ) > 0 ) : sorted_paths = sorted ( paths , key = ( lambda s : len ( s ) ) ) return sorted_paths [ 0 ] else : return None
locates a directory inside the given path .