diff --git a/tren.py b/tren.py index 6bd6f1d..4c6dac3 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.154 2010/02/17 22:07:53 tundra Exp $" +RCSID = "$Id: tren.py,v 1.155 2010/02/18 00:49:45 tundra Exp $" VERSION = RCSID.split()[2] # Copyright Information @@ -180,6 +180,7 @@ eNAMELONG = "Renaming '%s' to new name '%s' too long! (Maximum length is %s.)" eNAMESHORT = "Renaming '%s' to new name '%s' too short! (Minimum length is %s.)" eNULLARG = "%s cannot be empty!" +eRENAMEFAIL = "Attempt to rename '%s' to '%s' failed : %s!" eTOOMANYINC = "Too many includes! (Max is %d) Possible circular reference?" % MAXINCLUDES @@ -189,7 +190,7 @@ iRENFORCED = "Target '%s' Exists. Creating Backup." iRENSKIPPED = "Target '%s' Exists. Renaming Of '%s' Skipped." -iRENAMING = "Renaming '%s' To '%s'." +iRENAMING = "Renaming '%s' " + ARROW + " '%s'." ##### # Usage Prompts @@ -413,7 +414,7 @@ del SeqTypes - # End of '__ini__()' + # End of '__init__()' ##### @@ -450,7 +451,6 @@ def Rename(self): - self.newnames = [] self.indentlevel = -1 # Create a list of all renaming to be done. @@ -506,16 +506,27 @@ for i in oldstrings: newname = newname[:i] + new + newname[i + len(old):] - # If the new name is different from the old one, rename it. + + # Nothing to do, if old- and new names are the same if newname != oldname: - self.__RenameIt(pathname, oldname, newname) + + # If we're in test mode, just show what we would do + + if ProgramOptions[TESTMODE]: + + InfoMsg(iRENAMING % (pathname+oldname, pathname+newname)) + + # Otherwise, actually do the renaming + + else: + self.__RenameIt(pathname, oldname, newname) # End of 'Rename()' ##### - # Actually Rename A File (Or Show What Would Happen) + # Actually Rename A File ##### def __RenameIt(self, pathname, oldname, newname): @@ -549,13 +560,8 @@ # ourselves so that length and backups of backups are # enforced. - # NOTE: We have to keep track of every new name produced. - # When running in test mode, this is the only way to know - # what *would* end up on the disk (in case a previous - # renaming operation creates a filename that is now in - # conflict with a subseqent renaming target. - if (fullnew in self.newnames) or os.path.exists(fullnew): + if os.path.exists(fullnew): if ProgramOptions[FORCERENAME]: @@ -564,7 +570,6 @@ bkuname = newname + ProgramOptions[EXISTSUFFIX] InfoMsg(indent + iRENFORCED % fullnew) self.__RenameIt(pathname, newname, bkuname) - self.newnames.remove(fullnew) # Rename the original @@ -577,8 +582,10 @@ # No target conflict, just do the requested renaming else: - - self.newnames.append(fullnew) + try: + os.rename(fullold, fullnew) + except OSError as e: + ErrorMsg(eRENAMEFAIL % (fullold, fullnew, e.args[1])) self.indentlevel -= 1 @@ -767,8 +774,8 @@ msgtype = TESTMODE if not ProgramOptions[QUIET]: - for dmsg in l: - PrintStdout(PROGNAME + " " + msgtype + ": " + imsg) + for msg in l: + PrintStdout(PROGNAME + " " + msgtype + ": " + msg) # End of 'InfoMsg()'