[Erp5-report] r39577 jm - /erp5/trunk/products/ERP5Type/tests/

nobody at svn.erp5.org nobody at svn.erp5.org
Wed Oct 27 21:03:11 CEST 2010


Author: jm
Date: Wed Oct 27 21:03:09 2010
New Revision: 39577

URL: http://svn.erp5.org?rev=39577&view=rev
Log:
runUnitTest: use symlinks to avoid dangerous copies of static files

Modified:
    erp5/trunk/products/ERP5Type/tests/custom_zodb.py
    erp5/trunk/products/ERP5Type/tests/runUnitTest.py

Modified: erp5/trunk/products/ERP5Type/tests/custom_zodb.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/tests/custom_zodb.py?rev=39577&r1=39576&r2=39577&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/tests/custom_zodb.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/tests/custom_zodb.py [utf8] Wed Oct 27 21:03:09 2010
@@ -1,3 +1,4 @@
+import errno
 import os
 import shutil
 import socket
@@ -9,7 +10,7 @@ from asyncore import socket_map
 from ZODB.DemoStorage import DemoStorage
 from ZODB.FileStorage import FileStorage
 from Products.ERP5Type.tests.utils import getMySQLArguments, instance_random
-from Products.ERP5Type.tests.runUnitTest import static_dir_list
+from Products.ERP5Type.tests.runUnitTest import static_dir_list, WIN
 
 def _print(message):
   sys.stderr.write(message + "\n")
@@ -45,9 +46,12 @@ if save_mysql:
     os.system(command)
 
 _print("Cleaning static files ... ")
-for dir in static_dir_list:
-  for f in glob.glob(os.path.join(instance_home, dir, '*')):
-    os.remove(f)
+for static_dir in static_dir_list:
+  static_dir = os.path.join(instance_home, static_dir)
+  if os.path.islink(static_dir):
+    os.remove(static_dir)
+  elif os.path.exists(static_dir):
+    shutil.rmtree(static_dir)
 
 if load:
   if save_mysql:
@@ -68,11 +72,20 @@ if load:
     else:
       backup_path = full_path + '.bak'
     if os.path.exists(backup_path):
-      os.rmdir(full_path)
-      shutil.copytree(backup_path, full_path, symlinks=True)
+      if not save or WIN:
+        shutil.copytree(backup_path, full_path, symlinks=True)
+      else:
+        if not live_instance_path:
+          backup_path = os.path.basename(backup_path)
+        os.symlink(backup_path, full_path)
 elif save and not zeo_client and os.path.exists(data_fs_path):
   os.remove(data_fs_path)
 
+for static_dir in static_dir_list:
+  static_dir = os.path.join(instance_home, static_dir)
+  if not os.path.exists(static_dir):
+    os.mkdir(static_dir)
+
 zeo_server_pid = None
 zeo_client_pid_list = []
 

Modified: erp5/trunk/products/ERP5Type/tests/runUnitTest.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/tests/runUnitTest.py?rev=39577&r1=39576&r2=39577&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/tests/runUnitTest.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/tests/runUnitTest.py [utf8] Wed Oct 27 21:03:09 2010
@@ -159,14 +159,7 @@ def initializeInstanceHome(tests_framewo
   old_pwd = os.getcwd()
   try:
     os.chdir(instance_home)
-    # Before r23751, Extensions dir was initialized to be a symlink to real
-    # instance home Extensions folder, now it's initialized as an independant
-    # folder. If this test instance still have a symlink for Extensions, change
-    # it in a folder.
-    if os.path.islink('Extensions'):
-      os.remove('Extensions')
-
-    for d in static_dir_list + ('bin', 'etc', 'tests', 'var', 'log'):
+    for d in ('bin', 'etc', 'tests', 'var', 'log'):
       if not os.path.exists(d):
         os.mkdir(d)
     for d in ('Products', 'bt5', 'svn', 'lib', 'import'):
@@ -571,6 +564,8 @@ def runUnitTestList(test_list, verbosity
         _print('Dumping static files...\n')
       live_instance_path = os.environ.get('live_instance_path')
       for static_dir in static_dir_list:
+        if os.path.islink(static_dir):
+          continue
         if live_instance_path:
           backup_path = os.path.join(live_instance_path, static_dir)
         else:
@@ -580,7 +575,7 @@ def runUnitTestList(test_list, verbosity
         except OSError, e:
           if e.errno != errno.ENOENT:
             raise
-        shutil.copytree(static_dir, backup_path, symlinks=True)
+        os.rename(static_dir, backup_path)
     elif zeo_client_pid_list is not None:
       _print('WARNING: No static files saved. You will have to do it manually.')
 




More information about the Erp5-report mailing list