From 80a4ba9a5fdc430656f62cd11f1c3785c156f832 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 3 Mar 2013 20:31:57 +0100 Subject: [PATCH] wvtest.py: add a fallback definition of relpath() for Python < 2.6. 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 [rlb@defaultvalue.org: update LICENSE and add comment to code about updating LICENSE.] Signed-off-by: Rob Browning --- LICENSE | 12 ++++++++---- wvtest.py | 24 +++++++++++++++++++++++- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/LICENSE b/LICENSE index 6178f22..f16ccb5 100644 --- 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 diff --git a/wvtest.py b/wvtest.py index 4c4b4b9..27749e3 100755 --- 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() -- 2.39.2