From e152c866ef6ffd8b1433fbe13e4ecf822d3669dc Mon Sep 17 00:00:00 2001
From: Leif Walsh <leif@tokutek.com>
Date: Wed, 17 Apr 2013 00:01:21 -0400
Subject: [PATCH] fix stress test python script to save libs properly

git-svn-id: file:///svn/toku/tokudb@50790 c7de825b-a66e-492c-adef-691d508d4ae1
---
 scripts/run.stress-tests.py | 109 ++++++++++++++++++------------------
 1 file changed, 55 insertions(+), 54 deletions(-)

diff --git a/scripts/run.stress-tests.py b/scripts/run.stress-tests.py
index 21206073be8..e253e0571ce 100755
--- a/scripts/run.stress-tests.py
+++ b/scripts/run.stress-tests.py
@@ -46,6 +46,59 @@ __copyright__ = """Copyright (c) 2007-2012 Tokutek Inc.  All rights reserved.
                 No. 11/760379 and to the patents and/or patent
                 applications resulting from it."""
 
+# relpath implementation for python <2.6
+# from http://unittest-ext.googlecode.com/hg-history/1df911640f7be239e58fb185b06ac2a8489dcdc4/unittest2/unittest2/compatibility.py
+if not hasattr(os.path, 'relpath'):
+    if os.path is sys.modules.get('ntpath'):
+        def relpath(path, start=os.path.curdir):
+            """Return a relative version of a path"""
+
+            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)
+            if start_list[0].lower() != path_list[0].lower():
+                unc_path, rest = os.path.splitunc(path)
+                unc_start, rest = os.path.splitunc(start)
+                if bool(unc_path) ^ bool(unc_start):
+                    raise ValueError("Cannot mix UNC and non-UNC paths (%s and %s)"
+                                                                        % (path, start))
+                else:
+                    raise ValueError("path is on drive %s, start on drive %s"
+                                                        % (path_list[0], start_list[0]))
+            # Work out how much of the filepath is shared by start and path.
+            for i in range(min(len(start_list), len(path_list))):
+                if start_list[i].lower() != path_list[i].lower():
+                    break
+            else:
+                i += 1
+
+            rel_list = [os.path.pardir] * (len(start_list)-i) + path_list[i:]
+            if not rel_list:
+                return os.path.curdir
+            return os.path.join(*rel_list)
+
+    else:
+        # default to posixpath definition
+        def relpath(path, start=os.path.curdir):
+            """Return a relative version of a path"""
+
+            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 os.path.curdir
+            return os.path.join(*rel_list)
+
+    os.path.relpath = relpath
+
 def setlimits():
     setrlimit(RLIMIT_CORE, (-1, -1))
     os.nice(7)
@@ -201,7 +254,8 @@ class TestRunnerBase(object):
         copy(fullexecf, targetfor(fullexecf))
         for libname in ['util/libutil.so', 'portability/libtokuportability.so', 'src/libtokudb.so']:
             fulllibpath = os.path.join(self.builddir, libname)
-            targetpath = os.path.join(savedir, fulllibpath)
+            libpathfromroot = os.path.relpath(fulllibpath, '/')
+            targetpath = os.path.join(savedir, libpathfromroot)
             targetdir = os.path.dirname(targetpath)
             if not os.path.exists(targetdir):
                 os.makedirs(targetdir)
@@ -632,59 +686,6 @@ def main(opts):
         exception('Unhandled exception caught in main.')
         raise e
 
-# relpath implementation for python <2.6
-# from http://unittest-ext.googlecode.com/hg-history/1df911640f7be239e58fb185b06ac2a8489dcdc4/unittest2/unittest2/compatibility.py
-if not hasattr(os.path, 'relpath'):
-    if os.path is sys.modules.get('ntpath'):
-        def relpath(path, start=os.path.curdir):
-            """Return a relative version of a path"""
-
-            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)
-            if start_list[0].lower() != path_list[0].lower():
-                unc_path, rest = os.path.splitunc(path)
-                unc_start, rest = os.path.splitunc(start)
-                if bool(unc_path) ^ bool(unc_start):
-                    raise ValueError("Cannot mix UNC and non-UNC paths (%s and %s)"
-                                                                        % (path, start))
-                else:
-                    raise ValueError("path is on drive %s, start on drive %s"
-                                                        % (path_list[0], start_list[0]))
-            # Work out how much of the filepath is shared by start and path.
-            for i in range(min(len(start_list), len(path_list))):
-                if start_list[i].lower() != path_list[i].lower():
-                    break
-            else:
-                i += 1
-
-            rel_list = [os.path.pardir] * (len(start_list)-i) + path_list[i:]
-            if not rel_list:
-                return os.path.curdir
-            return os.path.join(*rel_list)
-
-    else:
-        # default to posixpath definition
-        def relpath(path, start=os.path.curdir):
-            """Return a relative version of a path"""
-
-            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 os.path.curdir
-            return os.path.join(*rel_list)
-
-    os.path.relpath = relpath
-
 if __name__ == '__main__':
     a0 = os.path.abspath(sys.argv[0])
     usage = '%prog [options]\n' + __doc__