diff --git a/tren.py b/tren.py index 8949044..94ec2a4 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.188 2010/03/12 03:04:12 tundra Exp $" +RCSID = "$Id: tren.py,v 1.189 2010/03/12 22:19:29 tundra Exp $" VERSION = RCSID.split()[2] # Copyright Information @@ -290,6 +290,8 @@ iRENFORCED = "Target '%s' Exists. Creating Backup." iRENSKIPPED = "Target '%s' Exists. Renaming Of '%s' Skipped." iRENAMING = "Renaming '%s' " + ARROW + " '%s'." +iSEQTOOLONG = "Sequence number %s, longer than format string %s, Rolling over!" + ##### # Usage Prompts @@ -1102,6 +1104,21 @@ def ComputeSeqString(fmt, incr, alphabet): + """ + fmt = A literal "format field" string + incr = A integer to be "added" to the field + alphabet = The alphabet of characters to use, in ascending order + + Add 'incr' to 'fmt' in base(len(alphabet)). Characters in + 'fmt' that are not in 'alphabet' are ignored in this addition. + + The final result is limited to be no longer than 'fmt'. Any + result longer than fmt has MSD dropped, thereby effectively + rolling over the count. If 'fmt' is null on entry, the final + result length is unlimited. + """ + + fmtlen = len(fmt) alphalen = len(alphabet) newval = "" @@ -1114,7 +1131,7 @@ # First convert the increment into a string in the base of the - # alphabet. + # alphabet idigits = [] while incr > alphalen-1: @@ -1126,7 +1143,7 @@ idigits.reverse() incr = "".join(idigits) - # Now to right-to-left digit addition with the format + # Now do right-to-left digit addition with the format # field. # Do position-wise "addition" via symbol substitution moving from @@ -1148,7 +1165,7 @@ sum += alphabet.index(incr[i]) - # Do arithmetic modulo alphabet length. + # Do arithmetic modulo alphabet length carry, digit = sum/alphalen, sum % alphalen @@ -1174,7 +1191,7 @@ while newval and newval[0] == alphabet[0]: newval = newval[1:] - + # Constrain the results to the length of the original format # string, rolling over and warning the user as necessary. The one # exception to this is when a null format string is passed. This @@ -1186,7 +1203,7 @@ if fmtlen: if len(newval) > fmtlen: - print "Result longer than pattern, rolling over" + InfoMsg(iSEQTOOLONG % (newval,fmt)) newval = newval[-fmtlen:] return fmt[:-len(newval)] + newval