Find an entry by relative path. Arguments:

    path -- the entry's filename (or entry ID)
    search_path -- a list of directories to check in

    Returns: the resolved Entry object
549555
def find_entry(rel_path, search_path):
    

    from . import entry  # pylint:disable=cyclic-import

    try:
        entry_id = int(rel_path)
        record = model.Entry.get(id=entry_id)
        if record:
            return entry.Entry(record)
    except ValueError:
        pass

    if rel_path.startswith('/'):
        search_path = [config.content_folder]
        rel_path = '.' + rel_path

    for where in search_path:
        abspath = os.path.normpath(os.path.join(where, rel_path))
        record = model.Entry.get(file_path=abspath)
        if record:
            return entry.Entry(record)
    return None
572357
def convert_entry_to_path(path):
    # type: (Dict[S, Union[S, bool, Tuple[S], List[S]]]) -> S
    """"""

    if not isinstance(path, Mapping):
        raise TypeError("expecting a mapping, received {0!r}".format(path))

    if not any(key in path for key in ["file", "path"]):
        raise ValueError("missing path-like entry in supplied mapping {0!r}".format(path))

    if "file" in path:
        path = vistir.path.url_to_path(path["file"])

    elif "path" in path:
        path = path["path"]
    return path
926249
def find_file(pattern, path):
    
    for fname in glob.iglob(path):
        with open(fname) as f:
            if re.search(pattern, f.read()):
                return fname
    return
493964
def resolve_path(path):
    """"""
    if path[0] == '~':
        # ~ or ~user
        path = os.path.expanduser(path)
    if path[0] != '/':
        # Relative path
        if cur_dir[-1] == '/':
            path = cur_dir + path
        else:
            path = cur_dir + '/' + path
    comps = path.split('/')
    new_comps = []
    for comp in comps:
        # We strip out xxx/./xxx and xxx//xxx, except that we want to keep the
        # leading / for absolute paths. This also removes the trailing slash
        # that autocompletion adds to a directory.
        if comp == '.' or (comp == '' and len(new_comps) > 0):
            continue
        if comp == '..':
            if len(new_comps) > 1:
                new_comps.pop()
        else:
            new_comps.append(comp)
    if len(new_comps) == 1 and new_comps[0] == '':
        return '/'
    return '/'.join(new_comps)
1018045
def path(self, path):
        
        if os.path.isabs(path):
            return path
        return os.path.join(self.location, path)
790907
def lookup_path(bin_name):
    
    paths = ('/usr/local/sbin/', '/usr/local/bin/', '/usr/sbin/', '/usr/bin/')
    for p in paths:
        fq_path = p + bin_name
        found = os.path.isfile(fq_path) and os.access(fq_path, os.X_OK)
        if found:
            return fq_path
    return False
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)
862149
def scantree(path):
    # type: (str) -> os.DirEntry
    
    for entry in scandir(path):
        if entry.is_dir(follow_symlinks=True):
            # due to python2 compat, cannot use yield from here
            for t in scantree(entry.path):
                yield t
        else:
            yield entry
775822
def _get_relative_path(self):
    """"""
    param_string = self._get_query_string()
    if self.path is None:
      path = '/'
    else:
      path = self.path
    if param_string:
      return '?'.join([path, param_string])
    else:
      return path
948680
def get_current_searchpath(self):
        
        idx = self.currentIndex()
        if idx == CWD:
            return self.path
        elif idx == PROJECT:
            return self.project_path
        elif idx == FILE_PATH:
            return self.file_path
        else:
            return self.external_path
343881
def get_formatted_relative_path(self, path):
        
        if self.format_relative_path and \
                (path.startswith('./') or path.startswith('.\\')):
            return path[2:]
        else:
            return path
1340948
def match_path(entry, opts):
    """"""
    if entry.name in ALWAYS_OMIT:
        return False
    # TODO: currently we use fnmatch syntax and match against names.
    # We also might allow glob syntax and match against the whole relative path instead
    # path = entry.get_rel_path()
    path = entry.name
    ok = True
    match = opts.get("match")
    exclude = opts.get("exclude")
    if entry.is_file() and match:
        assert type(match) is list
        ok = False
        for pat in match:
            if fnmatch.fnmatch(path, pat):
                ok = True
                break
    if ok and exclude:
        assert type(exclude) is list
        for pat in exclude:
            if fnmatch.fnmatch(path, pat):
                ok = False
                break
    # write("match", ok, entry)
    return ok
791003
def include_path(self, path):
        
        self.seen_paths.add(path)
        return self.filter.include(path)
1225672
def find(cls, searched_dir, pattern):
        
        Log.debug('find {0} with pattern: {1}'.format(searched_dir, pattern))
        matched_files = []
        for root_dir, dir_names, file_names in os.walk(searched_dir,
                                                       followlinks=False):
            for file_name in file_names:
                if fnmatch.fnmatch(file_name, pattern):
                    file_path = os.path.join(root_dir, file_name)
                    if not os.path.islink(file_path):
                        matched_files.append(file_path)
        matched_files.sort()
        return matched_files
133537
def entries(path)
      if File.directory?(path)
        Dir.entries(path).reject { |entry| entry =~ /^\.|~$|^\#.*\#$/ }.sort
      else
        []
      end
    end
716002
def enter(self, path):
        
        self.current.append(self.add(path))
        return self.current[-1]
669561
function resolvePath(_path, relativePath = currentWorkDir) {
  if (!isString(_path) || _path.startsWith('~')) {
    return _path;
  }
  const file = nativePath.relative(relativePath, _path);
  return nativePath.join(relativePath, file);
}