SVN: zope.testing/trunk/src/zope/testing/setupstack. More carefully remove temporary directories to deal with read-only files on windows

Jim Fulton <[email protected]>
Newsgroups gmane.comp.web.zope.zope3.cvs
Message-ID <20081017182358.899C039634__25567.4554886811$1224267967$gmane$org@cvs.zope.org>
Log message for revision 92340:
  More carefully remove temporary directories to deal with read-only files on windows

Changed:
  U   zope.testing/trunk/src/zope/testing/setupstack.py
  U   zope.testing/trunk/src/zope/testing/setupstack.txt

-=-
Modified: zope.testing/trunk/src/zope/testing/setupstack.py
===================================================================
--- zope.testing/trunk/src/zope/testing/setupstack.py	2008-10-17 17:43:09 UTC (rev 92339)
+++ zope.testing/trunk/src/zope/testing/setupstack.py	2008-10-17 18:23:57 UTC (rev 92340)
@@ -16,7 +16,7 @@
 See setupstack.txt
 """
 
-import os, shutil, tempfile
+import os, stat, tempfile
 
 key = '__' + __name__
 
@@ -34,9 +34,19 @@
 
 def setUpDirectory(test):
     tmp = tempfile.mkdtemp()
-    register(test, shutil.rmtree, tmp)
+    register(test, rmtree, tmp)
     here = os.getcwd()
     register(test, os.chdir, here)
     os.chdir(tmp)
 
+def rmtree(path):
+    for path, dirs, files in os.walk(path, False):
+        for fname in files:
+            fname = os.path.join(path, fname)
+            os.chmod(fname, stat.S_IWUSR)
+            os.remove(fname)
+        for dname in dirs:
+            dname = os.path.join(path, dname)
+            os.rmdir(dname)
+    os.rmdir(path)
     

Modified: zope.testing/trunk/src/zope/testing/setupstack.txt
===================================================================
--- zope.testing/trunk/src/zope/testing/setupstack.txt	2008-10-17 17:43:09 UTC (rev 92339)
+++ zope.testing/trunk/src/zope/testing/setupstack.txt	2008-10-17 18:23:57 UTC (rev 92340)
@@ -80,6 +80,13 @@
     >>> os.path.exists('Data.fs')
     True
 
+We'll make the file read-only. This can cause problems on Windows, but
+setupstack takes care of that by making files writable before trying
+to remove them.
+
+    >>> import stat
+    >>> os.chmod('Data.fs', stat.S_IREAD)
+
 When tearDown is called:
 
     >>> zope.testing.setupstack.tearDown(test)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.