]> arthur.barton.de Git - bup.git/commitdiff
wvtest.py: add a fallback definition of relpath() for Python < 2.6.
authorThomas Haller <thom311@gmail.com>
Sun, 3 Mar 2013 19:31:57 +0000 (20:31 +0100)
committerRob Browning <rlb@defaultvalue.org>
Sat, 23 Mar 2013 19:31:57 +0000 (14:31 -0500)
Since bup still supports Python 2.5 and relpath was added to Python in
2.6, add an os.path.relpath replacement, adapted from CPython source
(tag v2.6, file Lib/posixpath.py, hg-commit 95fff5a6a276).

Signed-off-by: Thomas Haller <thom311@gmail.com>
[rlb@defaultvalue.org: update LICENSE and add comment to code about
 updating LICENSE.]
Signed-off-by: Rob Browning <rlb@defaultvalue.org>
LICENSE
wvtest.py

diff --git a/LICENSE b/LICENSE
index 6178f22d475ad51da9e68e4eaf636ef2d866406d..f16ccb5f880982105bbcb6a1c4104625142dd3e7 100644 (file)
--- a/LICENSE
+++ b/LICENSE
@@ -1,11 +1,15 @@
 
-The files in this project may all be distributed under the terms of the
-following license. (The LGPL version 2.)
+Unless otherwise stated below, the files in this project may be
+distributed under the terms of the following license. (The LGPL
+version 2.)
 
 In addition, bupsplit.c, bupsplit.h, and options.py may be
-redistributed according to the separate license (a BSD-style license)
-written inside those files.
+redistributed according to the separate (BSD-style) license written
+inside those files.
 
+The definition of the relpath function was taken from CPython (tag
+v2.6, file Lib/posixpath.py, hg-commit 95fff5a6a276) and is covered
+under the terms of the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2.
 
 
                  GNU LIBRARY GENERAL PUBLIC LICENSE
index 4c4b4b99d0469e668c8241f8007230ac41a6a3f5..27749e348834ee354e58c59189e4a23cee93937b 100755 (executable)
--- a/wvtest.py
+++ b/wvtest.py
@@ -149,9 +149,31 @@ def _run_in_chdir(path, func, *args, **kwargs):
         sys.path = oldpath
 
 
+if sys.version_info >= (2,6,0):
+    _relpath = os.path.relpath;
+else:
+    # Implementation for Python 2.5, taken from CPython (tag v2.6,
+    # file Lib/posixpath.py, hg-commit 95fff5a6a276).  Update
+    # ./LICENSE When this code is eventually removed.
+    def _relpath(path, start=os.path.curdir):
+        if not path:
+            raise ValueError("no path specified")
+
+        start_list = os.path.abspath(start).split(os.path.sep)
+        path_list = os.path.abspath(path).split(os.path.sep)
+
+        # Work out how much of the filepath is shared by start and path.
+        i = len(os.path.commonprefix([start_list, path_list]))
+
+        rel_list = [os.path.pardir] * (len(start_list)-i) + path_list[i:]
+        if not rel_list:
+            return curdir
+        return os.path.join(*rel_list)
+
+
 def _runtest(fname, f):
     mod = inspect.getmodule(f)
-    relpath = os.path.relpath(mod.__file__, os.getcwd()).replace('.pyc', '.py')
+    relpath = _relpath(mod.__file__, os.getcwd()).replace('.pyc', '.py')
     print
     print 'Testing "%s" in %s:' % (fname, relpath)
     sys.stdout.flush()