summaryrefslogtreecommitdiff
path: root/morphlib/cachedir.py
diff options
context:
space:
mode:
Diffstat (limited to 'morphlib/cachedir.py')
-rw-r--r--morphlib/cachedir.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/morphlib/cachedir.py b/morphlib/cachedir.py
index cc528a43..d0763c4c 100644
--- a/morphlib/cachedir.py
+++ b/morphlib/cachedir.py
@@ -17,6 +17,8 @@
import hashlib
import os
+import morphlib
+
class CacheDir(object):
@@ -62,3 +64,18 @@ class CacheDir(object):
return os.path.join(self.dirname, key + suffix)
+ def open(self, relative_name):
+ '''Open a file for writing in the cache.
+
+ The file will be written with a temporary name, and renamed to
+ the final name when the file is closed. Additionally, if the
+ caller decides, mid-writing, that they don't want to write the
+ file after all (e.g., a log file), then the ``abort`` method
+ in the returned file handle can be called to remove the
+ temporary file.
+
+ '''
+
+ path = os.path.join(self.dirname, relative_name)
+ return morphlib.savefile.SaveFile(path, 'w')
+