diff --git a/tsshbatch.py b/tsshbatch.py index 965deb8..f6ca8c5 100755 --- a/tsshbatch.py +++ b/tsshbatch.py @@ -20,7 +20,7 @@ CMDINCL = PROGENV + "CMDS" HOSTINCL = PROGENV + "HOSTS" -CVSID = "$Id: tsshbatch.py,v 1.165 2013/10/28 22:49:30 tundra Exp $" +CVSID = "$Id: tsshbatch.py,v 1.166 2013/10/29 00:03:53 tundra Exp $" VERSION = CVSID.split()[2] CPRT = "(c)" DATE = "2011-2013" @@ -410,14 +410,10 @@ # Check to see if we can find the file, searching the # the relevant include environment variable path, if any - matches = tsearchpath(fname, envvar) - if not matches: + filename = SearchPath(fname, envvar) + if not filename: ErrorExit(eBADFILE % fname) - # We always attempt to open the first match found in the path - else: - filename = matches[0] - # Make sure we don't have a cyclic include reference if filename in FileIncludeStack: @@ -477,35 +473,37 @@ ##### -# Search A Path For A File, Returning All Possible Matches +# Search A Path For A File, Returning First Match ##### -def tsearchpath(filename, pathlist, delimiter=PATHDELIM): +def SearchPath(filename, pathlist, delimiter=PATHDELIM): # What we'll return if we find nothing - retval = [] + retval = "" # Handle fully qualified filenames + # But ignore this, if its a directory with a matching name - if os.path.exists(filename): - retval.append(os.path.realpath(filename)) + if os.path.exists(filename) and os.path.isfile(filename): + retval = os.path.realpath(filename) - # Find all instances of filename in specified paths - - paths = pathlist.split(delimiter) - for path in paths: + # Find first instance along specified path if one has been specified + elif pathlist: - if path and path[-1] != PATHSEP: - path += PATHSEP + paths = pathlist.split(delimiter) + for path in paths: - path += filename + if path and path[-1] != PATHSEP: + path += PATHSEP - if os.path.exists(path): - retval.append(os.path.realpath(path)) + path += filename + if os.path.exists(path): + retval = os.path.realpath(path) + break return retval -# End of 'tsearchpath()' +# End of 'SearchPath()' # ---------------------- Program Entry Point ---------------------- #