Skip to content

Commit 883618c

Browse files
authored
[CLI] Fix storage list error (#1431)
* Fix data retrieval from objects in list_bucket()
1 parent ceebd0f commit 883618c

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

lithops/scripts/cli.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -382,17 +382,21 @@ def list_bucket(prefix, bucket, backend, debug, config):
382382
logger.info('Listing objects in bucket {}'.format(bucket))
383383
objects = storage.list_objects(bucket, prefix=prefix)
384384

385-
objs = []
386-
for obj in objects:
387-
key = obj['Key']
388-
date = obj['LastModified'].strftime("%b %d %Y %H:%M:%S")
389-
size = sizeof_fmt(obj['Size'])
390-
objs.append([key, date, size])
391-
392-
headers = ['Key', 'Last modified', 'Size']
393-
print()
394-
print(tabulate(objs, headers=headers))
395-
print(f'\nTotal objects: {len(objs)}')
385+
objs = [
386+
{
387+
key: obj[key].strftime("%b %d %Y %H:%M:%S") if key == 'LastModified' else sizeof_fmt(obj[key]) if key == 'Size' else obj[key]
388+
for key in ('Key', 'LastModified', 'Size')
389+
if key in obj
390+
}
391+
for obj in objects
392+
]
393+
394+
if objs[0]:
395+
print()
396+
print(tabulate(objs, headers="keys"))
397+
print(f'\nTotal objects: {len(objs)}')
398+
else:
399+
print(f'\nNo information can be listed from bucket \"{bucket}\" using current \"{storage.backend}\" backend')
396400

397401

398402
# /---------------------------------------------------------------------------/

0 commit comments

Comments
 (0)