filter files to those that match nosebook-match
433356
def wantFile(self, filename):
        

        log.info("considering %s", filename)

        if self.testMatch(filename) is None:
            return False

        nb = self.readnb(filename)

        for cell in self.codeCells(nb):
            return True

        log.info("no `code` cells in %s", filename)

        return False
279840
def _match_real(filename, include, exclude, follow, symlinks):
    """"""

    sep = '\\' if util.platform() == "windows" else '/'
    if isinstance(filename, bytes):
        sep = os.fsencode(sep)
    if not filename.endswith(sep) and os.path.isdir(filename):
        filename += sep

    matched = False
    for pattern in include:
        if _fs_match(pattern, filename, sep, follow, symlinks):
            matched = True
            break

    if matched:
        matched = True
        if exclude:
            for pattern in exclude:
                if _fs_match(pattern, filename, sep, follow, symlinks):
                    matched = False
                    break
    return matched
165559
def match(self, filepath):
        
        for pattern in self.__pattern:
            if len(fnmatch.filter([filepath], pattern)) > 0:
                return True
        return False
148732
def filter( names, pat ):
    """"""
    import os, posixpath

    result = [ ]
    pat = os.path.normcase( pat )
    if not pat in _cache:
        res = translate( pat )
        if len( _cache ) >= _MAXCACHE:
            _cache.clear( )
        _cache[ pat ] = re.compile( res )
    match = _cache[ pat ].match
    if os.path is posixpath:
        # normcase on posix is NOP. Optimize it away from the loop.
        for name in names:
            if match( name ):
                result.append( name )
    else:
        for name in names:
            if match( os.path.normcase( name ) ):
                result.append( name )
    return result
513003
def filter_filenames(filenames):
    
    filenames_cleaned = []
    for filename in filenames:
        keep = True
        for pattern in FILE_EXCLUDE_EXTENTIONS:
            if filename.endswith(pattern):
                keep = False
        for pattern in FILE_SKIP_PATTENRS:   # This will reject exercises...
            if pattern in filename:
                keep = False
        if keep:
            filenames_cleaned.append(filename)
    return filenames_cleaned
327170
def match(self, filename, isdir=False):
    

    for lst in self:
      result = lst.match(filename, isdir)
      if result != MATCH_DEFAULT:
        return result
    return MATCH_DEFAULT
910301
def _find_to_filter(in_file, exclude_file, params, to_exclude):
    
    for feat in pybedtools.BedTool(in_file).intersect(pybedtools.BedTool(exclude_file), wao=True, nonamecheck=True):
        us_chrom, us_start, us_end, name, other_chrom, other_start, other_end, overlap = feat.fields
        if float(overlap) > 0:
            other_size = float(other_end) - float(other_start)
            other_pct = float(overlap) / other_size
            us_pct = float(overlap) / (float(us_end) - float(us_start))
            if us_pct > params["sv_pct"] or (other_pct > params["rpt_pct"]):
                to_exclude[name].append(float(overlap))
    return to_exclude
970411
function filterIgnored(files, ignore, fn) {
  fn(null, files.filter(function(file) {
    // TODO make more robust
    return !~ignore.indexOf(file) && !~ignore.indexOf(file + '/');
  }));
}
504334
def find_macthing_files(match):
    """"""
    last_slash = match.rfind('/')
    if last_slash == -1:
        dirname = '.'
        match_prefix = match
        result_prefix = ''
    else:
        dirname = match[0:last_slash]
        match_prefix = match[last_slash + 1:]
        result_prefix = dirname + '/'
    return [result_prefix + filename for filename in os.listdir(dirname) if filename.startswith(match_prefix)]
895590
def filter_matching(self, urls):
        
        for url in urls:
            if urlparse(url).hostname in self:
                yield url
502420
def file_matches(filename, patterns):
    """"""
    return any(fnmatch.fnmatch(filename, pat)
               or fnmatch.fnmatch(os.path.basename(filename), pat)
               for pat in patterns)
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
4404
def match(self, item):
        
        val = getattr(item, self._name)
        if val is not None:
            for fileinfo in val:
                if fnmatch.fnmatchcase(fileinfo.path.lower(), self._value):
                    return True
            return False
885309
def _file_filter(cls, filename, include_patterns, exclude_patterns):
    """"""
    logger.debug('filename: {}'.format(filename))
    for exclude_pattern in exclude_patterns:
      if exclude_pattern.match(filename):
        return False
    if include_patterns:
      found = False
      for include_pattern in include_patterns:
        if include_pattern.match(filename):
          found = True
          break
      if not found:
        return False
    return True
1186545
def match_filters(self, path):
        
        # indicate if all required filters were matched
        all_required_match = True

        # iterate over filters to match files
        for filt, ftype in self.__filters:

            # handle "Required" filters:
            if all_required_match and ftype == self.FilterType.Required and not filt.match(path):
                all_required_match = False

            # handle "Include" filters:
            elif ftype == self.FilterType.Include and filt.match(path):
                return True

            # handle "Exclude" filters:
            elif ftype == self.FilterType.Exclude and filt.match(path):
                return False

        # if got here it means we processed all filters, and no include/exclude filter was matched.
        # return if all required were matched
        return all_required_match
160722
def match(self, rule):
        
        if len(self.filters) == 0:
            return True

        for filter in self.filters:
            if filter.match(rule):
                return True
        return False
1217483
def match_patterns(pathname, patterns):
    """"""
    for pattern in patterns:
        if fnmatch(pathname, pattern):
            return True
    return False