[Python-checkins] distutils2: [datafiles] support for files exclusion in resources_dests
tarek.ziade
python-checkins at python.org
Wed Feb 16 22:23:57 CET 2011
tarek.ziade pushed 2f920a952c93 to distutils2:
http://hg.python.org/distutils2/rev/2f920a952c93
changeset: 1040:2f920a952c93
user: Pierre-Yves David <pierre-yves.david at ens-lyon.org>
date: Sat Jan 29 09:51:39 2011 +0100
summary:
[datafiles] support for files exclusion in resources_dests
rules with destination set to None excludes maching files.
files:
distutils2/datafiles.py
distutils2/tests/test_datafiles.py
diff --git a/distutils2/datafiles.py b/distutils2/datafiles.py
--- a/distutils2/datafiles.py
+++ b/distutils2/datafiles.py
@@ -11,7 +11,7 @@
self.suffix = suffix
- def expand(self, basepath, category):
+ def expand(self, basepath, destination):
if self.base:
base = osp.join(basepath, self.base)
else:
@@ -22,7 +22,8 @@
for file in iglob(absglob):
path_suffix = file[len(base):].lstrip('/')
relpath = file[len(basepath):].lstrip('/')
- yield relpath, osp.join(category, path_suffix)
+ dest = osp.join(destination, path_suffix)
+ yield relpath, dest
RICH_GLOB = re.compile(r'\{([^}]*)\}')
@@ -56,6 +57,15 @@
destinations = {}
for (base, suffix, glob_dest) in rules:
sglob = SmartGlob(base, suffix)
- for file, file_dest in sglob.expand(resources_dir, glob_dest):
- destinations[file] = file_dest
+ if glob_dest is None:
+ delete = True
+ dest = ''
+ else:
+ delete = False
+ dest = glob_dest
+ for file, file_dest in sglob.expand(resources_dir, dest):
+ if delete and file in destinations:
+ del destinations[file]
+ else:
+ destinations[file] = file_dest
return destinations
diff --git a/distutils2/tests/test_datafiles.py b/distutils2/tests/test_datafiles.py
--- a/distutils2/tests/test_datafiles.py
+++ b/distutils2/tests/test_datafiles.py
@@ -72,6 +72,14 @@
'Babarlikestrawberry': None}
self.assertFindGlob(rules, spec)
+ def test_set_match_exclude(self):
+ rules = [('scripts', '*', '{appscript}'),
+ ('', '**/*.sh', None)]
+ spec = {'scripts/scripts.bin': '{appscript}/scripts.bin',
+ 'scripts/script.sh': None,
+ 'Babarlikestrawberry': None}
+ self.assertFindGlob(rules, spec)
+
def test_glob_in_base(self):
rules = [('scrip*', '*.bin', '{appscript}')]
spec = {'scripts/scripts.bin': '{appscript}/scripts.bin',
--
Repository URL: http://hg.python.org/distutils2
More information about the Python-checkins
mailing list