diff --git a/tren.py b/tren.py index c301a96..cce69e5 100755 --- a/tren.py +++ b/tren.py @@ -8,7 +8,7 @@ PROGNAME = "tren.py" BASENAME = PROGNAME.split(".py")[0] PROGENV = BASENAME.upper() -RCSID = "$Id: tren.py,v 1.151 2010/02/12 18:29:38 tundra Exp $" +RCSID = "$Id: tren.py,v 1.152 2010/02/17 16:31:35 tundra Exp $" VERSION = RCSID.split()[2] # Copyright Information @@ -89,7 +89,7 @@ DEFLEN = 80 # Default output line length DEFSEP = "=" # Default rename command separator: old=new DEFSUFFIX = ".backup" # String used to rename existing targets -DEFESC = "\\" # Escape character +DEFESC = "\\" # Escape character EXT = "Ext" # Rename target is extension INCL = "I" # Include file command line option NAM = "Nam" # Rename target is name @@ -103,6 +103,7 @@ DEBUG = "DEBUG" CASESENSITIVE = "CASESENSITIVE" +ESCAPE = "ESCAPE" ERRORCONTINUE = "ERRORCONTINUE" EXISTSUFFIX = "EXISTSUFFIX" EXTDELIM = "EXTDELIM" @@ -167,6 +168,7 @@ # Error Messages ##### +eARGLENGTH = "%s must contain exactly %s character(s)!" eBADARG = "Invalid command line: %s!" eBADINCL = "option -%s requires argument" % INCL eBADNEWOLD = "Bad -r argument '%s'! Requires exactly one new, old string separator (Default: " + DEFSEP + ")" @@ -210,9 +212,9 @@ " -h Print help information", " -I file Include command line arguments from file", " -L string File extension delimiter string (Default: %s)" % DEFEXT, - " -P string Use 'string' as the escape sequence (Default: %s)" % DEFESC, + " -P char Use 'char' as the escape sequence (Default: %s)" % DEFESC, " -q Quiet mode, do not show progress", - " -R rensep Separator string for -r rename arguments (Default: %s)" % DEFSEP, + " -R char Separator character for -r rename arguments (Default: %s)" % DEFSEP, " -r old=new Replace old with new in file or directory names", " -S suffix Suffix to use when renaming existing filenames (Default: %s)" % DEFSUFFIX, " -t Test mode, don't rename, just show what the program *would* do", @@ -234,6 +236,7 @@ DEBUG : False, # Debugging off CASESENSITIVE : True, # Search is case-sensitive + ESCAPE : DEFESC, # Escape string ERRORCONTINUE : False, # Do not continue after error EXISTSUFFIX : DEFSUFFIX, # What to tack on when renaming existing targets EXTDELIM : DEFEXT, # Name/Extension delimiter @@ -456,8 +459,8 @@ ErrorMsg(eNOTHINGTODO) return - # Iterate over all the target filenames in command line order, - # applying each renaming in requested order + # Create a list of all renaming to be done. + # This includes the renaming of any existing targets. for target in self.SortViews[ORDERBYCMDLINE]: @@ -713,7 +716,7 @@ if arg[i:].startswith(oldnewsep): - if (i > 0 and (arg[i-1] != DEFESC)) or i == 0: + if (i > 0 and (arg[i-1] != ProgramOptions[ESCAPE])) or i == 0: sepindex = i numseps += 1 @@ -728,8 +731,8 @@ else: old, new = arg[:sepindex], arg[sepindex + len(oldnewsep):] - old = old.replace(DEFESC + oldnewsep, oldnewsep) - new = new.replace(DEFESC + oldnewsep, oldnewsep) + old = old.replace(ProgramOptions[ESCAPE] + oldnewsep, oldnewsep) + new = new.replace(ProgramOptions[ESCAPE] + oldnewsep, oldnewsep) return [old, new] # End of 'GetOldNew()' @@ -979,19 +982,19 @@ ErrorMsg(eNULLARG % NULLEXT, EXIT=True) if opt == "-P": - if val: - pass + if len(val) == 1: + ProgramOptions[ESCAPE] = val else: - ErrorMsg(eNULLARG % NULLESC, EXIT=True) + ErrorMsg(eARGLENGTH % (NULLESC, "1"), EXIT=True) if opt == "-q": ProgramOptions[QUIET] = True if opt == '-R': - if val: + if len(val) == 1: ProgramOptions[RENSEP] = val else: - ErrorMsg(eNULLARG % NULLRENSEP, EXIT=True) + ErrorMsg(eARGLENGTH % (NULLRENSEP, "1"), EXIT=True) if opt == "-r": req = {}