Repository: ESMCI/cime

Issue:
If stream filename is full path use it to set filepath
Related to issue #1903 

./create_newcase --case ../../cases/QPC6_c201_userSSTtest --compset QPC6 --res f09_f09_mg17 --project UMAI0021 --run-unsupported
cd ../../cases/QPC6_c201_userSSTtest/
./case.setup
./xmlchange DOCN_MODE="sst_aquapfile"
./xmlchange DOCN_AQP_FILENAME="/glade/u/home/benedict/ys/datain/SST_ICE_zonalAsymQOBS_fv0.9x1.25_allSeas_clim_1982-2011.nc"

~ ~ ~ The error:  Even before building, you can run ./preview_namelists to set the inputs in $CASEROOT/CaseDocs.  When you do this, you can see a problem in file $CASEROOT/CaseDocs/docn.streams.txt.aquapfile:
<filePath> /glade/p/cesmdata/cseg/inputdata/ocn/docn7/AQUAPLANET/
<fileNames> /glade/u/home/benedict/ys/datain/SST_ICE_zonalAsymQOBS_fv0.9x1.25_allSeas_clim_1982-2011.nc



Discussion:

Resolving patch:
diff --git a/scripts/lib/CIME/Servers/ftp.py b/scripts/lib/CIME/Servers/ftp.py
--- a/scripts/lib/CIME/Servers/ftp.py
+++ b/scripts/lib/CIME/Servers/ftp.py
@@ -7,6 +7,7 @@
 from ftplib import FTP as FTPpy
 from ftplib import all_errors as all_ftp_errors
 
+
 logger = logging.getLogger(__name__)
 # I think that multiple inheritence would be useful here, but I couldnt make it work
 # in a py2/3 compatible way.
@@ -50,6 +51,8 @@ def getfile(self, rel_path, full_path):
         try:
             stat = self.ftp.retrbinary('RETR {}'.format(rel_path), open(full_path, "wb").write)
         except all_ftp_errors:
+            if os.path.isfile(full_path):
+                os.remove(full_path)
             logger.warning("ERROR from ftp server, trying next server")
             return False
 
diff --git a/scripts/lib/CIME/case/check_input_data.py b/scripts/lib/CIME/case/check_input_data.py
--- a/scripts/lib/CIME/case/check_input_data.py
+++ b/scripts/lib/CIME/case/check_input_data.py
@@ -6,7 +6,7 @@
 from CIME.XML.inputdata import Inputdata
 import CIME.Servers
 
-import glob, hashlib
+import glob, hashlib, shutil
 
 logger = logging.getLogger(__name__)
 # The inputdata_checksum.dat file will be read into this hash if it's available
@@ -132,7 +132,10 @@ def _download_if_in_repo(server, input_data_root, rel_path, isdirectory=False):
             # this is intended to prevent a race condition in which
             # one case attempts to use a refdir before another one has
             # completed the download
-            os.rename(full_path+".tmp",full_path)
+            if success:
+                os.rename(full_path+".tmp",full_path)
+            else:
+                shutil.rmtree(full_path+".tmp")
         else:
             success = server.getfile(rel_path, full_path)
     return success
@@ -354,8 +357,8 @@ def verify_chksum(input_data_root, rundir, filename, isdirectory):
     For file in filename perform a chksum and compare the result to that stored in
     the local checksumfile, if isdirectory chksum all files in the directory of form *.*
     """
+    hashfile = os.path.join(rundir, local_chksum_file)
     if not chksum_hash:
-        hashfile = os.path.join(rundir, local_chksum_file)
         if not os.path.isfile(hashfile):
             expect(False, "Failed to find or download file {}".format(hashfile))
 
diff --git a/scripts/lib/CIME/nmlgen.py b/scripts/lib/CIME/nmlgen.py
--- a/scripts/lib/CIME/nmlgen.py
+++ b/scripts/lib/CIME/nmlgen.py
@@ -474,7 +474,9 @@ def create_stream_file_and_update_shr_strdata_nml(self, config, #pylint:disable=
             for i, filename in enumerate(domain_filenames.split("\n")):
                 if filename.strip() == '':
                     continue
-                filepath = os.path.join(domain_filepath, filename.strip())
+                filepath, filename = os.path.split(filename)
+                if not filepath:
+                    filepath = os.path.join(domain_filepath, os.path.dirname(filename.strip()))
                 string = "domain{:d} = {}\n".format(i+1, filepath)
                 hashValue = hashlib.md5(string.rstrip().encode('utf-8')).hexdigest()
                 if hashValue not in lines_hash:


Test patch: