X-Git-Url: http://git.vrable.net/?a=blobdiff_plain;f=python%2Fcumulus%2Fstore%2Fs3.py;h=65884ea5465e956738c0cae736176575b6e38c7e;hb=65edb87a0b8a578b4a7221478a851d71df21fab0;hp=9fa006e3ae04a2b5873fa5c51b73a94071b3190f;hpb=5f2e50c2ad75043142dc1812fe19dbd7ad86488c;p=cumulus.git diff --git a/python/cumulus/store/s3.py b/python/cumulus/store/s3.py index 9fa006e..65884ea 100644 --- a/python/cumulus/store/s3.py +++ b/python/cumulus/store/s3.py @@ -6,17 +6,24 @@ from boto.s3.key import Key import cumulus.store class S3Store(cumulus.store.Store): - def __init__(self, bucket, prefix): + def __init__(self, url, **kw): + (bucket, prefix) = self.path.lstrip("/").split("/", 1) self.conn = boto.connect_s3(is_secure=False) self.bucket = self.conn.create_bucket(bucket) - while prefix.endswith("/"): prefix = prefix[:-1] - self.prefix = prefix + self.prefix = prefix.rstrip ("/") + 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,5 +45,14 @@ 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)} + +Store = S3Store