summaryrefslogtreecommitdiff
path: root/morphlib/cachedir.py
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2011-09-29 14:29:19 +0100
committerLars Wirzenius <liw@liw.fi>2011-09-29 14:29:19 +0100
commite8f1882ce8236081ba7a6cc716cff0754e8a438a (patch)
tree8ad1ddb437f2fa3f74afa65d99c959fc49d659ec /morphlib/cachedir.py
parentfebe4fdc0d1f1cfe902300b0b85bd990d88eef50 (diff)
downloadmorph-e8f1882ce8236081ba7a6cc716cff0754e8a438a.tar.gz
Add CacheDir.key method.
Diffstat (limited to 'morphlib/cachedir.py')
-rw-r--r--morphlib/cachedir.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/morphlib/cachedir.py b/morphlib/cachedir.py
index a8e8dec6..88008547 100644
--- a/morphlib/cachedir.py
+++ b/morphlib/cachedir.py
@@ -14,9 +14,29 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+import hashlib
+
+
class CacheDir(object):
'''Manage Baserock cached binaries.'''
def __init__(self, dirname):
self.dirname = dirname
+
+ def key(self, dict_key):
+ '''Create a string key from a dictionary key.
+
+ The string key can be used as a filename, or as part of one.
+ The dictionary key is a dict that maps any set of strings to
+ another set of strings.
+
+ The same string key is guaranteed to be returned for a given
+ dictionary key. It is highly unlikely that two different dictionary
+ keys result in the same string key.
+
+ '''
+
+ data = ''.join(key + value for key, value in dict_key.iteritems())
+ return hashlib.sha256(data).hexdigest()
+