Find the base of a glob.
354629
def find_base(path):
	""""""
	result = _pattern.match(path)

	if result:
		base = result.group(0)
	else:
		base = "./"

	if base.endswith('/') or base.endswith('\\'):
		return os.path.abspath(base)
	else:
		return os.path.dirname(os.path.abspath(base))
793694
def iglob(pathname):
    
    if not has_magic(pathname):
        yield pathname
        return
    dirname, basename = os.path.split(pathname)
    if not dirname:
        for name in glob1(dirname, basename):
            yield name
        return
    if has_magic(dirname):
        dirs = iglob(dirname)
    else:
        dirs = [dirname]
    if has_magic(basename):
        glob_in_dir = glob1
    else:
        glob_in_dir = glob0
    for dirname in dirs:
        for name in glob_in_dir(dirname, basename):
            yield os.path.join(dirname, name)
347707
def contains_glob(path_to_directory, pattern, wanted=None):
    """"""
    if not path_to_directory:
        return False
    needed = make_needed(pattern, path_to_directory, wanted)
    for name in _names_in_directory(path_to_directory):
        if needed(name):
            return True
    return False
713878
def get_base_dir():
    
    return os.path.split(os.path.abspath(os.path.dirname(__file__)))[0]
138597
def _expand_glob_path(file_roots):
    '''
    
    '''
    unglobbed_path = []
    for path in file_roots:
        try:
            if glob.has_magic(path):
                unglobbed_path.extend(glob.glob(path))
            else:
                unglobbed_path.append(path)
        except Exception:
            unglobbed_path.append(path)
    return unglobbed_path
220668
function globFile (file) {
    return stat(file).then(({ err, stats }) => {
      if (err) throw err
      if (stats.isDirectory()) {
        // TODO what if file is already slash-terminated?
        switch (file) {
          case './':
            return globPromise('./*.js')
          case 'bin':
            return globPromise('bin/*')
          default:
            return globPromise(`${file}/**/*.js`)
        }
      } else {
        return Promise.resolve(file)
      }
    })
  }
1017950
def glob_in_parents(dir, patterns, upper_limit=None):
    """"""

    assert(isinstance(dir, str))
    assert(isinstance(patterns, list))

    result = []

    absolute_dir = os.path.join(os.getcwd(), dir)
    absolute_dir = os.path.normpath(absolute_dir)
    while absolute_dir:
        new_dir = os.path.split(absolute_dir)[0]
        if new_dir == absolute_dir:
            break
        result = glob([new_dir], patterns)
        if result:
            break
        absolute_dir = new_dir

    return result
977218
def glob(self, pat):
        
        r = ""
        negate = int(pat.startswith('!'))
        i = negate

        while i < len(pat):
            if pat[i:i + 3] == '**/':
                r += "(?:.*/)?"
                i += 3
            elif pat[i] == "*":
                r += "[^/]*"
                i += 1
            elif pat[i] == ".":
                r += "[.]"
                i += 1
            elif pat[i] == "?":
                r += "."
                i += 1
            else:
                r += pat[i]
                i += 1
        r += r'\Z(?ms)'
        # print '\n\npat', pat
        # print 'regex:', r
        # print [s.relpath(self).replace('\\', '/') for s in self]
        rx = re.compile(r)

        def match(d):
            m = rx.match(d)
            return not m if negate else m

        return [s for s in self if match(s.relpath(self).replace('\\', '/'))]
518290
def find_files(globs):
	""""""

	last_cwd = os.getcwd()
	os.chdir(config.cwd)

	gex, gin = separate_globs(globs)

	# Find excluded files
	exclude = []
	for glob in gex:
		parse_glob(glob, exclude)

	files = []
	include = []
	order = 0

	# Find included files and removed excluded files
	for glob in gin:
		order += 1
		array = parse_glob(glob, include)
		base = find_base(glob)

		for file in array:
			if file not in exclude:
				files.append((order, base, file))

	os.chdir(last_cwd)
	return files
