[Python-checkins] distutils2: put relative path logic in a dedicated function

tarek.ziade python-checkins at python.org
Wed Feb 16 22:23:58 CET 2011


tarek.ziade pushed 57af7fec7fd4 to distutils2:

http://hg.python.org/distutils2/rev/57af7fec7fd4
changeset:   1085:57af7fec7fd4
user:        Pierre-Yves David <pierre-yves.david at ens-lyon.org>
date:        Sat Feb 05 17:35:54 2011 +0100
summary:
  put relative path logic in a dedicated function

files:
  distutils2/resources.py

diff --git a/distutils2/resources.py b/distutils2/resources.py
--- a/distutils2/resources.py
+++ b/distutils2/resources.py
@@ -3,6 +3,10 @@
 
 __all__ = ['resources_dests']
 
+def _rel_path(base, path):
+    assert path.startswith(base)
+    return path[len(base):].lstrip('/')
+
 def _expand(root_dir, glob_base, glob_suffix):
     """search for file in a directory and return they radical part.
 
@@ -19,8 +23,8 @@
             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('/')
+        path_suffix = _rel_path(base, glob_file)
+        relpath = _rel_path(root_dir, glob_file)
         yield relpath, path_suffix
 
 def resources_dests(resources_dir, rules):

--
Repository URL: http://hg.python.org/distutils2


More information about the Python-checkins mailing list