Commits

Pierre-Yves David committed 9e136b0

simplify expand function by remove the "destination" argument.

Comments (0)

Files changed (1)

distutils2/resources.py

 
 __all__ = ['resources_dests']
 
-def _expand(root_dir, glob_base, glob_suffix, destination):
-    """search for file in a directory and return they expected destination.
+def _expand(root_dir, glob_base, glob_suffix):
+    """search for file in a directory and return they radical part.
 
     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.
+    glob_base:   part of the path not included in radical.
+    glob_suffix: part of the path used as radical.
     """
     if glob_base:
         base = os.path.join(root_dir, glob_base)
     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
+        yield relpath, path_suffix
 
 def resources_dests(resources_dir, rules):
     """find destination of ressources files"""
     destinations = {}
     for (base, suffix, glob_dest) in rules:
-        if glob_dest is None:
-            delete = True
-            dest = ''
-        else:
-            delete = False
-            dest = glob_dest
-        for resource_file, file_dest in _expand(resources_dir, base, suffix, dest):
-            if delete and resource_file in destinations:
-                del destinations[resource_file]
+        for resource_file, radical in _expand(resources_dir, base, suffix):
+            if glob_dest is None:
+                destinations.pop(resource_file, None) #remove the entry if it was here
             else:
-                destinations[resource_file] = file_dest
+                destinations[resource_file] = os.path.join(glob_dest, radical)
     return destinations