@@ -242,21 +242,13 @@ def give_permission(filename):
242242 except subprocess .CalledProcessError :
243243 pass
244244
245- def check_file_tape (fileNcdf , abort = False ):
245+ def check_file_tape (fileNcdf ):
246246 """
247- For use in the NAS environnment only.
248- Checks whether a file is exists on the disk by running the command
249- ``dmls -l`` on NAS. This prevents the program from stalling if the
250- files need to be migrated from the disk to the tape.
251-
247+ Checks whether a file exists on the disk. If on a NAS system,
248+ also checks if the file needs to be migrated from tape.
249+
252250 :param fileNcdf: full path to a netcdf file or a file object with a name attribute
253251 :type fileNcdf: str or file object
254-
255- :param abort: If True, exit the program. Defaults to False
256- :type abort: bool, optional
257-
258- :return: None
259-
260252 """
261253 # Get the filename, whether passed as string or as file object
262254 filename = fileNcdf if isinstance (fileNcdf , str ) else fileNcdf .name
@@ -265,42 +257,58 @@ def check_file_tape(fileNcdf, abort=False):
265257 if not re .search (".nc" , filename ):
266258 print (f"{ Red } { filename } is not a netCDF file{ Nclr } " )
267259 exit ()
268-
269- try :
270- # Check if the file exists on the disk, exit otherwise. If it
271- # exists, copy it over from the disk.
272- # Check if dmls command is available
273- subprocess .check_call (["dmls" ], shell = True ,
274- stdout = open (os .devnull , "w" ),
275- stderr = open (os .devnull , "w" ))
276- # Get the last columns of the ls command (filename and status)
277- cmd_txt = f"dmls -l { filename } | awk '{{print $8,$9}}'"
278- # Get 3-letter identifier from dmls -l command, convert byte to
279- # string for Python3
280- dmls_out = subprocess .check_output (cmd_txt ,
281- shell = True ).decode ("utf-8" )
282- if dmls_out [1 :4 ] not in ["DUL" , "REG" , "MIG" ]:
283- # If file is OFFLINE, UNMIGRATING etc...
284- if abort :
285- print (f"{ Red } *** Error ***\n { dmls_out } \n { dmls_out [6 :- 1 ]} "
286- f"is not available on disk, status is: { dmls_out [0 :5 ]} "
287- f"CHECK file status with ``dmls -l *.nc`` and run "
288- f"``dmget *.nc`` to migrate the files.\n Exiting now..."
260+
261+ # First check if the file exists at all
262+ if not os .path .isfile (filename ):
263+ print (f"{ Red } File { filename } does not exist{ Nclr } " )
264+ exit ()
265+
266+ # Check if we're on a NAS system by looking for specific environment variables
267+ # or filesystem paths that are unique to NAS
268+ is_nas = False
269+
270+ # Method 1: Check for NAS-specific environment variables
271+ nas_env_vars = ['PBS_JOBID' , 'SGE_ROOT' , 'NOBACKUP' , 'NASA_ROOT' ]
272+ for var in nas_env_vars :
273+ if var in os .environ :
274+ is_nas = True
275+ break
276+
277+ # Method 2: Check for NAS-specific directories
278+ nas_paths = ['/nobackup' , '/nobackupp' , '/u/scicon' ]
279+ for path in nas_paths :
280+ if os .path .exists (path ):
281+ is_nas = True
282+ break
283+
284+ # Only perform NAS-specific operations if we're on a NAS system
285+ if is_nas :
286+ try :
287+ # Check if dmls command is available
288+ subprocess .check_call (["dmls" ], shell = True ,
289+ stdout = open (os .devnull , "w" ),
290+ stderr = open (os .devnull , "w" ))
291+
292+ # Get the last columns of the ls command (filename and status)
293+ cmd_txt = f"dmls -l { filename } | awk '{{print $8,$9}}'"
294+
295+ # Get identifier from dmls -l command
296+ dmls_out = subprocess .check_output (cmd_txt , shell = True ).decode ("utf-8" )
297+
298+ if dmls_out [1 :4 ] not in ["DUL" , "REG" , "MIG" ]:
299+ # If file is OFFLINE, UNMIGRATING etc...
300+ print (f"{ Yellow } *** Warning ***\n { dmls_out [6 :- 1 ]} "
301+ f"is not loaded on disk (Status: { dmls_out [0 :5 ]} ). "
302+ f"Please migrate it to disk with:\n "
303+ f"``dmget { dmls_out [6 :- 1 ]} ``\n then try again."
289304 f"\n { Nclr } " )
290305 exit ()
291- else :
292- print (f"{ Yellow } *** Warning ***\n { dmls_out [6 :- 1 ]} is not "
293- f"available on the disk. Status: { dmls_out [0 :5 ]} .\n "
294- f"Consider checking file status with ``dmls -l *.nc`` "
295- f"and run ``dmget *.nc`` to migrate the files.\n "
296- f"Waiting for file to be migrated to the disk, this "
297- f"may take awhile..." )
298- except subprocess .CalledProcessError :
299- # Return an eror message
300- if abort :
301- exit ()
302- else :
306+ except (subprocess .CalledProcessError , FileNotFoundError , IndexError ):
307+ # If there's any issue with the dmls command, log it but continue
308+ if "--debug" in sys .argv :
309+ print (f"{ Yellow } Warning: Could not check tape status for { filename } { Nclr } " )
303310 pass
311+ # Otherwise, we're not on a NAS system, so just continue
304312
305313
306314def get_Ncdf_path (fNcdf ):
0 commit comments