From cca99eace79aaef9d754c3ca32eac5743c45f003 Mon Sep 17 00:00:00 2001 From: acanadil Date: Mon, 12 May 2025 11:07:43 +0200 Subject: [PATCH 1/2] Fix data retrieval from objects in list_bucket() --- lithops/scripts/cli.py | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/lithops/scripts/cli.py b/lithops/scripts/cli.py index f9cfbc242..d23849271 100644 --- a/lithops/scripts/cli.py +++ b/lithops/scripts/cli.py @@ -382,17 +382,22 @@ def list_bucket(prefix, bucket, backend, debug, config): logger.info('Listing objects in bucket {}'.format(bucket)) objects = storage.list_objects(bucket, prefix=prefix) - objs = [] - for obj in objects: - key = obj['Key'] - date = obj['LastModified'].strftime("%b %d %Y %H:%M:%S") - size = sizeof_fmt(obj['Size']) - objs.append([key, date, size]) - - headers = ['Key', 'Last modified', 'Size'] - print() - print(tabulate(objs, headers=headers)) - print(f'\nTotal objects: {len(objs)}') + objs = [ + { + key: obj[key].strftime("%b %d %Y %H:%M:%S") if key == 'LastModified' else + sizeof_fmt(obj[key]) if key == 'Size' else + obj[key] + for key in ('Key', 'LastModified', 'Size') if key in obj + } + for obj in objects + ] + + if objs[0]: + print() + print(tabulate(objs, headers="keys")) + print(f'\nTotal objects: {len(objs)}') + else: + print(f'\nNo information can be listed from bucket \"{bucket}\" using current \"{storage.backend}\" backend') # /---------------------------------------------------------------------------/ From 3817e639d35928f5bd80526afcb1b1389089e474 Mon Sep 17 00:00:00 2001 From: acanadil Date: Mon, 12 May 2025 16:56:32 +0200 Subject: [PATCH 2/2] Fix linting --- lithops/scripts/cli.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lithops/scripts/cli.py b/lithops/scripts/cli.py index d23849271..7af456ebc 100644 --- a/lithops/scripts/cli.py +++ b/lithops/scripts/cli.py @@ -384,14 +384,13 @@ def list_bucket(prefix, bucket, backend, debug, config): objs = [ { - key: obj[key].strftime("%b %d %Y %H:%M:%S") if key == 'LastModified' else - sizeof_fmt(obj[key]) if key == 'Size' else - obj[key] - for key in ('Key', 'LastModified', 'Size') if key in obj + key: obj[key].strftime("%b %d %Y %H:%M:%S") if key == 'LastModified' else sizeof_fmt(obj[key]) if key == 'Size' else obj[key] + for key in ('Key', 'LastModified', 'Size') + if key in obj } for obj in objects ] - + if objs[0]: print() print(tabulate(objs, headers="keys"))