From 46512abc32c3d38e4c78d806edf0b5761ac686de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kripner?= Date: Fri, 27 Oct 2023 15:53:43 +0200 Subject: [PATCH] Refactored file existence checks to use pathlib. --- omas/omas_mongo.py | 6 +++--- omas/tests/failed_imports.py | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/omas/omas_mongo.py b/omas/omas_mongo.py index 68aee448..83a2d863 100644 --- a/omas/omas_mongo.py +++ b/omas/omas_mongo.py @@ -155,9 +155,9 @@ def get_mongo_credentials(server='', database='', collection=''): server = server.split('@')[-1] up = {'user': 'omas_test', 'pass': 'omas_test'} config = {} - filename = pathlib.Path.home() / '/.omas/mongo_credentials' - if os.path.exists(filename): - with open(filename) as f: + filepath = pathlib.Path.home() / '/.omas/mongo_credentials' + if filepath.exists(): + with open(filepath) as f: config = json.loads(f.read()) if 'default' in config: up = config['default'] diff --git a/omas/tests/failed_imports.py b/omas/tests/failed_imports.py index 270d516e..53fbf978 100644 --- a/omas/tests/failed_imports.py +++ b/omas/tests/failed_imports.py @@ -42,7 +42,8 @@ from botocore.exceptions import NoCredentialsError import boto3 - if not os.path.exists(os.environ.get('AWS_CONFIG_FILE', pathlib.Path.home() + '/.aws/config')): + aws_confi_path = pathlib.Path(os.environ.get('AWS_CONFIG_FILE', pathlib.Path.home() / '/.aws/config')) + if not aws_confi_path.exists(): raise RuntimeError('Missing AWS configuration file ~/.aws/config') failed_S3 = False except (ImportError, RuntimeError, NoCredentialsError) as _excp: