[Python-checkins] distutils2: remove useless SmartGlob class used by distutils2 module.
tarek.ziade
python-checkins at python.org
Wed Feb 16 22:23:58 CET 2011
tarek.ziade pushed 06cf46799b59 to distutils2:
http://hg.python.org/distutils2/rev/06cf46799b59
changeset: 1083:06cf46799b59
user: Pierre-Yves David <pierre-yves.david at ens-lyon.org>
date: Sat Feb 05 17:08:29 2011 +0100
summary:
remove useless SmartGlob class used by distutils2 module.
files:
distutils2/resources.py
diff --git a/distutils2/resources.py b/distutils2/resources.py
--- a/distutils2/resources.py
+++ b/distutils2/resources.py
@@ -3,39 +3,39 @@
__all__ = ['resources_dests']
-class SmartGlob(object):
+def _expand(root_dir, glob_base, glob_suffix, destination):
+ """search for file in a directory and return they expected destination.
- def __init__(self, base, suffix):
- self.base = base
- self.suffix = suffix
-
-
- def expand(self, basepath, destination):
- if self.base:
- base = os.path.join(basepath, self.base)
- else:
- base = basepath
- if '*' in base or '{' in base or '}' in base:
- raise NotImplementedError('glob are not supported into base part\
- of resources definition. %r is an invalide basepath' % base)
- absglob = os.path.join(base, self.suffix)
- for glob_file in iglob(absglob):
- path_suffix = glob_file[len(base):].lstrip('/')
- relpath = glob_file[len(basepath):].lstrip('/')
- dest = os.path.join(destination, path_suffix)
- yield relpath, dest
+ root_dir: directory where to search for resources.
+ glob_base: part of the path not included in destination.
+ glob_suffix: part of the path reused in the destination.
+ destination: base part of the destination.
+ """
+ if glob_base:
+ base = os.path.join(root_dir, glob_base)
+ else:
+ base = root_dir
+ if '*' in base or '{' in base or '}' in base:
+ raise NotImplementedError('glob are not supported into base part\
+ of resources definition. %r is an invalide root_dir' % base)
+ absglob = os.path.join(base, glob_suffix)
+ for glob_file in iglob(absglob):
+ path_suffix = glob_file[len(base):].lstrip('/')
+ relpath = glob_file[len(root_dir):].lstrip('/')
+ dest = os.path.join(destination, path_suffix)
+ yield relpath, dest
def resources_dests(resources_dir, rules):
+ """find destination of ressources files"""
destinations = {}
for (base, suffix, glob_dest) in rules:
- sglob = SmartGlob(base, suffix)
if glob_dest is None:
delete = True
dest = ''
else:
delete = False
dest = glob_dest
- for resource_file, file_dest in sglob.expand(resources_dir, dest):
+ for resource_file, file_dest in _expand(resources_dir, base, suffix, dest):
if delete and resource_file in destinations:
del destinations[resource_file]
else:
--
Repository URL: http://hg.python.org/distutils2
More information about the Python-checkins
mailing list