Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 57 lines (48 sloc) 1.565 kB
767facb @lirazsiri cleanup whitespace
lirazsiri authored
1 #
d740e7a @lirazsiri updated copyright year
lirazsiri authored
2 # Copyright (c) 2010-2012 Liraz Siri <liraz@turnkeylinux.org>
767facb @lirazsiri cleanup whitespace
lirazsiri authored
3 #
32b1e9e @lirazsiri TurnKey Linux => TurnKey GNU/Linux
lirazsiri authored
4 # This file is part of TKLBAM (TurnKey GNU/Linux BAckup and Migration).
767facb @lirazsiri cleanup whitespace
lirazsiri authored
5 #
e34925a @lirazsiri free software => open source software
lirazsiri authored
6 # TKLBAM is open source software; you can redistribute it and/or
0c11ee9 @lirazsiri added copyright notices to everything
lirazsiri authored
7 # modify it under the terms of the GNU General Public License as
8 # published by the Free Software Foundation; either version 3 of
9 # the License, or (at your option) any later version.
767facb @lirazsiri cleanup whitespace
lirazsiri authored
10 #
0a99d06 @lirazsiri major code reorganization and refactoring
lirazsiri authored
11 import glob
12 from os.path import *
13
14 class PathMap(dict):
15 @staticmethod
16 def _expand(path):
17 def needsglob(path):
18 for c in ('*?[]'):
19 if c in path:
20 return True
21 return False
22
23 path = abspath(path)
24 if needsglob(path):
25 return glob.glob(path)
26 else:
27 return [ path ]
28
29 def __init__(self, paths):
489d0b9 @lirazsiri bugfix: PathMap should support blacklist mode
lirazsiri authored
30 self.default = True
0a99d06 @lirazsiri major code reorganization and refactoring
lirazsiri authored
31 for path in paths:
32 if path[0] == '-':
33 path = path[1:]
34 sign = False
35 else:
489d0b9 @lirazsiri bugfix: PathMap should support blacklist mode
lirazsiri authored
36 self.default = False
0a99d06 @lirazsiri major code reorganization and refactoring
lirazsiri authored
37 sign = True
38
39 for expanded in self._expand(path):
40 self[expanded] = sign
41
42 def includes(self):
9f1091d @lirazsiri eliminated dangerous use of iterators
lirazsiri authored
43 return [ path for path in self if self[path] ]
0a99d06 @lirazsiri major code reorganization and refactoring
lirazsiri authored
44 includes = property(includes)
45
46 def excludes(self):
9f1091d @lirazsiri eliminated dangerous use of iterators
lirazsiri authored
47 return [ path for path in self if not self[path] ]
0a99d06 @lirazsiri major code reorganization and refactoring
lirazsiri authored
48 excludes = property(excludes)
49
bcf1ed6 @lirazsiri refactored PathMap interface to be more Pythonic
lirazsiri authored
50 def __contains__(self, path):
0a99d06 @lirazsiri major code reorganization and refactoring
lirazsiri authored
51 while path not in ('', '/'):
bcf1ed6 @lirazsiri refactored PathMap interface to be more Pythonic
lirazsiri authored
52 if dict.__contains__(self, path):
0a99d06 @lirazsiri major code reorganization and refactoring
lirazsiri authored
53 return self[path]
54 path = dirname(path)
55
489d0b9 @lirazsiri bugfix: PathMap should support blacklist mode
lirazsiri authored
56 return self.default
Something went wrong with that request. Please try again.