Author: jezdez
Date: 2010-12-31 08:22:55 -0600 (Fri, 31 Dec 2010)
New Revision: 15120

Modified:
   django/trunk/django/utils/_os.py
   django/trunk/tests/regressiontests/staticfiles_tests/tests.py
Log:
Added our own rmtree error handler to make sure we can delete correctly delete 
.svn directories when running the tests on Windows which are read-only for some 
reason.

Modified: django/trunk/django/utils/_os.py
===================================================================
--- django/trunk/django/utils/_os.py    2010-12-31 14:22:32 UTC (rev 15119)
+++ django/trunk/django/utils/_os.py    2010-12-31 14:22:55 UTC (rev 15120)
@@ -44,3 +44,23 @@
         raise ValueError('The joined path (%s) is located outside of the base '
                          'path component (%s)' % (final_path, base_path))
     return final_path
+
+def rmtree_errorhandler(func, path, exc_info):
+    """
+    On Windows, some files are read-only (e.g. in in .svn dirs), so when
+    rmtree() tries to remove them, an exception is thrown.
+    We catch that here, remove the read-only attribute, and hopefully
+    continue without problems.
+    """
+    exctype, value = exc_info[:2]
+    # lookin for a windows error
+    if exctype is not WindowsError or 'Access is denied' not in str(value):
+        raise
+    # file type should currently be read only
+    if ((os.stat(path).st_mode & stat.S_IREAD) != stat.S_IREAD):
+        raise
+    # convert to read/write
+    os.chmod(path, stat.S_IWRITE)
+    # use the original function to repeat the operation
+    func(path)
+

Modified: django/trunk/tests/regressiontests/staticfiles_tests/tests.py
===================================================================
--- django/trunk/tests/regressiontests/staticfiles_tests/tests.py       
2010-12-31 14:22:32 UTC (rev 15119)
+++ django/trunk/tests/regressiontests/staticfiles_tests/tests.py       
2010-12-31 14:22:55 UTC (rev 15120)
@@ -13,6 +13,7 @@
 from django.db.models.loading import load_app
 from django.template import Template, Context
 from django.test import TestCase
+from django.utils._os import rmtree_errorhandler
 
 
 TEST_ROOT = os.path.normcase(os.path.dirname(__file__))
@@ -97,7 +98,9 @@
         self.run_collectstatic()
 
     def tearDown(self):
-        shutil.rmtree(settings.STATIC_ROOT)
+        # Use our own error handler that can handle .svn dirs on Windows
+        shutil.rmtree(settings.STATIC_ROOT, ignore_errors=True,
+                      onerror=rmtree_errorhandler)
         settings.STATIC_ROOT = self.old_root
         super(BuildStaticTestCase, self).tearDown()
 

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to