diff --git a/tren.py b/tren.py index 254acce..16316b0 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.211 2010/03/23 21:15:55 tundra Exp $" +RCSID = "$Id: tren.py,v 1.212 2010/03/28 19:52:04 tundra Exp $" VERSION = RCSID.split()[2] # Copyright Information @@ -132,7 +132,7 @@ # List all legal command line options that will be processed by getopt() later. # We exclude -I here because it is parsed manually before the getopt() call. -OPTIONSLIST = "A:aCcdfhi:P:qR:r:S:tvw:Xx" # All legal command line options in getopt() format +OPTIONSLIST = "A:abCcdfhi:P:qR:r:S:tvw:Xx" # All legal command line options in getopt() format ##### @@ -250,6 +250,7 @@ ##### ASK = "ASK" +BACKUPS = "BACKUPS" DEBUG = "DEBUG" CASESENSITIVE = "CASESENSITIVE" ESCAPE = "ESCAPE" @@ -363,8 +364,9 @@ # Informational Messages ##### -iRENFORCED = "Target '%s' Exists. Creating Backup." -iRENSKIPPED = "Target '%s' Exists. Renaming Of '%s' Skipped." +iFORCEDNOBKU = "Forced renaming WITHOUT backups in effect!!! %s is overwriting %s." +iRENFORCED = "Target '%s' exists. Creating backup." +iRENSKIPPED = "Target '%s' exists. Renaming '%s' skipped." iRENAMING = "Renaming '%s' " + ARROW + " '%s'." iSEQTOOLONG = "Sequence number %s, longer than format string %s, Rolling over!" @@ -375,10 +377,11 @@ uTable = [PROGVER, HOMEPAGE, - "usage: " + PROGNAME + " [[-aCcdfhqtvwXx] [-I file] [-i instance] [-P escape] [ -R separator] [-r old=new] [-S suffix] [-w width]] ... file|dir file|dir ...", + "usage: " + PROGNAME + " [[-abCcdfhqtvwXx] [-I file] [-i instance] [-P escape] [ -R separator] [-r old=new] [-S suffix] [-w width]] ... file|dir file|dir ...", " where,", " -A alphabet Install \"alphabet\" for use by sequence renaming tokens", " -a Ask interactively before renaming (Default: Off)", + " -b Turn off backups during forced renaming (Default: Do Backups)", " -C Do case-sensitive renaming (Default)", " -c Collapse case when doing string substitution (Default: False)", " -d Dump debugging information (Default: False)", @@ -483,6 +486,7 @@ ProgramOptions = { ASK : False, # Interactively ask user before renaming each file + BACKUPS : True, # Do backups during forced renaming DEBUG : False, # Debugging off CASESENSITIVE : True, # Search is case-sensitive ESCAPE : DEFESC, # Escape string @@ -548,6 +552,7 @@ self.RenRequests = [ { ASK : interactive ask flag + BACKUPS : do backups during forced renaming flag, OLD : old rename string, NEW : new rename string, DEBUG : debug flag, @@ -1061,17 +1066,21 @@ if ProgramOptions[FORCERENAME]: - # Create the backup + # Create the backup unless we've been told not to - bkuname = newname + ProgramOptions[EXISTSUFFIX] - InfoMsg(indent + iRENFORCED % fullnew) - self.__RenameIt(pathname, newname, bkuname) + if ProgramOptions[BACKUPS]: + + bkuname = newname + ProgramOptions[EXISTSUFFIX] + InfoMsg(indent + iRENFORCED % fullnew) + self.__RenameIt(pathname, newname, bkuname) + + else: + InfoMsg(iFORCEDNOBKU % (fullold, fullnew)) else: InfoMsg(indent + iRENSKIPPED % (fullnew, fullold)) doit = False - if doit: if ProgramOptions[ASK]: @@ -1965,6 +1974,11 @@ if opt == "-a": ProgramOptions[ASK] = True + # Turn off backups during forced renaming + + if opt == "-b": + ProgramOptions[BACKUPS] = False + # Select case-sensitivity for replacements (or not) if opt == "-C":