Implemented -b option to suppress backups during forced renaming.
1 parent 105c794 commit cd915be1e9a83a4837080bc2b38e6094e8e8dde3
@tundra tundra authored on 28 Mar 2010
Showing 1 changed file
View
42
tren.py
 
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
 
 
# 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
 
 
#####
# Literals
# Internal program state literals
#####
 
ASK = "ASK"
BACKUPS = "BACKUPS"
DEBUG = "DEBUG"
CASESENSITIVE = "CASESENSITIVE"
ESCAPE = "ESCAPE"
EXISTSUFFIX = "EXISTSUFFIX"
#####
# 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!"
 
 
#####
 
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)",
" -f Force renaming even if target file or directory name already exists (Default: False)",
IncludedFiles = []
 
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
EXISTSUFFIX : DEFSUFFIX, # What to tack on when renaming existing targets
self.RenRequests = [
{
ASK : interactive ask flag
BACKUPS : do backups during forced renaming flag,
OLD : old rename string,
NEW : new rename string,
DEBUG : debug flag,
CASESENSITIVE : case sensitivity flag,
(ProgramOptions[TESTMODE] and fullnew not in self.RenamedFiles and (newexists or fullnew in self.NewFiles)):
 
if ProgramOptions[FORCERENAME]:
 
# Create the backup
 
bkuname = newname + ProgramOptions[EXISTSUFFIX]
InfoMsg(indent + iRENFORCED % fullnew)
self.__RenameIt(pathname, newname, bkuname)
# Create the backup unless we've been told not to
 
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]:
 
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":
ProgramOptions[CASESENSITIVE] = True