summaryrefslogtreecommitdiff
path: root/morphlib/cachedir.py
diff options
context:
space:
mode:
authorLars Wirzenius <lars.wirzenius@codethink.co.uk>2012-03-01 14:56:26 +0000
committerLars Wirzenius <lars.wirzenius@codethink.co.uk>2012-03-02 17:13:29 +0000
commitfafeea2dfcf5de44c72bde892e3e053b652479cf (patch)
tree3e3a17225405479a3b1727e60640c4f54b0034cf /morphlib/cachedir.py
parent8c9369d86d0168e9509ec06d7bb5f4f9b5e82311 (diff)
downloadmorph-fafeea2dfcf5de44c72bde892e3e053b652479cf.tar.gz
Change Cachedir.open to allow dict_key instead of basename, and optional suffix
Diffstat (limited to 'morphlib/cachedir.py')
-rw-r--r--morphlib/cachedir.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/morphlib/cachedir.py b/morphlib/cachedir.py
index d0763c4c..6bd75608 100644
--- a/morphlib/cachedir.py
+++ b/morphlib/cachedir.py
@@ -64,7 +64,7 @@ class CacheDir(object):
return os.path.join(self.dirname, key + suffix)
- def open(self, relative_name):
+ def open(self, relative_name_or_cache_key, suffix=''):
'''Open a file for writing in the cache.
The file will be written with a temporary name, and renamed to
@@ -75,7 +75,11 @@ class CacheDir(object):
temporary file.
'''
-
- path = os.path.join(self.dirname, relative_name)
+
+ if type(relative_name_or_cache_key) is dict:
+ path = self.name(relative_name_or_cache_key)
+ else:
+ path = os.path.join(self.dirname, relative_name_or_cache_key)
+ path += suffix
return morphlib.savefile.SaveFile(path, 'w')