+class S3Backend:
+ """An interface to BlueSky where the log segments are on in Amazon S3."""
+
+ def __init__(self, bucket, path='', cachedir=None):
+ self.conn = boto.connect_s3(is_secure=False)
+ self.bucket = self.conn.get_bucket(bucket)
+ self.path = path
+
+ def list(self):
+ files = []
+ for k in self.bucket.list(self.path + 'log-'):
+ files.append((k.key, k.size))
+ return files
+
+ def read(self, filename):
+ k = Key(self.bucket)
+ k.key = self.path + filename
+ return k.get_contents_as_string()
+
+ def write(self, filename, data):
+ k = Key(self.bucket)
+ k.key = self.path + filename
+ k.set_contents_from_string(data)
+
+ def delete(self, filename):
+ k = Key(self.bucket)
+ k.key = self.path + filename
+ k.delete()
+
+ def loc_to_name(self, location):
+ return "log-%08d-%08d" % (location)
+
+ def name_to_loc(self, name):
+ m = re.match(r"^log-(\d+)-(\d+)$", name)
+ if m: return (int(m.group(1)), int(m.group(2)))
+