diff --git a/tren.py b/tren.py index 0c889b2..cfa2d5c 100755 --- a/tren.py +++ b/tren.py @@ -8,7 +8,8 @@ PROGNAME = "tren.py" BASENAME = PROGNAME.split(".py")[0] PROGENV = BASENAME.upper() -RCSID = "$Id: tren.py,v 1.217 2010/04/07 18:36:55 tundra Exp $" +INCLENV = PROGENV + "INCL" +RCSID = "$Id: tren.py,v 1.218 2010/06/25 22:39:46 tundra Exp $" VERSION = RCSID.split()[2] # Copyright Information @@ -64,9 +65,12 @@ elif OSNAME == 'posix': POSIX = True -# If we're on Win32, try to load win32all stuff if it's available - +# Set up Windows-specific stuff + if WINDOWS: + + # Try to load win32all stuff if it's available + try: from win32api import GetFileAttributes, GetComputerName import win32con @@ -79,13 +83,18 @@ except: WIN32ALL = False - -# Get Unix password and group features +# Set up Unix-specific stuff elif POSIX: + + # Get Unix password and group features + import grp import pwd + +# Uh oh, this is not an OS we know about + else: sys.stderr.write("Unsupported Operating System! Aborting ...\n") sys.exit(1) @@ -102,7 +111,6 @@ #----------------------------------------------------------# - ##### # General Program Constants ##### @@ -156,6 +164,9 @@ NULLRENSEP = "Old/New separator string" # Cannot be null NULLSUFFIX = "Forced renaming suffix string" # Cannot be null OPTINTRO = "-" # Option introducer +PATHDELUNIX = ":" # Separates include path elements on Unix systems +PATHDELWIN = ";" # Separates include path elements on Windows systems +PATHSEP = os.path.sep # File path separator character RANGESEP = ":" # Separator for instance ranges SINGLEINST = "SINGLEINST" # Indicates a single, not range, replacement instance WINDOWSGROUP = "WindowsGroup" # Returned on Windows w/o win32all @@ -1842,6 +1853,15 @@ # Read the included file, stripping out comments + # Use include path if one was provided + + inclpath = os.getenv(INCLENV) + if inclpath: + + found = searchpath(inclfile, inclpath, PATHDEL) + if found: + inclfile = found[0] + try: n = [] f = open(inclfile) @@ -1876,6 +1896,35 @@ ##### +# Search Path Looking For Include File +##### + +def searchpath(filename, pathlist, pathdelim): + + # What we'll return if we find nothing + + retval = [] + + # Find all instances of filename in specified paths + + paths = pathlist.split(pathdelim) + + for path in paths: + + if path and path[-1] != PATHSEP: + path += PATHSEP + + path += filename + + if os.path.exists(path): + retval.append(os.path.realpath(path)) + + return retval + +# End of 'searchpath()' + + +##### # Print Usage Information ##### @@ -1890,6 +1939,16 @@ # Program Entry Point # #----------------------------------------------------------# +# Set up proper include path separator + + +if WINDOWS: + PATHDEL = PATHDELWIN + +else: + PATHDEL = PATHDELUNIX + + ##### # Command Line Preprocessing #