Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge remote-tracking branch 'manos/master' into manos-merge

  • Loading branch information...
commit 352e33b8bfe95ddacaad650a1773b5a56135e131 2 parents 1e63679 + cf2bdf3
@mdomsch authored
Showing with 21 additions and 11 deletions.
  1. +21 −11 s3cmd
View
32 s3cmd
@@ -67,18 +67,28 @@ def subcmd_bucket_usage(s3, uri):
if object.endswith('*'):
object = object[:-1]
- try:
- response = s3.bucket_list(bucket, prefix = object, recursive = True)
- except S3Error, e:
- if S3.codes.has_key(e.info["Code"]):
- error(S3.codes[e.info["Code"]] % bucket)
- return
- else:
- raise
+
bucket_size = 0
- for object in response["list"]:
- size, size_coeff = formatSize(object["Size"], False)
- bucket_size += size
+ # iterate and store directories to traverse, while summing objects:
+ dirs = [object]
+ while dirs:
+ try:
+ response = s3.bucket_list(bucket, prefix=dirs.pop())
+ except S3Error, e:
+ if S3.codes.has_key(e.info["Code"]):
+ error(S3.codes[e.info["Code"]] % bucket)
+ return
+ else:
+ raise
+
+ # objects in the current scope:
+ for obj in response["list"]:
+ bucket_size += int(obj["Size"])
+
+ # directories found in current scope:
+ for obj in response["common_prefixes"]:
+ dirs.append(obj["Prefix"])
+
total_size, size_coeff = formatSize(bucket_size, Config().human_readable_sizes)
total_size_str = str(total_size) + size_coeff
output(u"%s %s" % (total_size_str.ljust(8), uri))
Please sign in to comment.
Something went wrong with that request. Please try again.