X-Git-Url: http://git.vrable.net/?p=cumulus.git;a=blobdiff_plain;f=python%2Fcumulus%2Fstore%2Fs3.py;h=63efa17d5d7b748a55f4aede245147e234350f6c;hp=1e7257af00d80016468bbe46ad2578fa39527e5a;hb=92488d46a0deca6d031d07852c3b79214280ab6d;hpb=0d3714dd199cb13174bdcacf7bc9e65290769b6f diff --git a/python/cumulus/store/s3.py b/python/cumulus/store/s3.py index 1e7257a..63efa17 100644 --- a/python/cumulus/store/s3.py +++ b/python/cumulus/store/s3.py @@ -11,12 +11,19 @@ class S3Store(cumulus.store.Store): self.bucket = self.conn.create_bucket(bucket) while prefix.endswith("/"): prefix = prefix[:-1] self.prefix = prefix + self.scan_cache = {} def _get_key(self, type, name): k = Key(self.bucket) k.key = "%s/%s/%s" % (self.prefix, type, name) return k + def scan(self): + prefix = "%s/" % (self.prefix,) + for i in self.bucket.list(prefix): + assert i.key.startswith(prefix) + self.scan_cache[i.key] = i + def list(self, type): prefix = "%s/%s/" % (self.prefix, type) for i in self.bucket.list(prefix): @@ -38,7 +45,12 @@ class S3Store(cumulus.store.Store): self.bucket.delete_key("%s/%s/%s" % (self.prefix, type, name)) def stat(self, type, name): - k = self.bucket.get_key("%s/%s/%s" % (self.prefix, type, name)) + path = "%s/%s/%s" % (self.prefix, type, name) + if path in self.scan_cache: + k = self.scan_cache[path] + else: + k = self.bucket.get_key(path) if k is None: raise cumulus.store.NotFoundError + return {'size': int(k.size)}