1188074
def _glob(self, curdir, this, rest):
        

        is_magic = this.is_magic
        dir_only = this.dir_only
        target = this.pattern
        is_globstar = this.is_globstar

        if is_magic and is_globstar:
            # Glob star directory `**`.

            # Throw away multiple consecutive `globstars`
            # and acquire the pattern after the `globstars` if available.
            this = rest.pop(0) if rest else None
            globstar_end = this is None
            while this and not globstar_end:
                if this:
                    dir_only = this.dir_only
                    target = this.pattern
                if this and this.is_globstar:
                    this = rest.pop(0) if rest else None
                    if this is None:
                        globstar_end = True
                else:
                    break

            if globstar_end:
                target = None

            # We match `**/next` during a deep glob, so what ever comes back,
            # we will send back through `_glob` with pattern after `next` (`**/next/after`).
            # So grab `after` if available.
            this = rest.pop(0) if rest else None

            # Deep searching is the unique case where we
            # might feed in a `None` for the next pattern to match.
            # Deep glob will account for this.
            matcher = self._get_matcher(target)

            # If our pattern ends with `curdir/**`, but does not start with `**` it matches zero or more,
            # so it should return `curdir/`, signifying `curdir` + no match.
            # If a pattern follows `**/something`, we always get the appropriate
            # return already, so this isn't needed in that case.
            # There is one quirk though with Bash, if `curdir` had magic before `**`, Bash
            # omits the trailing `/`. We don't worry about that.
            if globstar_end and curdir:
                yield os.path.join(curdir, self.empty)

            # Search
            for path in self._glob_dir(curdir, matcher, dir_only, deep=True):
                if this:
                    yield from self._glob(path, this, rest[:])
                else:
                    yield path

        elif not dir_only:
            # Files: no need to recursively search at this point as we are done.
            matcher = self._get_matcher(target)
            yield from self._glob_dir(curdir, matcher)

        else:
            # Directory: search current directory against pattern
            # and feed the results back through with the next pattern.
            this = rest.pop(0) if rest else None
            matcher = self._get_matcher(target)
            for path in self._glob_dir(curdir, matcher, True):
                if this:
                    yield from self._glob(path, this, rest[:])
                else:
                    yield path
843701
def find(self, path):
    """"""
    keys = ['^'] + path.split(os.path.sep)
    for i in range(len(keys)):
      # See if we have a match at position i.  We have such a match if following the path
      # segments into the trie, from the root, leads us to a terminal.
      node = self._root
      langs = set()
      j = i
      while j < len(keys):
        child = node.get_child(keys[j], langs)
        if child is None:
          break
        else:
          node = child
          j += 1
      if node.is_terminal:
        if j == 1:  # The match was on the root itself.
          path = ''
        else:
          path = os.path.join(*keys[1:j])
        return self._source_root_factory.create(path, langs, node.category)
      # Otherwise, try the next value of i.
    return None
460540
def get(obj, glob, separator="/"):
    
    ret = None
    found = False
    for item in search(obj, glob, yielded=True, separator=separator):
        if ret is not None:
            raise ValueError("dpath.util.get() globs must match only one leaf : %s" % glob)
        ret = item[1]
        found = True
    if found is False:
        raise KeyError(glob)
    return ret
