diff --git a/tren.py b/tren.py index a0cce99..5e4a6bf 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.183 2010/03/10 19:09:13 tundra Exp $" +RCSID = "$Id: tren.py,v 1.184 2010/03/10 22:18:20 tundra Exp $" VERSION = RCSID.split()[2] # Copyright Information @@ -42,6 +42,7 @@ import grp import pwd import os +import random import re from stat import * import sys @@ -167,6 +168,7 @@ TOKCMDEXEC = "`" # Delimiter for command execution renaming tokens TOKENV = "$" # Introducer for environment variable replacement tokens +TOKRAND = "RAND" # Random replacement token # Sequence Renaming Tokens @@ -271,6 +273,7 @@ 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 @@ -947,6 +950,28 @@ else: r[2] = output.replace("\n", "") + + # Random Number Replacement token + + elif r[2].startswith(TOKRAND): + + random.seed() + + # Figure out how many digits of randomness the user want + + try: + precision = r[2].split(TOKRAND)[1] + precision = int(precision) + + except: + ErrorMsg(eTOKRANDIG % str(precision)) + + if precision < 1: + ErrorMsg(eTOKRANDIG % str(precision)) + + fmt = '"%0' + str(precision) + 'd" % random.randint(0, pow(10, precision))' + r[2] = eval(fmt) + ### # Sequence Renaming Tokens ###