Skip to content

Commit

Permalink
Merge pull request #1874 from UV-CDAT/issue_1867
Browse files Browse the repository at this point in the history
uri starting with file:// were not interpreted correctly
  • Loading branch information
aashish24 committed Mar 17, 2016
2 parents 96acdc8 + 5482dac commit 65ca26c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
9 changes: 6 additions & 3 deletions Packages/cdms2/Lib/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,12 @@ def openDataset(uri,mode='r',template=None,dods=1,dpath=None, hostObj=None):
uri = string.strip(uri)
(scheme,netloc,path,parameters,query,fragment)=urlparse.urlparse(uri)
if scheme in ('','file'):
if uri[:7].lower() == "file://":
path = uri[7:]
if netloc:
# In case of relative path...
path = netloc + path
path = os.path.expanduser(path)
path = os.path.normpath(os.path.join(os.getcwd(), path))

root,ext = os.path.splitext(path)
if ext in ['.xml','.cdml']:
if mode!='r': raise ModeNotSupported(mode)
Expand Down Expand Up @@ -973,7 +976,7 @@ def __init__(self, path, mode, hostObj = None, mpiBarrier=False):
if "://" in path:
self.uri = path
else:
self.uri = "file://" + path
self.uri = "file://" + os.path.abspath(os.path.expanduser(path))
self._mode_ = mode
try:
if mode[0].lower()=="w":
Expand Down
3 changes: 3 additions & 0 deletions testing/cdms2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ cdat_add_test("test_dim_unlimited"
${cdat_SOURCE_DIR}/testing/cdms2/test_dim_unlimited.py
TestCDATLite)
if (CDAT_DOWNLOAD_SAMPLE_DATA)
cdat_add_test("CDMS_test_cdms_file_in_uri"
"${PYTHON_EXECUTABLE}"
${cdat_SOURCE_DIR}/testing/cdms2/test_cdms_file_in_uri.py)
cdat_add_test("CDMS_Test_Zonal_regrid_Switch_to_Regrid2"
"${PYTHON_EXECUTABLE}"
${cdat_SOURCE_DIR}/testing/cdms2/test_regrid_zonal_switch_to_regrid2.py)
Expand Down
7 changes: 7 additions & 0 deletions testing/cdms2/test_cdms_file_in_uri.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import cdms2
import cdat_info
import os

pth = os.path.join(cdat_info.get_sampledata_path(),"clt.nc")

f=cdms2.open("file://"+pth)

0 comments on commit 65ca26c

Please sign in to comment.