diff --git a/tren.py b/tren.py index 4c6dac3..bf5f703 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.155 2010/02/18 00:49:45 tundra Exp $" +RCSID = "$Id: tren.py,v 1.156 2010/02/24 00:00:35 tundra Exp $" VERSION = RCSID.split()[2] # Copyright Information @@ -82,20 +82,15 @@ # Literals ##### -ALL = "All" # Rename target is whole filename ARROW = "--->" # Used for formatting renaming messages COMMENT = "#" # Comment character in include files -DEFEXT = "." # Default name/extension separator DEFLEN = 80 # Default output line length DEFSEP = "=" # Default rename command separator: old=new DEFSUFFIX = ".backup" # String used to rename existing targets DEFESC = "\\" # Escape character -EXT = "Ext" # Rename target is extension INCL = "I" # Include file command line option INDENT = " " # Indent string for nested messages -NAM = "Nam" # Rename target is name NULLESC = "Escape string" # Cannot be null -NULLEXT = "Extension delimiter string" # Cannot be null NULLRENSEP = "Old/New separator string" # Cannot be null NULLSUFFIX = "Forced renaming suffix string" # Cannot be null OPTINTRO = "-" # Option introducer @@ -107,14 +102,12 @@ ESCAPE = "ESCAPE" ERRORCONTINUE = "ERRORCONTINUE" EXISTSUFFIX = "EXISTSUFFIX" -EXTDELIM = "EXTDELIM" FORCERENAME = "FORCERENAME" GLOBAL = "GLOBAL" MAXLINELEN = "MAXLINELEN" QUIET = "QUIET" REGEX = "REGEX" RENSEP = "RENSEP" -TARGET = "TARGET" TESTMODE = "TESTMODE" # Rename target keys @@ -198,20 +191,17 @@ uTable = [PROGVER, HOMEPAGE, - "usage: " + PROGNAME + " [-abCcdEefGghqtvwXx] [-I file] [-L string] [-r old=new]... [-S suffix] file|dir file|dir ...", + "usage: " + PROGNAME + " [-CcdEfGghqtvwXx] [-I file] [-r old=new]... [-S suffix] file|dir file|dir ...", " where,", - " -a Rename within the entire file or directory name (Default)", " -C Do case-sensitive renaming (Default)", " -c Collapse case when doing string substitution (Default: False)", " -d Dump debugging information (Default: False)", - " -e Only perform renaming within extension portion of or directory name (Default: False)", " -E Continue after an error is encountered (Default: False)", " -f Force renaming even if target file or directory name already exists (Default: False)", " -G Rename only the first instance of the specified string (Default)", " -g Replace all instances (global rename) of the old string with the new (Default: False)", " -h Print help information (Default: False)", " -I file Include command line arguments from file", - " -L string File extension delimiter string (Default: %s)" % DEFEXT, " -P char Use 'char' as the escape sequence (Default: %s)" % DEFESC, " -q Quiet mode, do not show progress (Default: False)", " -R char Separator character for -r rename arguments (Default: %s)" % DEFSEP, @@ -239,14 +229,12 @@ 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 FORCERENAME : False, # Do not rename if target already exists GLOBAL : False, # Only rename first instance of old string MAXLINELEN : DEFLEN, # Width of output messages QUIET : False, # Display progress REGEX : False, # Do not treat old string as a regex RENSEP : DEFSEP, # Old, New string separator for -r - TARGET : ALL, # Can be "All", "Name", or "Ext" TESTMODE : False # Global data structures } @@ -296,14 +284,12 @@ DEBUG : debug flag, CASESENSITIVE : case sensitivity flag, ERRORCONTINUE : error continuation flag, - EXTDELIM : name/Extension delimiter string, FORCERENAME : force renaming flag, GLOBAL : global replace flag, MAXLINELEN : max output line length, QUIET : quiet output flag, REGEX : regular expression enable flag, RENSEP : old/new rename separator string, - TARGET : target field , TESTMODE : testmode flag } ... (repeated for each rename request) ] @@ -449,7 +435,7 @@ # Go Do The Requested Renaming ##### - def Rename(self): + def ProcessRenameRequests(self): self.indentlevel = -1 @@ -463,7 +449,7 @@ for renrequest in self.RenRequests: - old, new = self.ResolveRenameStrings(renrequest[OLD], renrequest[NEW]) + old, new = self.ResolveRenameTokens(renrequest[OLD], renrequest[NEW]) oldstrings = [] # Build a list of indexes to every occurence of the old string, @@ -522,7 +508,7 @@ else: self.__RenameIt(pathname, oldname, newname) - # End of 'Rename()' + # End of 'ProcessRenameRequests()' ##### @@ -601,12 +587,12 @@ then be applied to the rename. """ - def ResolveRenameStrings(self, old, new): + def ResolveRenameTokens(self, old, new): return [old, new] - # End of 'ResolveRenameStrings()' + # End of 'ResolveRenameTokens()' # End of class 'RenameTargets' @@ -952,7 +938,7 @@ # And parse the command line try: - opts, args = getopt.getopt(OPTIONS, 'abbCcdEefGghL:P:qR:r:S:tvw:Xx]') + opts, args = getopt.getopt(OPTIONS, 'CcdEfGghP:qR:r:S:tvw:Xx]') except getopt.GetoptError as e: ErrorMsg(eBADARG % e.args[0], EXIT=True) @@ -968,12 +954,6 @@ for opt, val in opts: - if opt == "-a": - ProgramOptions[TARGET] = ALL - - if opt == "-b": - ProgramOptions[TARGET] = NAM - if opt == "-C": ProgramOptions[CASESENSITIVE] = True @@ -987,9 +967,6 @@ if opt == "-E": ProgramOptions[ERRORCONTINUE] = True - if opt == "-e": - ProgramOptions[TARGET] = EXT - if opt == "-f": ProgramOptions[FORCERENAME] = True @@ -1003,12 +980,6 @@ Usage() sys.exit(0) - if opt == "-L": - if val: - ProgramOptions[EXTDELIM] = val - else: - ErrorMsg(eNULLARG % NULLEXT, EXIT=True) - if opt == "-P": if len(val) == 1: ProgramOptions[ESCAPE] = val @@ -1082,7 +1053,7 @@ # Perform reqested renamings -targs.Rename() +targs.ProcessRenameRequests() # Release the target container if we created one