1
# Copyright (C) 2006-2010 Canonical Ltd
1
# Copyright (C) 2006, 2008 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
215
215
return patterns[match.lastindex -1]
218
class ExceptionGlobster(object):
219
"""A Globster that supports exception patterns.
218
class ExcludingGlobster(object):
219
"""A Globster that supports exclusion patterns.
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.
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.
229
227
def __init__(self,patterns):
230
ignores = [[], [], []]
231
230
for p in patterns:
232
231
if p.startswith(u'!!'):
233
ignores[2].append(p[2:])
232
excludes[1].append(p[2:])
234
233
elif p.startswith(u'!'):
235
ignores[1].append(p[1:])
234
excludes[0].append(p[1:])
238
self._ignores = [Globster(i) for i in ignores]
237
self._ignores = Globster(ignores)
238
self._excludes = [Globster(i) for i in excludes]
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._ignores[2].match(filename)
245
double_neg = self._excludes[1].match(filename)
247
247
return "!!%s" % double_neg
248
elif self._ignores[1].match(filename):
249
if self._excludes[0].match(filename):
251
return self._ignores[0].match(filename)
252
return self._ignores.match(filename)
253
254
class _OrderedGlobster(Globster):
254
255
"""A Globster that keeps pattern order."""