Consolidated all test mode reporting down into __RenameIt() so that -t will also show any required backup operations.
1 parent 23fb393 commit b672dd79a857d68c1f95815bc017fdc42dda2809
@tundra tundra authored on 26 Feb 2010
Showing 1 changed file
View
67
tren.py
 
PROGNAME = "tren.py"
BASENAME = PROGNAME.split(".py")[0]
PROGENV = BASENAME.upper()
RCSID = "$Id: tren.py,v 1.162 2010/02/26 18:56:41 tundra Exp $"
RCSID = "$Id: tren.py,v 1.163 2010/02/26 20:11:29 tundra Exp $"
VERSION = RCSID.split()[2]
 
# Copyright Information
 
 
# Nothing to do, if old- and new names are the same
 
if newname != oldname:
 
# 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)
self.__RenameIt(pathname, oldname, newname)
# End of 'ProcessRenameRequests()'
 
 
 
fullold = pathname + oldname
fullnew = pathname + newname
 
# Let the user know what we're trying to do
 
InfoMsg(indent + iRENAMING % (fullold, fullnew))
 
# See if our proposed renaming is about to stomp on an
# existing file, and create a backup if forced renaming
# requested. We such backups with a recursive call to
# ourselves so that length and backups of backups are
# enforced.
 
 
# requested. We do such backups with a recursive call to
# ourselves so that filename length limits are observed and
# backups-of-backups are preserved.
 
doit = True
if os.path.exists(fullnew):
 
if ProgramOptions[FORCERENAME]:
 
bkuname = newname + ProgramOptions[EXISTSUFFIX]
InfoMsg(indent + iRENFORCED % fullnew)
self.__RenameIt(pathname, newname, bkuname)
# Rename the original
 
self.__RenameIt(pathname, oldname, newname)
 
 
else:
InfoMsg(indent + iRENSKIPPED % (fullnew, fullold))
 
# No target conflict, just do the requested renaming
 
else:
try:
os.rename(fullold, fullnew)
except OSError as e:
ErrorMsg(eRENAMEFAIL % (fullold, fullnew, e.args[1]))
doit = False
 
if doit:
 
InfoMsg(indent + iRENAMING % (fullold, fullnew))
 
if not ProgramOptions[TESTMODE]:
 
try:
os.rename(fullold, fullnew)
except OSError as e:
ErrorMsg(eRENAMEFAIL % (fullold, fullnew, e.args[1]))
 
self.indentlevel -= 1
 
# End of '__RenameIt()'