... | ... |
@@ -260,13 +260,14 @@ class Config(object): |
260 | 260 |
resp = conn.getresponse() |
261 | 261 |
files = resp.read() |
262 | 262 |
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')) |
|
264 | 264 |
resp=conn.getresponse() |
265 | 265 |
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'])) |
|
270 | 271 |
else: |
271 | 272 |
raise IOError |
272 | 273 |
else: |
... | ... |
@@ -194,12 +194,12 @@ __all__.append("dateRFC822toUnix") |
194 | 194 |
def formatSize(size, human_readable = False, floating_point = False): |
195 | 195 |
size = floating_point and float(size) or int(size) |
196 | 196 |
if human_readable: |
197 |
- coeffs = ['k', 'M', 'G', 'T'] |
|
197 |
+ coeffs = ['K', 'M', 'G', 'T'] |
|
198 | 198 |
coeff = "" |
199 | 199 |
while size > 2048: |
200 | 200 |
size /= 1024 |
201 | 201 |
coeff = coeffs.pop(0) |
202 |
- return (size, coeff) |
|
202 |
+ return (floating_point and float(size) or int(size), coeff) |
|
203 | 203 |
else: |
204 | 204 |
return (size, "") |
205 | 205 |
__all__.append("formatSize") |
... | ... |
@@ -102,8 +102,8 @@ def subcmd_bucket_usage_all(s3): |
102 | 102 |
buckets_size += size |
103 | 103 |
total_size, size_coeff = formatSize(buckets_size, cfg.human_readable_sizes) |
104 | 104 |
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))) |
|
107 | 107 |
return size |
108 | 108 |
|
109 | 109 |
def subcmd_bucket_usage(s3, uri): |
... | ... |
@@ -131,9 +131,14 @@ def subcmd_bucket_usage(s3, uri): |
131 | 131 |
except KeyboardInterrupt as e: |
132 | 132 |
extra_info = u' [interrupted]' |
133 | 133 |
|
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)) |
|
137 | 142 |
return bucket_size |
138 | 143 |
|
139 | 144 |
def cmd_ls(args): |
... | ... |
@@ -184,18 +189,25 @@ def subcmd_bucket_list(s3, uri, limit): |
184 | 184 |
error(S3.codes[e.info["Code"]] % bucket) |
185 | 185 |
raise |
186 | 186 |
|
187 |
+ # md5 are 32 char long, but for multipart there could be a suffix |
|
188 |
+ if Config().human_readable_sizes: |
|
189 |
+ # %(size)5s%(coeff)1s |
|
190 |
+ format_size = u"%5d%1s" |
|
191 |
+ dir_str = u"DIR".rjust(6) |
|
192 |
+ else: |
|
193 |
+ format_size = u"%12d%s" |
|
194 |
+ dir_str = u"DIR".rjust(12) |
|
187 | 195 |
if cfg.long_listing: |
188 |
- format_string = u"%(timestamp)16s %(size)9s%(coeff)1s %(md5)32s %(storageclass)s %(uri)s" |
|
196 |
+ format_string = u"%(timestamp)16s %(size)s %(md5)-35s %(storageclass)-11s %(uri)s" |
|
189 | 197 |
elif cfg.list_md5: |
190 |
- format_string = u"%(timestamp)16s %(size)9s%(coeff)1s %(md5)32s %(uri)s" |
|
198 |
+ format_string = u"%(timestamp)16s %(size)s %(md5)-35s %(uri)s" |
|
191 | 199 |
else: |
192 |
- format_string = u"%(timestamp)16s %(size)9s%(coeff)1s %(uri)s" |
|
200 |
+ format_string = u"%(timestamp)16s %(size)s %(uri)s" |
|
193 | 201 |
|
194 | 202 |
for prefix in response['common_prefixes']: |
195 | 203 |
output(format_string % { |
196 | 204 |
"timestamp": "", |
197 |
- "size": "DIR", |
|
198 |
- "coeff": "", |
|
205 |
+ "size": dir_str, |
|
199 | 206 |
"md5": "", |
200 | 207 |
"storageclass": "", |
201 | 208 |
"uri": uri.compose_uri(bucket, prefix["Prefix"])}) |
... | ... |
@@ -213,11 +225,11 @@ def subcmd_bucket_list(s3, uri, limit): |
213 | 213 |
except KeyError: |
214 | 214 |
pass |
215 | 215 |
|
216 |
- size, size_coeff = formatSize(object["Size"], Config().human_readable_sizes) |
|
216 |
+ size_and_coeff = formatSize(object["Size"], |
|
217 |
+ Config().human_readable_sizes) |
|
217 | 218 |
output(format_string % { |
218 | 219 |
"timestamp": formatDateTime(object["LastModified"]), |
219 |
- "size" : str(size), |
|
220 |
- "coeff": size_coeff, |
|
220 |
+ "size" : format_size % size_and_coeff, |
|
221 | 221 |
"md5" : md5, |
222 | 222 |
"storageclass" : storageclass, |
223 | 223 |
"uri": uri.compose_uri(bucket, object["Key"]), |