103595
def glob(self):
        """"""

        # Cached symlinks
        self.symlinks = {}

        if self.is_bytes:
            curdir = os.fsencode(os.curdir)
        else:
            curdir = os.curdir

        for pattern in self.pattern:
            # If the pattern ends with `/` we return the files ending with `/`.
            dir_only = pattern[-1].dir_only if pattern else False

            if pattern:
                if not pattern[0].is_magic:
                    # Path starts with normal plain text
                    # Lets verify the case of the starting directory (if possible)
                    this = pattern[0]

                    curdir = this[0]

                    if not os.path.lexists(curdir):
                        return

                    # Make sure case matches, but running case insensitive
                    # on a case sensitive file system may return more than
                    # one starting location.
                    results = [curdir] if this.is_drive else self._get_starting_paths(curdir)
                    if not results:
                        if not dir_only:
                            # There is no directory with this name,
                            # but we have a file and no directory restriction
                            yield curdir
                        return

                    if this.dir_only:
                        # Glob these directories if they exists
                        for start in results:
                            if os.path.isdir(start):
                                rest = pattern[1:]
                                if rest:
                                    this = rest.pop(0)
                                    for match in self._glob(curdir, this, rest):
                                        if not self._is_excluded(match, dir_only):
                                            yield os.path.join(match, self.empty) if dir_only else match
                                elif not self._is_excluded(curdir, dir_only):
                                    yield os.path.join(curdir, self.empty) if dir_only else curdir
                    else:
                        # Return the file(s) and finish.
                        for start in results:
                            if os.path.lexists(start) and not self._is_excluded(start, dir_only):
                                yield os.path.join(start, self.empty) if dir_only else start
                else:
                    # Path starts with a magic pattern, let's get globbing
                    rest = pattern[:]
                    this = rest.pop(0)
                    for match in self._glob(curdir if not curdir == self.current else self.empty, this, rest):
                        if not self._is_excluded(match, dir_only):
                            yield os.path.join(match, self.empty) if dir_only else match
679934
function (p, cb) {
				var pth = p.replace(/\\\?/g, '\/'); // Glob must use / as path seperator even on windows
				glob(pth + '/**/*.*', function (er, files) {
					if (er) {
						return cb(er);
					}
					return cb(null, files.map(function (f) {
						return path.relative(p, f);
					}));
				});
			}
436237
function doesStateMatchGlob (glob) {
    var globSegments = glob.split('.'),
        segments = $state.$current.name.split('.');

    //match greedy starts
    if (globSegments[0] === '**') {
       segments = segments.slice(indexOf(segments, globSegments[1]));
       segments.unshift('**');
    }
    //match greedy ends
    if (globSegments[globSegments.length - 1] === '**') {
       segments.splice(indexOf(segments, globSegments[globSegments.length - 2]) + 1, Number.MAX_VALUE);
       segments.push('**');
    }

    if (globSegments.length != segments.length) {
      return false;
    }

    //match single stars
    for (var i = 0, l = globSegments.length; i < l; i++) {
      if (globSegments[i] === '*') {
        segments[i] = '*';
      }
    }

    return segments.join('') === globSegments.join('');
  }
167900
def lookupfile(filename):
    """"""
    logger.info('Looking up %s'%(filename))

    # First open cache file to see if we already looked up this stuff
    dirname=os.path.dirname(filename)
    basefilename=os.path.basename(filename)

    CACHE_FILE = os.path.join(dirname,'.'+basefilename+'.gpscache')
    cache=loadCacheFile(CACHE_FILE)

    # Get the input file
    positions=parsePositionFile(filename)

    # If load didn't work, read again and lookup
    if not cache:
        logger.info("%s - No cache file found, looking up location"\
                %(basefilename))
        cache=lookupGeoInfo(positions)
        # Save to DB
        json.dump(cache,open(CACHE_FILE,'w'))
    else:
        logger.info("%s - Found cache file for locations"\
                %(basefilename))

    return positions,cache
898639
def _glob(pattern, skip_dirs=False):
    """"""
    # Implicit recursive iff no / in pattern and starts with *
    if "/" not in pattern and pattern.startswith("*"):
        files = glob.glob(f"**/{pattern}", recursive=True)
    else:
        files = glob.glob(pattern, recursive=True)

    # Expand dirs
    all_files = set()
    for file in files:
        if os.path.isdir(file) and not skip_dirs:
            all_files.update(set(f for f in _glob(f"{file}/**/*", skip_dirs=True) if not os.path.isdir(f)))
        else:
            all_files.add(file)

    # Normalize all files
    return {str(Path(f)) for f in all_files}