diff options
author | willmcgugan <willmcgugan@67cdc799-7952-0410-af00-57a81ceafa0f> | 2008-09-08 11:04:43 +0000 |
---|---|---|
committer | willmcgugan <willmcgugan@67cdc799-7952-0410-af00-57a81ceafa0f> | 2008-09-08 11:04:43 +0000 |
commit | 7ae5f69d2b2e47ff13c5834ea860b527182c35ef (patch) | |
tree | 08cd26cd48fee6480c2c134064a68ccf5fab92cd /fs/tempfs.py | |
parent | 40309dd53c5644f04c2ed217abf8469540518596 (diff) | |
download | pyfilesystem-7ae5f69d2b2e47ff13c5834ea860b527182c35ef.tar.gz |
Work in progress
git-svn-id: http://pyfilesystem.googlecode.com/svn/trunk@60 67cdc799-7952-0410-af00-57a81ceafa0f
Diffstat (limited to 'fs/tempfs.py')
-rw-r--r-- | fs/tempfs.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/fs/tempfs.py b/fs/tempfs.py new file mode 100644 index 0000000..3361966 --- /dev/null +++ b/fs/tempfs.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python + +from osfs import OSFS +import tempfile +from shutil import rmtree + +class TempFS(OSFS): + + """Create a Filesystem in a tempory directory (with tempfile.mkdtemp), + and removes it when the TempFS object is cleaned up.""" + + def __init__(self): + self._temp_dir = tempfile.mkdtemp("fstest") + OSFS.__init__(self, self._temp_dir) + + def _cleanup(self): + if self._temp_dir: + rmtree(self._temp_dir) + self._temp_dir = "" + + def __del__(self): + self._cleanup() |