Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse NCI filepaths to THREDDS location #523

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions cubedash/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,16 @@ def as_external_url(
>>> # Converts s3 to http
>>> as_external_url('s3://some-data/L2/S2A_OPER_MSI_ARD__A030100_T56LNQ_N02.09/ARD-METADATA.yaml', "ap-southeast-2")
'https://some-data.s3.ap-southeast-2.amazonaws.com/L2/S2A_OPER_MSI_ARD__A030100_T56LNQ_N02.09/ARD-METADATA.yaml'
>>> # Other URLs are left as-is
>>> unconvertable_url = 'file:///g/data/xu18/ga_ls8c_ard_3-1-0_095073_2019-03-22_final.odc-metadata.yaml'
>>> unconvertable_url == as_external_url(unconvertable_url)
True
>>> # Converts NCI filepaths to THREDDS location
>>> as_external_url('file:///g/data/xu18/ga_ls8c_ard_3-1-0_095073_2019-03-22_final.odc-metadata.yaml')
'https://dapds00.nci.org.au/thredds/fileServer/xu18/ga_ls8c_ard_3-1-0_095073_2019-03-22_final.odc-metadata.yaml'
>>> # Leaves other urls as-is
>>> as_external_url('some/relative/path.txt')
'some/relative/path.txt'
>>> # if base uri was none, we may want to return the s3 location instead of the metadata yaml
"""
parsed = urlparse(url)
print(parsed)

if s3_region and parsed.scheme == "s3":
# get buckets for which link should be to data location instead of s3 link
Expand All @@ -179,6 +180,12 @@ def as_external_url(

return f"https://{parsed.netloc}.s3.{s3_region}.amazonaws.com{parsed.path}"

if parsed.scheme == "file":
path = parsed.path.replace("/g/data/", "")
if path.find("/ga") != -1:
path = path.replace("/ga/", "/")
return f"https://dapds00.nci.org.au/thredds/fileServer/{path}"

return url


Expand Down