Show More
@@ -1,36 +1,51 b'' | |||||
1 | import util |
|
1 | import util | |
2 |
|
2 | |||
3 | class match(object): |
|
3 | class match(object): | |
4 | def __init__(self, root, cwd, patterns, include, exclude, default): |
|
4 | def __init__(self, root, cwd, patterns, include, exclude, default): | |
5 | self._patterns = patterns |
|
5 | self._patterns = patterns | |
6 | self._root = root |
|
6 | self._root = root | |
7 | self._cwd = cwd |
|
7 | self._cwd = cwd | |
8 | self._include = include |
|
8 | self._include = include | |
9 | self._exclude = exclude |
|
9 | self._exclude = exclude | |
10 | f, mf, ap = util.matcher(root, cwd, patterns, include, exclude, |
|
10 | f, mf, ap = util.matcher(root, cwd, patterns, include, exclude, | |
11 | self.src(), default) |
|
11 | self.src(), default) | |
12 | self._files = f |
|
12 | self._files = f | |
13 | self._fmap = dict.fromkeys(f) |
|
13 | self._fmap = dict.fromkeys(f) | |
14 | self._matchfn = mf |
|
14 | self._matchfn = mf | |
15 | self._anypats = ap |
|
15 | self._anypats = ap | |
16 | def src(self): |
|
16 | def src(self): | |
17 | return None |
|
17 | return None | |
18 | def __call__(self, fn): |
|
18 | def __call__(self, fn): | |
19 | return self._matchfn(fn) |
|
19 | return self._matchfn(fn) | |
20 | def __iter__(self): |
|
20 | def __iter__(self): | |
21 | for f in self._files: |
|
21 | for f in self._files: | |
22 | yield f |
|
22 | yield f | |
23 | def bad(self, f, msg): |
|
23 | def bad(self, f, msg): | |
24 | return True |
|
24 | return True | |
25 | def dir(self, f): |
|
25 | def dir(self, f): | |
26 | pass |
|
26 | pass | |
27 | def missing(self, f): |
|
27 | def missing(self, f): | |
28 | pass |
|
28 | pass | |
29 | def exact(self, f): |
|
29 | def exact(self, f): | |
30 | return f in self._fmap |
|
30 | return f in self._fmap | |
31 | def rel(self, f): |
|
31 | def rel(self, f): | |
32 | return util.pathto(self._root, self._cwd, f) |
|
32 | return util.pathto(self._root, self._cwd, f) | |
33 | def files(self): |
|
33 | def files(self): | |
34 | return self._files |
|
34 | return self._files | |
35 | def anypats(self): |
|
35 | def anypats(self): | |
36 | return self._anypats |
|
36 | return self._anypats | |
|
37 | ||||
|
38 | def always(root, cwd): | |||
|
39 | return match(root, cwd, [], None, None, 'relpath') | |||
|
40 | ||||
|
41 | def never(root, cwd): | |||
|
42 | m = match(root, cwd, [], None, None, 'relpath') | |||
|
43 | m._matchfn = lambda f: False | |||
|
44 | return m | |||
|
45 | ||||
|
46 | def exact(root, cwd, files): | |||
|
47 | m = always(root, cwd) | |||
|
48 | m._files = files | |||
|
49 | m._fmap = dict.fromkeys(files) | |||
|
50 | m._matchfn = m._fmap.has_key | |||
|
51 | return m |
General Comments 0
You need to be logged in to leave comments.
Login now