215
215
return patterns[match.lastindex -1]
218
class ExcludingGlobster(object):
219
"""A Globster that supports exclusion patterns.
218
class ExceptionGlobster(object):
219
"""A Globster that supports exception patterns.
221
These are ignore patterns prefixed with '!'. Exclusion
222
patterns take precedence over regular patterns and negate the
223
normal matching logic, causing a matching filename to return
224
None from the match() function.
221
Exceptions are ignore patterns prefixed with '!'. Exception
222
patterns take precedence over regular patterns and cause a
223
matching filename to return None from the match() function.
224
Patterns using a '!!' prefix are highest precedence, and act
225
as regular ignores. '!!' patterns are useful to establish ignores
226
that apply under paths specified by '!' exception patterns.
227
229
def __init__(self,patterns):
230
ignores = [[], [], []]
230
231
for p in patterns:
231
232
if p.startswith(u'!!'):
232
excludes[1].append(p[2:])
233
ignores[2].append(p[2:])
233
234
elif p.startswith(u'!'):
234
excludes[0].append(p[1:])
235
ignores[1].append(p[1:])
237
self._ignores = Globster(ignores)
238
self._excludes = [Globster(i) for i in excludes]
238
self._ignores = [Globster(i) for i in ignores]
240
240
def match(self, filename):
241
241
"""Searches for a pattern that matches the given filename.
243
243
:return A matching pattern or None if there is no matching pattern.
245
double_neg = self._excludes[1].match(filename)
245
double_neg = self._ignores[2].match(filename)
247
247
return "!!%s" % double_neg
249
if self._excludes[0].match(filename):
248
elif self._ignores[1].match(filename):
252
return self._ignores.match(filename)
251
return self._ignores[0].match(filename)
254
253
class _OrderedGlobster(Globster):
255
254
"""A Globster that keeps pattern order."""