diff options
author | willmcgugan@gmail.com <willmcgugan@gmail.com@67cdc799-7952-0410-af00-57a81ceafa0f> | 2013-03-31 21:30:34 +0000 |
---|---|---|
committer | willmcgugan@gmail.com <willmcgugan@gmail.com@67cdc799-7952-0410-af00-57a81ceafa0f> | 2013-03-31 21:30:34 +0000 |
commit | 3ea4efe11b1a7f31c355103608950379d52fdec5 (patch) | |
tree | 5547f10f29e28894ae70ff5b97e858456f94103a /fs/tempfs.py | |
parent | c6391b6f5dcf2a30d4657b5808f9f668fbc02de3 (diff) | |
download | pyfilesystem-git-3ea4efe11b1a7f31c355103608950379d52fdec5.tar.gz |
Change of api (fs.open, fs.setcontent, fs.getcontents) to support io module in Py2.6+ and Py3
Diffstat (limited to 'fs/tempfs.py')
-rw-r--r-- | fs/tempfs.py | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/fs/tempfs.py b/fs/tempfs.py index bc7d75f..4142e9a 100644 --- a/fs/tempfs.py +++ b/fs/tempfs.py @@ -10,13 +10,14 @@ import os import os.path import time import tempfile -import platform +from fs.base import synchronize from fs.osfs import OSFS from fs.errors import * from fs import _thread_synchronize_default + class TempFS(OSFS): """Create a Filesystem in a temporary directory (with tempfile.mkdtemp), @@ -38,7 +39,7 @@ class TempFS(OSFS): self.identifier = identifier self.temp_dir = temp_dir self.dir_mode = dir_mode - self._temp_dir = tempfile.mkdtemp(identifier or "TempFS",dir=temp_dir) + self._temp_dir = tempfile.mkdtemp(identifier or "TempFS", dir=temp_dir) self._cleaned = False super(TempFS, self).__init__(self._temp_dir, dir_mode=dir_mode, thread_synchronize=thread_synchronize) @@ -65,6 +66,7 @@ class TempFS(OSFS): # dir_mode=self.dir_mode, # thread_synchronize=self.thread_synchronize) + @synchronize def close(self): """Removes the temporary directory. @@ -73,13 +75,13 @@ class TempFS(OSFS): Note that once this method has been called, the FS object may no longer be used. """ - super(TempFS,self).close() + super(TempFS, self).close() # Depending on how resources are freed by the OS, there could # be some transient errors when freeing a TempFS soon after it # was used. If they occur, do a small sleep and try again. try: self._close() - except (ResourceLockedError,ResourceInvalidError): + except (ResourceLockedError, ResourceInvalidError): time.sleep(0.5) self._close() @@ -97,20 +99,23 @@ class TempFS(OSFS): try: # shutil.rmtree doesn't handle long paths on win32, # so we walk the tree by hand. - entries = os.walk(self.root_path,topdown=False) - for (dir,dirnames,filenames) in entries: + entries = os.walk(self.root_path, topdown=False) + for (dir, dirnames, filenames) in entries: for filename in filenames: try: - os_remove(os.path.join(dir,filename)) + os_remove(os.path.join(dir, filename)) except ResourceNotFoundError: pass for dirname in dirnames: try: - os_rmdir(os.path.join(dir,dirname)) + os_rmdir(os.path.join(dir, dirname)) except ResourceNotFoundError: pass - os.rmdir(self.root_path) + try: + os.rmdir(self.root_path) + except OSError: + pass self._cleaned = True finally: self._lock.release() - super(TempFS,self).close() + super(TempFS, self).close() |