Skip to content

Commit ae6a635

Browse files
committed
Merge changes of release 2.0.2
2 parents 4801552 + 16bec96 commit ae6a635

File tree

3 files changed

+33
-20
lines changed

3 files changed

+33
-20
lines changed

S3/Config.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -260,13 +260,14 @@ def role_config(self):
260260
resp = conn.getresponse()
261261
files = resp.read()
262262
if resp.status == 200 and len(files)>1:
263-
conn.request('GET', "/latest/meta-data/iam/security-credentials/%s"%files.decode('UTF-8'))
263+
conn.request('GET', "/latest/meta-data/iam/security-credentials/%s" % files.decode('utf-8'))
264264
resp=conn.getresponse()
265265
if resp.status == 200:
266-
creds=json.load(resp)
267-
Config().update_option('access_key', creds['AccessKeyId'].encode('ascii'))
268-
Config().update_option('secret_key', creds['SecretAccessKey'].encode('ascii'))
269-
Config().update_option('access_token', creds['Token'].encode('ascii'))
266+
resp_content = config_unicodise(resp.read())
267+
creds=json.loads(resp_content)
268+
Config().update_option('access_key', config_unicodise(creds['AccessKeyId']))
269+
Config().update_option('secret_key', config_unicodise(creds['SecretAccessKey']))
270+
Config().update_option('access_token', config_unicodise(creds['Token']))
270271
else:
271272
raise IOError
272273
else:

S3/Utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,12 @@ def dateRFC822toUnix(date):
194194
def formatSize(size, human_readable = False, floating_point = False):
195195
size = floating_point and float(size) or int(size)
196196
if human_readable:
197-
coeffs = ['k', 'M', 'G', 'T']
197+
coeffs = ['K', 'M', 'G', 'T']
198198
coeff = ""
199199
while size > 2048:
200200
size /= 1024
201201
coeff = coeffs.pop(0)
202-
return (size, coeff)
202+
return (floating_point and float(size) or int(size), coeff)
203203
else:
204204
return (size, "")
205205
__all__.append("formatSize")

s3cmd

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ def subcmd_bucket_usage_all(s3):
102102
buckets_size += size
103103
total_size, size_coeff = formatSize(buckets_size, cfg.human_readable_sizes)
104104
total_size_str = str(total_size) + size_coeff
105-
output(u"".rjust(8, "-"))
106-
output(u"%s Total" % (total_size_str.ljust(8)))
105+
output(u"".rjust(12, "-"))
106+
output(u"%s Total" % (total_size_str.ljust(12)))
107107
return size
108108

109109
def subcmd_bucket_usage(s3, uri):
@@ -131,9 +131,14 @@ def subcmd_bucket_usage(s3, uri):
131131
except KeyboardInterrupt as e:
132132
extra_info = u' [interrupted]'
133133

134-
total_size, size_coeff = formatSize(bucket_size, Config().human_readable_sizes)
135-
total_size_str = str(total_size) + size_coeff
136-
output(u"%s %s objects %s%s" % (total_size_str.ljust(8), object_count, uri, extra_info))
134+
total_size_str = u"%d%s" % formatSize(bucket_size,
135+
Config().human_readable_sizes)
136+
if Config().human_readable_sizes:
137+
total_size_str = total_size_str.rjust(5)
138+
else:
139+
total_size_str = total_size_str.rjust(12)
140+
output(u"%s %7s objects %s%s" % (total_size_str, object_count, uri,
141+
extra_info))
137142
return bucket_size
138143

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

192+
# md5 are 32 char long, but for multipart there could be a suffix
193+
if Config().human_readable_sizes:
194+
# %(size)5s%(coeff)1s
195+
format_size = u"%5d%1s"
196+
dir_str = u"DIR".rjust(6)
197+
else:
198+
format_size = u"%12d%s"
199+
dir_str = u"DIR".rjust(12)
187200
if cfg.long_listing:
188-
format_string = u"%(timestamp)16s %(size)9s%(coeff)1s %(md5)32s %(storageclass)s %(uri)s"
201+
format_string = u"%(timestamp)16s %(size)s %(md5)-35s %(storageclass)-11s %(uri)s"
189202
elif cfg.list_md5:
190-
format_string = u"%(timestamp)16s %(size)9s%(coeff)1s %(md5)32s %(uri)s"
203+
format_string = u"%(timestamp)16s %(size)s %(md5)-35s %(uri)s"
191204
else:
192-
format_string = u"%(timestamp)16s %(size)9s%(coeff)1s %(uri)s"
205+
format_string = u"%(timestamp)16s %(size)s %(uri)s"
193206

194207
for prefix in response['common_prefixes']:
195208
output(format_string % {
196209
"timestamp": "",
197-
"size": "DIR",
198-
"coeff": "",
210+
"size": dir_str,
199211
"md5": "",
200212
"storageclass": "",
201213
"uri": uri.compose_uri(bucket, prefix["Prefix"])})
@@ -213,11 +225,11 @@ def subcmd_bucket_list(s3, uri, limit):
213225
except KeyError:
214226
pass
215227

216-
size, size_coeff = formatSize(object["Size"], Config().human_readable_sizes)
228+
size_and_coeff = formatSize(object["Size"],
229+
Config().human_readable_sizes)
217230
output(format_string % {
218231
"timestamp": formatDateTime(object["LastModified"]),
219-
"size" : str(size),
220-
"coeff": size_coeff,
232+
"size" : format_size % size_and_coeff,
221233
"md5" : md5,
222234
"storageclass" : storageclass,
223235
"uri": uri.compose_uri(bucket, object["Key"]),

0 commit comments

Comments
 (0)