def glob_(baseDir, patternList): if not patternList: yield baseDir return head = patternList[0] if head == "**": for f in glob_(baseDir, patternList[1:]): yield f for d in pyglob(baseDir + "/*/"): for f in glob_(d, patternList): yield f return for m in pyglob(baseDir + "/" + head): for f in glob_(m, patternList[1:]): yield f
def glob(*pathnames): """Return concatenation of ordered lists of paths matching patterns in *pathnames*.""" paths = [] for pathname in pathnames: matches = pyglob(pathname) matches.sort() paths.extend(matches) return paths
def glob(*pathnames): """Returns concatenation of ordered lists of paths matching patterns in *pathnames*.""" paths = [] for pathname in pathnames: matches = pyglob(pathname) matches.sort() paths.extend(matches) return paths
def glob(pattern, path = None): ''' Like find() but interpret <pattern> as a glob. A list is returned. ''' name = expanduservars(pattern) maybe = pyglob(name) if maybe: return maybe if name.startswith(os.pathsep): return list() if not path: return list() if isinstance(path, type("")): path = path.split(':') ret = list() for p in path: n = os.path.join(expanduservars(p), name) maybe = pyglob(n) if maybe: ret += maybe return ret
def globdict(package, subdir=[], filter='*'): # find absolute file path of package path = module_path(package) # add subdirs path += os.sep + os.path.join(subdir) if os.path.isdir(path): dict = {} for f in pyglob(path + os.sep + filter): dict[os.path.split(f)[1]] = f return dict else: raise ImportError
def test_globdict(self): """Dictionary of fully qualified paths keyed by filename for package directory""" base_path = agdevicecontrol.__path__[0] # fully qualified paths to images fqfiles = map(os.path.abspath, pyglob(base_path + "/gui/images/*.png")) fqfiles.sort() dict = resource.globdict("agdevicecontrol.gui", subdir="images", filter='*.png') assert len(dict) == len(fqfiles) for fqfile in fqfiles: file = os.path.split(fqfile)[1] assert file in dict assert dict[file] == fqfile