Skip to content

Commit

Permalink
Allow both string and Path objects
Browse files Browse the repository at this point in the history
  • Loading branch information
israelmcmc committed Mar 12, 2024
1 parent 815376b commit 17ff708
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions cosipy/util/data_fetching.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
from awscli.clidriver import create_clidriver
from pathlib import Path

def fetch_wasabi_file(file,
output = None,
Expand Down Expand Up @@ -31,16 +32,19 @@ def fetch_wasabi_file(file,
if output is None:
output = file.split('/')[-1]

if os.path.exists(output) and not override:
output = Path(output)

if output.exists() and not override:
raise RuntimeError(f"File {output} already exists.")

cli = create_clidriver()

cli.session.set_credentials(access_key, secret_key)

cli.main(['s3api', 'get-object',
'--bucket', bucket,
'--key', file,
'--endpoint-url', endpoint,
output])
command = ['s3api', 'get-object',
'--bucket', bucket,
'--key', file,
'--endpoint-url', endpoint,
str(output)]

cli.main(command)

0 comments on commit 17ff708

Please sign in to comment.