summaryrefslogtreecommitdiff
path: root/patchtracker/CacheObject.py
diff options
context:
space:
mode:
authorSean Finney <seanius@debian.org>2010-05-17 06:11:23 +0200
committerSean Finney <seanius@debian.org>2010-05-17 06:11:23 +0200
commit168b7f0f311af1a3ef959a2d4810accf8b2d2a42 (patch)
tree04ce72c2d8a5bcda7cbada7a6e6343f4d29fea66 /patchtracker/CacheObject.py
parent3354dec92cbe14761146c1b964237145160ed3f9 (diff)
downloadpatch-tracker-168b7f0f311af1a3ef959a2d4810accf8b2d2a42.tar.gz
Remove dead CacheObject code
Diffstat (limited to 'patchtracker/CacheObject.py')
-rw-r--r--patchtracker/CacheObject.py63
1 files changed, 0 insertions, 63 deletions
diff --git a/patchtracker/CacheObject.py b/patchtracker/CacheObject.py
deleted file mode 100644
index c37c3b5..0000000
--- a/patchtracker/CacheObject.py
+++ /dev/null
@@ -1,63 +0,0 @@
-import errno
-import gzip
-import md5
-import os
-
-import Conf
-
-class CacheMissException (Exception):
- pass
-
-class CacheObject:
- """ A CacheObject is a compressed on-disk version of a serialized object.
- """
- def __init__ (self, key=None, keys=None):
- self.obj = None
- #print "CacheObject: key=%s keys=%s"%(key, keys)
- if not key and not keys:
- raise "CacheObject needs at least one of key, keys"
- checksum = md5.md5()
- if key:
- checksum.update(key)
- if keys:
- for k in keys:
- checksum.update(str(k))
- self.path = os.path.sep.join([Conf.cachedir, checksum.hexdigest()])
-
- def get(self):
- if not self.obj:
- try:
- if Conf.cachecompress:
- self.obj = gzip.GzipFile(self.path).read()
- else:
- self.obj = file(self.path).read()
- except IOError, e:
- if e.errno != errno.ENOENT:
- raise e
- else:
- #print "CacheObject: cache miss"
- raise CacheMissException("Object not present in cache")
- #print "CacheObject: cache hit"
- return self.obj
-
- def put(self, obj):
- self.obj = obj
- #print "CacheObject: cache put"
- try:
- if Conf.cachecompress:
- gzip.GzipFile(self.path, "wb").write(str(self.obj))
- else:
- file(self.path, "wb").write(str(self.obj))
- except Exception, e:
- os.unlink(self.path)
- raise e
-
-if __name__ == '__main__':
- co = CacheObject( key="magic" )
- try:
- print "going to try to read an object before it exists"
- print "first line:", co.get().split()[0]
- except CacheMissException:
- print "file was missing as expected. now let's try to put it and fetch it"
- co.put(file("/etc/passwd").read())
- print "first line:", co.get().split()[0]