diff --git a/tren.py b/tren.py index ab95136..1c6164d 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.193 2010/03/15 16:47:42 tundra Exp $" +RCSID = "$Id: tren.py,v 1.194 2010/03/16 20:43:04 tundra Exp $" VERSION = RCSID.split()[2] # Copyright Information @@ -90,7 +90,7 @@ # 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 = "aCcdfhi:P:qR:r:S:tvw:Xx" # All legal command line options in getopt() format +OPTIONSLIST = "A:aCcdfhi:P:qR:r:S:tvw:Xx" # All legal command line options in getopt() format ##### @@ -277,6 +277,8 @@ eALPHABETEXIST = "Renaming token '%s' specifies a non-existent alphabet!" eALPHABETMISSING = "Renaming token '%s' has a missing or incorrect alphabet specification!" +eALPHACMDBAD = "Alphabet specificaton '%s' malformed! Try \"Name:Alphabet\"" +eALPHACMDLEN = "Alphabet '%s' too short! Must contain at least 2 symbols." eARGLENGTH = "%s must contain exactly %s character(s)!" eBADARG = "Invalid command line: %s!" eBADINCL = "option -%s requires argument" % INCL @@ -318,6 +320,7 @@ HOMEPAGE, "usage: " + PROGNAME + " [[-aCcdfhqtvwXx] [-I file] [-i instance] [-P escape] [ -R separator] [-S suffix] [-r old=new]] ... file|dir file|dir ...", " where,", + " -A alphabet Install \"alphabet\" for use by sequence renaming tokens", " -a Turn on interactive asking before each rename (Default: Off)", " -C Do case-sensitive renaming (Default)", " -c Collapse case when doing string substitution (Default: False)", @@ -1652,7 +1655,26 @@ for opt, val in opts: - # Turn on interactive "ask" mode + # Install new alphabet + + if opt == "-A": + + alphaname, delim, alpha = val.partition(ALPHADELIM) + + if not delim: + ErrorMsg(eALPHACMDBAD % val) + + if not alphaname: + ErrorMsg(eALPHACMDBAD % val) + + if len(alpha) < 2: + ErrorMsg(eALPHACMDLEN % val) + + a = [] + for c in alpha: + a.append(c) + + ALPHABETS[alphaname] = a if opt == "-a": ProgramOptions[ASK] = True