Cleaned up renaming token error messages and fixed bug that happened on null format fields.
1 parent 005b120 commit 5785dfe4a65250bd5fe94ea26ed661a8875ebfcc
@tundra tundra authored on 15 Mar 2010
Showing 1 changed file
View
30
tren.py
 
PROGNAME = "tren.py"
BASENAME = PROGNAME.split(".py")[0]
PROGENV = BASENAME.upper()
RCSID = "$Id: tren.py,v 1.192 2010/03/13 20:57:13 tundra Exp $"
RCSID = "$Id: tren.py,v 1.193 2010/03/15 16:47:42 tundra Exp $"
VERSION = RCSID.split()[2]
 
# Copyright Information
 
#####
# Error Messages
#####
 
eALPHABETEXIST = "Alphabet '%s' requested in '%s' does not exist!"
eALPHABETMISSING = "'%s' has a missing or incorrect alphabet specification!"
eALPHABETEXIST = "Renaming token '%s' specifies a non-existent alphabet!"
eALPHABETMISSING = "Renaming token '%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!"
eEXECFAIL = "Renaming token: '%s', 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.)"
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."
eTOKRANDIG = "Renaming token: '%s' has invalid random precision! Must be integer > 0."
eTOKUNKNOWN = "Renaming token '%s' is unknown type!"
eTOOMANYINC = "Too many includes! (Max is %d) Possible circular reference?" % MAXINCLUDES
 
 
rentokens.reverse()
 
for r in rentokens:
 
fullrentoken = "%s%s%s" % (TOKDELIM, r[2], TOKDELIM) # Need this for error messages.
###
# File Attribute Renaming Tokens
###
 
 
# Nonzero status means error attempting to execute the command
if status:
ErrorMsg(eEXECFAIL % command)
ErrorMsg(eEXECFAIL % (fullrentoken, command))
 
# Otherwise swap the command with its results, stripping newlines
else:
precision = r[2].split(TOKRAND)[1]
precision = int(precision)
 
except:
ErrorMsg(eTOKRANDIG % str(precision))
ErrorMsg(eTOKRANDIG % fullrentoken)
 
if precision < 1:
ErrorMsg(eTOKRANDIG % str(precision))
ErrorMsg(eTOKRANDIG % fullrentoken)
fmt = '"%0' + str(precision) + 'd" % random.randint(0, pow(10, precision)-1)'
r[2] = eval(fmt)
 
found = True
break
if not found:
ErrorMsg(eTOKBADSEQ % r[2])
ErrorMsg(eTOKBADSEQ % fullrentoken)
 
# Now derive the name of the alphabet to use
 
if field[0] != ALPHADELIM:
ErrorMsg(eALPHABETMISSING % r[2])
if not field.startswith(ALPHADELIM):
ErrorMsg(eALPHABETMISSING % fullrentoken)
 
field = field[1:]
 
alphabet, alphadelim, field = field.partition(ALPHADELIM)
 
if not alphadelim:
ErrorMsg(eALPHABETMISSING % r[2])
ErrorMsg(eALPHABETMISSING % fullrentoken)
 
# Empty alphabet string means default to decimal counting
if not alphabet:
alphabet = DECIMAL
if alphabet not in ALPHABETS:
ErrorMsg(eALPHABETEXIST % (alphabet, r[2]))
ErrorMsg(eALPHABETEXIST % fullrentoken)
 
 
# Retrieve the ordered list of the requested type,
# adjust for descending order, and plug in the
# Unrecognized Renaming Token
###
else:
ErrorMsg(eTOKUNKNOWN % (TOKDELIM + r[2] + TOKDELIM))
ErrorMsg(eTOKUNKNOWN % fullrentoken)
###
# Successful Lookup, Do the actual replacement
###