Skip to content

Commit

Permalink
Refactored file existence checks to use pathlib.
Browse files Browse the repository at this point in the history
  • Loading branch information
kripnerl committed Oct 27, 2023
1 parent da4d0be commit 46512ab
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 3 additions & 3 deletions omas/omas_mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
3 changes: 2 additions & 1 deletion omas/tests/failed_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 46512ab

Please sign in to comment.