2
Filename globbing like the python glob module with minor differences:
4
* glob relative to an arbitrary directory
6
* check that link targets exist, not just links
12
_globcheck = re.compile('[[*?]')
15
return _globcheck.search(p) is not None
17
def glob(fsdir, path):
19
Yield paths matching the path glob. Sorts as a bonus. Excludes '.' and '..'
22
dir, leaf = os.path.split(path)
24
return globpattern(fsdir, leaf)
27
dirsfound = glob(fsdir, dir)
34
fspath = util.normaljoin(fsdir, dir)
35
if not os.path.isdir(fspath):
38
r.extend((util.normaljoin(dir, found) for found in globpattern(fspath, leaf)))
42
def globpattern(dir, pattern):
44
Return leaf names in the specified directory which match the pattern.
47
if not hasglob(pattern):
49
if os.path.isdir(dir):
53
if os.path.exists(util.normaljoin(dir, pattern)):
57
leaves = os.listdir(dir) + ['.', '..']
59
# "hidden" filenames are a bit special
60
if not pattern.startswith('.'):
61
leaves = [leaf for leaf in leaves
62
if not leaf.startswith('.')]
64
leaves = fnmatch.filter(leaves, pattern)
65
leaves = filter(lambda l: os.path.exists(util.normaljoin(dir, l)), leaves)