Skip to content
This repository has been archived by the owner on Nov 4, 2018. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'manos/master' into manos-merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Domsch authored and Matt Domsch committed Jul 14, 2012
2 parents 1e63679 + cf2bdf3 commit 352e33b
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions s3cmd
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -67,18 +67,28 @@ def subcmd_bucket_usage(s3, uri):


if object.endswith('*'): if object.endswith('*'):
object = object[:-1] 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 bucket_size = 0
for object in response["list"]: # iterate and store directories to traverse, while summing objects:
size, size_coeff = formatSize(object["Size"], False) dirs = [object]
bucket_size += size 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, size_coeff = formatSize(bucket_size, Config().human_readable_sizes)
total_size_str = str(total_size) + size_coeff total_size_str = str(total_size) + size_coeff
output(u"%s %s" % (total_size_str.ljust(8), uri)) output(u"%s %s" % (total_size_str.ljust(8), uri))
Expand Down

0 comments on commit 352e33b

Please sign in to comment.