Retooled Sequence renaming token parsing to require an alphabet specification.
1 parent 2c173ba commit b5962e64c276f97acec8bd64b734662c949fbce7
@tundra tundra authored on 13 Mar 2010
Showing 1 changed file
View
102
tren.py
 
PROGNAME = "tren.py"
BASENAME = PROGNAME.split(".py")[0]
PROGENV = BASENAME.upper()
RCSID = "$Id: tren.py,v 1.190 2010/03/13 19:59:52 tundra Exp $"
RCSID = "$Id: tren.py,v 1.191 2010/03/13 20:53:25 tundra Exp $"
VERSION = RCSID.split()[2]
 
# Copyright Information
 
UPPERLOWER = "UpperLower"
 
# General Literals
 
ALPHADELIM = ":" # Delimits alphabet name in a Sequence renaming token
TOKDELIM = "/" # Delimiter for all renaming tokens
 
# Shared File Attribute And Sequence Renaming Tokens
 
#####
# Debug Messages
#####
 
DEBUGFLAG = "-d"
dALPHABETS = "Alphabets"
dCMDLINE = "Command Line"
dCURSTATE = "Current State Of Program Options"
dDEBUG = "DEBUG"
dDUMPOBJ = "Dumping Object %s"
dINCLFILES = "Included Files:"
dPROGENV = "$" + PROGENV
dRENREQ = "Renaming Request:"
dRENTARGET = "Rename Target:"
dRESOLVEDOPTS = "Resolved Command Line"
dSEPCHAR = "-" # Used for debug separator lines
dSORTVIEW = "Sort View:"
DEBUGFLAG = "-d"
dALPHABETS = "Alphabets"
dCMDLINE = "Command Line"
dCURSTATE = "Current State Of Program Options"
dDEBUG = "DEBUG"
dDUMPOBJ = "Dumping Object %s"
dINCLFILES = "Included Files:"
dPROGENV = "$" + PROGENV
dRENREQ = "Renaming Request:"
dRENTARGET = "Rename Target:"
dRESOLVEDOPTS = "Resolved Command Line"
dSEPCHAR = "-" # Used for debug separator lines
dSORTVIEW = "Sort View:"
 
 
#####
# Error Messages
#####
 
eARGLENGTH = "%s must contain exactly %s character(s)!"
eBADARG = "Invalid command line: %s!"
eBADINCL = "option -%s requires argument" % INCL
eBADINSTANCE = "%s is an invalid replacement instance! Must be integer values in the form: n, n:n, :n, n:, or :"
eBADLEN = "Bad line length '%s'!"
eBADNEWOLD = "Bad -r argument '%s'! Requires exactly one new, old string separator (Default: " + DEFSEP + ")"
eBADREGEX = "Invalid Regular Expression: %s"
eERROR = "ERROR"
eEXECFAIL = "Command: '%s' Failed To Execute!"
eFILEOPEN = "Cannot open file '%s': %s!"
eLINELEN = "Specified line length too short! Must be at least %s" % MINLEN
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.)"
eNOROOTRENAME = "Cannot rename root of file tree!"
eNULLARG = "%s cannot be empty!"
eRENAMEFAIL = "Attempt to rename '%s' to '%s' failed : %s!"
eTOKBADSEQ = "Unknown sequence renaming token, '%s'!"
eTOKDELIM = "Renaming token '%s' missing delimiter!"
eTOKRANDIG = "Invalid random precision, '%s'! Must be integer > 0."
eTOKUNKNOWN = "Renaming token '%s' is unknown type!"
eTOOMANYINC = "Too many includes! (Max is %d) Possible circular reference?" % MAXINCLUDES
eALPHABETEXIST = "Alphabet '%s' requested in '%s' does not exist!"
eALPHABETMISSING = "'%s' has a missing or incorrect alphabet specification!"
eARGLENGTH = "%s must contain exactly %s character(s)!"
eBADARG = "Invalid command line: %s!"
eBADINCL = "option -%s requires argument" % INCL
eBADINSTANCE = "%s is an invalid replacement instance! Must be integer values in the form: n, n:n, :n, n:, or :"
eBADLEN = "Bad line length '%s'!"
eBADNEWOLD = "Bad -r argument '%s'! Requires exactly one new, old string separator (Default: " + DEFSEP + ")"
eBADREGEX = "Invalid Regular Expression: %s"
eERROR = "ERROR"
eEXECFAIL = "Command: '%s' Failed To Execute!"
eFILEOPEN = "Cannot open file '%s': %s!"
eLINELEN = "Specified line length too short! Must be at least %s" % MINLEN
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.)"
eNOROOTRENAME = "Cannot rename root of file tree!"
eNULLARG = "%s cannot be empty!"
eRENAMEFAIL = "Attempt to rename '%s' to '%s' failed : %s!"
eTOKBADSEQ = "Unknown sequence renaming token, '%s'!"
eTOKDELIM = "Renaming token '%s' missing delimiter!"
eTOKRANDIG = "Invalid random precision, '%s'! Must be integer > 0."
eTOKUNKNOWN = "Renaming token '%s' is unknown type!"
eTOOMANYINC = "Too many includes! (Max is %d) Possible circular reference?" % MAXINCLUDES
 
 
#####
# Informational Messages
###
# Sequence Renaming Tokens
###
elif r[2] != "" and (r[2][0] == TOKASCEND or r[2][0] == TOKDESCEND):
elif r[2] and (r[2][0] == TOKASCEND or r[2][0] == TOKDESCEND):
 
# Parse the Sequence Renaming Token into the token itself
# and its corresponding formatting field.
 
token, field = token[:len(seqtoken)], token[len(seqtoken):]
found = True
break
 
if not found:
ErrorMsg(eTOKBADSEQ % r[2])
 
# Now derive the name of the alphabet to use
 
if field[0] != ALPHADELIM:
ErrorMsg(eALPHABETMISSING % r[2])
 
field = field[1:]
 
alphabet, alphadelim, field = field.partition(ALPHADELIM)
 
if not alphadelim:
ErrorMsg(eALPHABETMISSING % r[2])
 
# Empty alphabet string means default to decimal counting
if not alphabet:
alphabet = DECIMAL
if alphabet not in ALPHABETS:
ErrorMsg(eALPHABETEXIST % (alphabet, r[2]))
 
 
# Retrieve the ordered list of the requested type,
# adjust for descending order, and plug in the
# sequence number for the current renaming target
 
if r[2][0] == TOKDESCEND:
orderedlist.reverse()
 
r[2] = ComputeSeqString(field, orderedlist.index(target), ALPHABETS[DECIMAL])
r[2] = ComputeSeqString(field, orderedlist.index(target), ALPHABETS[alphabet])
###
# Unrecognized Renaming Token
###