summaryrefslogtreecommitdiff
path: root/morphlib/cachedir.py
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2011-09-29 14:40:47 +0100
committerLars Wirzenius <liw@liw.fi>2011-09-29 14:40:47 +0100
commitca50eed4c902a3454cf7210eeeb818f28d6e7e2a (patch)
treee47b8b237e1aaa3dee236633d279b8bff93ba439 /morphlib/cachedir.py
parente8f1882ce8236081ba7a6cc716cff0754e8a438a (diff)
downloadmorph-ca50eed4c902a3454cf7210eeeb818f28d6e7e2a.tar.gz
Add generation of filenames in the cache directory.
Diffstat (limited to 'morphlib/cachedir.py')
-rw-r--r--morphlib/cachedir.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/morphlib/cachedir.py b/morphlib/cachedir.py
index 88008547..7ee77222 100644
--- a/morphlib/cachedir.py
+++ b/morphlib/cachedir.py
@@ -15,6 +15,7 @@
import hashlib
+import os
class CacheDir(object):
@@ -40,3 +41,24 @@ class CacheDir(object):
data = ''.join(key + value for key, value in dict_key.iteritems())
return hashlib.sha256(data).hexdigest()
+ def name(self, dict_key):
+ '''Return a filename for an object described by dictionary key.
+
+ It is the caller's responsibility to set the fields in the
+ dictionary key suitably. For example, if there is a field
+ specifying a commit id, it should be the full git SHA-1
+ identifier, not something ephemeral like HEAD.
+
+ If the field 'kind' has a value, it is used as a suffix for
+ the filename.
+
+ '''
+
+ key = self.key(dict_key)
+ if 'kind' in dict_key and dict_key['kind']:
+ suffix = '.%s' % dict_key['kind']
+ else:
+ suffix = ''
+
+ return os.path.join(self.dirname, key + suffix)
+