best effort function to detect the manifest path.
 checks for well known locations and falls back to a recursive search with
 a maximum depth of 2 directory levels
976563
def detect_android_manifest_path
      manifest_file = 'AndroidManifest.xml'
      known_manifest_locations = %W(./#{manifest_file} ./src/main/#{manifest_file})
      known_manifest_locations.find {|loc| File.exist?(loc)} || begin
        Find.find('.') do |path|
          Find.prune if path.start_with?('./.') || path.split('/').size > 3
          if File.directory?(path)
            manifest_file_path = known_manifest_locations.map {|known_location| "#{path}/#{known_location}"}.find {|loc| File.exist?(loc)}
            return manifest_file_path if manifest_file_path and application_path?(path)
          end
        end
      end
    end
365755
def _find_file(self, path, silent=False):
        
        for filename in DEFAULT_FILENAMES:
            full_path = os.path.join(path, filename) if path else filename
            if os.path.exists(full_path):
                return full_path

        # Return default filename if silent
        if silent:
            return os.path.join(path, DEFAULT_FILENAME)

        raise ReadmeNotFoundError(path)
487494
def check_file_existence(path):
    

    pathvalidate.validate_file_path(path)

    if not os.path.lexists(path):
        raise FileNotFoundError(path)

    if os.path.isfile(path):
        logger.debug("file found: " + path)
        return FileType.FILE

    if os.path.isdir(path):
        logger.debug("directory found: " + path)
        return FileType.DIRECTORY

    if os.path.islink(path):
        logger.debug("link found: " + path)
        return FileType.LINK

    raise RuntimeError()
890021
def find_in_path(name, path):
    ""
    # adapted fom http://code.activestate.com/recipes/52224-find-a-file-given-a-search-path/
    for dir in path.split(os.pathsep):
        binpath = os.path.join(dir, name)
        if os.path.exists(binpath):
            return os.path.abspath(binpath)
    return None
600248
function findRelative( url ){

    var dirName =       path.dirname( url );
    var baseName =      path.basename( url );
    var entries;

    if ( !fs.existsSync( dirName )){
        entries =       [];
    } else {
        entries =       fs.readdirSync( dirName ).filter( matches );
    }

    return entries.map( fsUtils.getFullPath( dirName ));

    /// Return true if entry === baseName.extension
    function matches( entry ){

        var len =       baseName.length;
        return entry[len] === "." && !entry.indexOf( baseName ) && entry.slice( len + 1 ).indexOf( "." ) === -1;
    }///
}
1030082
function locateConfig(url) {
  let configpath = '';

  function check(dir) {
    // Support js, json, and package.json
    const urljs = path.join(dir, DEFAULT_MANIFEST.js);
    const urljson = path.join(dir, DEFAULT_MANIFEST.json);
    const urlpkgjson = path.join(dir, DEFAULT_MANIFEST.pkgjson);
    let urlFinal;

    if (exists((urlFinal = urljs)) || exists((urlFinal = urljson)) || exists((urlFinal = urlpkgjson))) {
      return urlFinal;
    }
    return '';
  }

  if (url) {
    configpath = path.resolve(url);

    try {
      // Try default file name if passed directory
      if (!path.extname(configpath).length || fs.statSync(configpath).isDirectory()) {
        configpath = check(configpath);
        if (!configpath) throw Error('no default found');
      }
    } catch (err) {
      throw Error(strong('buddy') + ' config not found in ' + strong(path.dirname(url)));
    }

    // No url specified
  } else {
    try {
      // Find the first instance of a DEFAULT file based on the current working directory
      configpath = hunt(
        process.cwd(),
        (resource, stat) => {
          if (stat.isFile()) {
            const basename = path.basename(resource);

            return basename == DEFAULT_MANIFEST.js ||
              basename == DEFAULT_MANIFEST.json ||
              basename == DEFAULT_MANIFEST.pkgjson;
          }
        },
        true
      );
    } catch (err) {
      if (!configpath) throw Error(strong('buddy') + ' config not found');
    }
  }

  return configpath;
}
96929
def make_path_relative(path: str) -> str:
    
    if "../" in path:
        raise ManifestBuildingError(
            f"Path: {path} appears to be outside of the virtual source tree. "
            "Please make sure all sources are within the virtual source tree root directory."
        )

    if path[:2] != "./":
        return f"./{path}"
    return path
1312312
function findExactPath(filePath, relPath) {
    let filePathList = filePath.split('/'),
        relPathList = relPath.split('/'),
        actualPath = '',
        i = 0,
        j = 0;

    while (relPathList[i] === '..') {
        i++;
    }

    for (; j < filePathList.length - 1 - i; j++) {
        actualPath += filePathList[j] + '/';
    }

    if (i === 0) {
        i++;
        if (relPathList[i] === filePathList[i]) i++;
    }

    for (; i < relPathList.length - 1; i++) {
        actualPath += relPathList[i] + '/';
    }

    actualPath += relPathList[relPathList.length - 1];

    return actualPath;
}
1014530
function findResource(name, filepath, extList) {
  var candidates = [name, path.join(name, 'index')];
  var baseName = path.basename(name);
  if (baseName && baseName !== '.' && baseName !== '..') {
    candidates.push(path.join(name, baseName));
  }
  var info = null;

  candidates.every(function(candidate) {
    info = fis.uri(candidate, filepath);

    for (var i = 0, len = extList.length; i < len && !info.file; i++) {
      info = fis.uri(candidate + extList[i], filepath);
    }

    if (info && info.file) {
      return false;
    }

    return true;
  });

  return info;
}
150706
def _check_missing_manifests(self, segids):
    """"""
    manifest_paths = [ self._manifest_path(segid) for segid in segids ]
    with Storage(self.vol.layer_cloudpath, progress=self.vol.progress) as stor:
      exists = stor.files_exist(manifest_paths)

    dne = []
    for path, there in exists.items():
      if not there:
        (segid,) = re.search(r'(\d+):0$', path).groups()
        dne.append(segid)
    return dne
1010621
def find_manifests(self):
        ''''''
        manifest_dir = mp_util.dot_mavproxy()

        ret = []
        for file in os.listdir(manifest_dir):
            try:
                file.index("manifest")
                ret.append(os.path.join(manifest_dir,file))
            except ValueError:
                pass
        return ret
755330
def get_paths(patterns, start_dirs=None, max_depth=1):
    """"""
    # Shortcut: if there is only one pattern, make sure we process just that.
    if len(patterns) == 1 and not start_dirs:
        pattern = patterns[0]
        directory = os.path.dirname(pattern)
        if directory:
            patterns = [os.path.basename(pattern)]
            start_dirs = directory
            max_depth = 1

    if not start_dirs or start_dirs == '.':
        start_dirs = os.getcwd()
    for start_dir in start_dirs.split(','):
        for root, dirs, files in os.walk(start_dir):  # pylint: disable=W0612
            if max_depth is not None:
                relpath = os.path.relpath(root, start=start_dir)
                depth = len(relpath.split(os.sep))
                if depth > max_depth:
                    continue
            names = []
            for pattern in patterns:
                names += fnmatch.filter(files, pattern)
            for name in names:
                path = os.path.join(root, name)
                yield path
803454
def findByNodePath(self, nodePath):
        
        def _auxGetByPath(parts, item):
            "Aux function that does the actual recursive search"
            #logger.debug("_auxGetByPath item={}, parts={}".format(item, parts))

            if len(parts) == 0:
                return item

            head, tail = parts[0], parts[1:]
            if head == '':
                # Two consecutive slashes. Just go one level deeper.
                return _auxGetByPath(tail, item)
            else:
                childItem = item.childByNodeName(head)
                return _auxGetByPath(tail, childItem)

        # The actual body of findByNodePath starts here

        check_is_a_string(nodePath)
        assert not nodePath.startswith('/'), "nodePath may not start with a slash"

        if not nodePath:
            raise IndexError("Item not found: {!r}".format(nodePath))

        return _auxGetByPath(nodePath.split('/'), self)
476852
def AtMaximumDepth(self, search_depth):
    
    if self._key_path_segments is not None:
      if search_depth >= self._number_of_key_path_segments:
        return True

    return False
557647
def find_in_path(path, file):
  """"""
  for p in path.split(os.pathsep):
    candidate = os.path.join(p, file)
    if os.path.exists(candidate) and os.path.isfile(candidate):
      return candidate
  return False
679991
def _search_path(self, directory_name, filename):
        """"""
        full_path = path.join(directory_name, filename)
        if path.exists(full_path):
            return full_path

        # Could not find the requested file in any of the directories
        return None
398044
function getSourceDestinationPath (srcPath) {
        let dests = _.keys(options.files);
        return _.find(dests, function (destPath) {
            let paths = options.files[destPath];
            return _.find(paths, function (p) {
                return p === srcPath || srcPath.indexOf(p) !== -1;
            });
        });
    }