Skip to content

Commit

Permalink
Merge changes of release 2.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
fviard committed Jul 22, 2018
2 parents 4801552 + 16bec96 commit ae6a635
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 20 deletions.
11 changes: 6 additions & 5 deletions S3/Config.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,14 @@ def role_config(self):
resp = conn.getresponse()
files = resp.read()
if resp.status == 200 and len(files)>1:
conn.request('GET', "/latest/meta-data/iam/security-credentials/%s"%files.decode('UTF-8'))
conn.request('GET', "/latest/meta-data/iam/security-credentials/%s" % files.decode('utf-8'))
resp=conn.getresponse()
if resp.status == 200:
creds=json.load(resp)
Config().update_option('access_key', creds['AccessKeyId'].encode('ascii'))
Config().update_option('secret_key', creds['SecretAccessKey'].encode('ascii'))
Config().update_option('access_token', creds['Token'].encode('ascii'))
resp_content = config_unicodise(resp.read())
creds=json.loads(resp_content)
Config().update_option('access_key', config_unicodise(creds['AccessKeyId']))
Config().update_option('secret_key', config_unicodise(creds['SecretAccessKey']))
Config().update_option('access_token', config_unicodise(creds['Token']))
else:
raise IOError
else:
Expand Down
4 changes: 2 additions & 2 deletions S3/Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,12 @@ def dateRFC822toUnix(date):
def formatSize(size, human_readable = False, floating_point = False):
size = floating_point and float(size) or int(size)
if human_readable:
coeffs = ['k', 'M', 'G', 'T']
coeffs = ['K', 'M', 'G', 'T']
coeff = ""
while size > 2048:
size /= 1024
coeff = coeffs.pop(0)
return (size, coeff)
return (floating_point and float(size) or int(size), coeff)
else:
return (size, "")
__all__.append("formatSize")
Expand Down
38 changes: 25 additions & 13 deletions s3cmd
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ def subcmd_bucket_usage_all(s3):
buckets_size += size
total_size, size_coeff = formatSize(buckets_size, cfg.human_readable_sizes)
total_size_str = str(total_size) + size_coeff
output(u"".rjust(8, "-"))
output(u"%s Total" % (total_size_str.ljust(8)))
output(u"".rjust(12, "-"))
output(u"%s Total" % (total_size_str.ljust(12)))
return size

def subcmd_bucket_usage(s3, uri):
Expand Down Expand Up @@ -131,9 +131,14 @@ def subcmd_bucket_usage(s3, uri):
except KeyboardInterrupt as e:
extra_info = u' [interrupted]'

total_size, size_coeff = formatSize(bucket_size, Config().human_readable_sizes)
total_size_str = str(total_size) + size_coeff
output(u"%s %s objects %s%s" % (total_size_str.ljust(8), object_count, uri, extra_info))
total_size_str = u"%d%s" % formatSize(bucket_size,
Config().human_readable_sizes)
if Config().human_readable_sizes:
total_size_str = total_size_str.rjust(5)
else:
total_size_str = total_size_str.rjust(12)
output(u"%s %7s objects %s%s" % (total_size_str, object_count, uri,
extra_info))
return bucket_size

def cmd_ls(args):
Expand Down Expand Up @@ -184,18 +189,25 @@ def subcmd_bucket_list(s3, uri, limit):
error(S3.codes[e.info["Code"]] % bucket)
raise

# md5 are 32 char long, but for multipart there could be a suffix
if Config().human_readable_sizes:
# %(size)5s%(coeff)1s
format_size = u"%5d%1s"
dir_str = u"DIR".rjust(6)
else:
format_size = u"%12d%s"
dir_str = u"DIR".rjust(12)
if cfg.long_listing:
format_string = u"%(timestamp)16s %(size)9s%(coeff)1s %(md5)32s %(storageclass)s %(uri)s"
format_string = u"%(timestamp)16s %(size)s %(md5)-35s %(storageclass)-11s %(uri)s"
elif cfg.list_md5:
format_string = u"%(timestamp)16s %(size)9s%(coeff)1s %(md5)32s %(uri)s"
format_string = u"%(timestamp)16s %(size)s %(md5)-35s %(uri)s"
else:
format_string = u"%(timestamp)16s %(size)9s%(coeff)1s %(uri)s"
format_string = u"%(timestamp)16s %(size)s %(uri)s"

for prefix in response['common_prefixes']:
output(format_string % {
"timestamp": "",
"size": "DIR",
"coeff": "",
"size": dir_str,
"md5": "",
"storageclass": "",
"uri": uri.compose_uri(bucket, prefix["Prefix"])})
Expand All @@ -213,11 +225,11 @@ def subcmd_bucket_list(s3, uri, limit):
except KeyError:
pass

size, size_coeff = formatSize(object["Size"], Config().human_readable_sizes)
size_and_coeff = formatSize(object["Size"],
Config().human_readable_sizes)
output(format_string % {
"timestamp": formatDateTime(object["LastModified"]),
"size" : str(size),
"coeff": size_coeff,
"size" : format_size % size_and_coeff,
"md5" : md5,
"storageclass" : storageclass,
"uri": uri.compose_uri(bucket, object["Key"]),
Expand Down

0 comments on commit ae6a635

Please sign in to comment.