lookyloo/tools/check_s3fs_entry.py

30 lines
979 B
Python
Raw Permalink Normal View History

#!/usr/bin/env python3
import argparse
import json
import logging
2023-11-24 13:49:50 +01:00
import s3fs # type: ignore
from lookyloo.default import get_config
2024-01-12 17:15:41 +01:00
def check_path(path: str) -> dict[str, str]:
s3fs_config = get_config('generic', 's3fs')
s3fs_client = s3fs.S3FileSystem(key=s3fs_config['config']['key'],
secret=s3fs_config['config']['secret'],
endpoint_url=s3fs_config['config']['endpoint_url'])
s3fs_bucket = s3fs_config['config']['bucket_name']
return s3fs_client.info(f'{s3fs_bucket}/{path}')
if __name__ == '__main__':
logger = logging.getLogger('Lookyloo - S3FS checker')
parser = argparse.ArgumentParser(description='Check the status of a file/directory on s3fs.')
parser.add_argument('--path', help='The path to check on s3fs. Should always start with Year/Month.')
args = parser.parse_args()
path_info = check_path(args.path)
print(json.dumps(path_info, indent=2))