Commit 29a1ca1c by rfkelly0

utility method for S3FS: get_total_size

parent 991cf3e8
...@@ -65,7 +65,7 @@ class S3FS(FS): ...@@ -65,7 +65,7 @@ class S3FS(FS):
# Normalise prefix to this form: path/to/files/ # Normalise prefix to this form: path/to/files/
while prefix.startswith(separator): while prefix.startswith(separator):
prefix = prefix[1:] prefix = prefix[1:]
if not prefix.endswith(separator): if not prefix.endswith(separator) and prefix != "":
prefix = prefix + separator prefix = prefix + separator
self._prefix = prefix self._prefix = prefix
FS.__init__(self, thread_syncronize=thread_syncronize) FS.__init__(self, thread_syncronize=thread_syncronize)
...@@ -449,3 +449,7 @@ class S3FS(FS): ...@@ -449,3 +449,7 @@ class S3FS(FS):
self.copy(src,dst,overwrite=overwrite) self.copy(src,dst,overwrite=overwrite)
self._s3bukt.delete_key(self._s3path(src)) self._s3bukt.delete_key(self._s3path(src))
def get_total_size(self):
"""Get total size of all files in this FS."""
return sum(k.size for k in self._s3bukt.list(prefix=self._prefix))
...@@ -711,7 +711,7 @@ class TestAppendZipFS(TestWriteZipFS): ...@@ -711,7 +711,7 @@ class TestAppendZipFS(TestWriteZipFS):
import s3fs import s3fs
class TestS3FS(TestOSFS): class TestS3FS(TestOSFS):
bucket = "test-s3fs-new.rfk.id.au" bucket = "test-s3fs.rfk.id.au"
def setUp(self): def setUp(self):
self.fs = s3fs.S3FS(self.bucket,"/unittest/files") self.fs = s3fs.S3FS(self.bucket,"/unittest/files")
...@@ -728,7 +728,7 @@ class TestS3FS(TestOSFS): ...@@ -728,7 +728,7 @@ class TestS3FS(TestOSFS):
self._clear() self._clear()
for k in self.fs._s3bukt.list(): for k in self.fs._s3bukt.list():
self.fs._s3bukt.delete_key(k) self.fs._s3bukt.delete_key(k)
#self.fs._s3conn.delete_bucket(self.bucket) self.fs._s3conn.delete_bucket(self.bucket)
def check(self, p): def check(self, p):
return self.fs.exists(p) return self.fs.exists(p)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment