diff --git a/tren.py b/tren.py index 2588953..bc81293 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.177 2010/03/09 01:17:57 tundra Exp $" +RCSID = "$Id: tren.py,v 1.178 2010/03/09 22:56:36 tundra Exp $" VERSION = RCSID.split()[2] # Copyright Information @@ -114,13 +114,6 @@ ##### -# Month Conversion Tables -##### - -MONTHS = {1:"Jan", 2:"Feb", 3:"Mar", 4:"Apr", 5:"May", 6:"Jun", - 7:"Jul", 8:"Aug", 9:"Sep", 10:"Oct", 11:"Nov", 12:"Dec"} - -##### # Replacement Token Literals ##### @@ -161,11 +154,16 @@ TOKMSEC = "MSEC" # ss replacement token TOKMYEAR = "MYEAR" # yyyy replacement token -# System Related Renaming Tokens +# System Renaming Tokens TOKCMDEXEC = "`" # Delimiter for command execution renaming tokens TOKENV = "$" # Introducer for environment variable replacement tokens +# Sequence Renaming Tokens + +TOKASCEND = "+" # Ascending order flag +TOKDESCEND = "-" # Descending order flag + ##### # Internal program state literals @@ -295,6 +293,44 @@ " -x Treat the old replacement string as a Python regular expression (Default: False)", ] + +#----------------------------------------------------------# +# Lookup Tables # +#----------------------------------------------------------# + +# Month Conversion Table + +MONTHS = {1:"Jan", 2:"Feb", 3:"Mar", 4:"Apr", 5:"May", 6:"Jun", + 7:"Jul", 8:"Aug", 9:"Sep", 10:"Oct", 11:"Nov", 12:"Dec"} + +# File Time Renaming Token Lookup Table + +FILETIMETOKS = { TOKADAY : ("%02d", "ST_ATIME", "tm_mday"), + TOKAHOUR : ("%02d", "ST_ATIME", "tm_hour"), + TOKAMIN : ("%02d", "ST_ATIME", "tm_min"), + TOKAMON : ("%02d", "ST_ATIME", "tm_mon"), + TOKAMONTH : ("", "ST_ATIME", "tm_mon"), + TOKASEC : ("%02d", "ST_ATIME", "tm_sec"), + TOKAYEAR : ("%04d", "ST_ATIME", "tm_year"), + TOKCDAY : ("%02d", "ST_CTIME", "tm_mday"), + TOKCHOUR : ("%02d", "ST_CTIME", "tm_hour"), + TOKCMIN : ("%02d", "ST_CTIME", "tm_min"), + TOKCMON : ("%02d", "ST_CTIME", "tm_mon"), + TOKCMONTH : ("", "ST_CTIME", "tm_mon"), + TOKCSEC : ("%02d", "ST_CTIME", "tm_sec"), + TOKCYEAR : ("%04d", "ST_CTIME", "tm_year"), + TOKMDAY : ("%02d", "ST_MTIME", "tm_mday"), + TOKMHOUR : ("%02d", "ST_MTIME", "tm_hour"), + TOKMMIN : ("%02d", "ST_MTIME", "tm_min"), + TOKMMON : ("%02d", "ST_MTIME", "tm_mon"), + TOKMMONTH : ("", "ST_MTIME", "tm_mon"), + TOKMSEC : ("%02d", "ST_MTIME", "tm_sec"), + TOKMYEAR : ("%04d", "ST_MTIME", "tm_year") + } + + + + #----------------------------------------------------------# # Global Variables & Data Structures # #----------------------------------------------------------# @@ -320,6 +356,7 @@ } + #--------------------------- Code Begins Here ---------------------------------# @@ -817,69 +854,22 @@ # File Time Renaming Tokens ### - elif r[2] == TOKADAY: - r[2] = "%02d" % time.localtime(self.RenNames[target][STATS][ST_ATIME]).tm_mday - - elif r[2] == TOKAHOUR: - r[2] = "%02d" % time.localtime(self.RenNames[target][STATS][ST_ATIME]).tm_hour - - elif r[2] == TOKAMIN: - r[2] = "%02d" % time.localtime(self.RenNames[target][STATS][ST_ATIME]).tm_min - - elif r[2] == TOKAMON: - r[2] = "%02d" % time.localtime(self.RenNames[target][STATS][ST_ATIME]).tm_mon + if r[2] in FILETIMETOKS: - elif r[2] == TOKAMONTH: - r[2] = MONTHS[time.localtime(self.RenNames[target][STATS][ST_ATIME]).tm_mon] - - elif r[2] == TOKASEC: - r[2] = "%02d" % time.localtime(self.RenNames[target][STATS][ST_ATIME]).tm_sec + parms = FILETIMETOKS[r[2]] + val = eval("time.localtime(self.RenNames[target][STATS][%s]).%s" % (parms[1], parms[2])) - elif r[2] == TOKAYEAR: - r[2] = "%02d" % time.localtime(self.RenNames[target][STATS][ST_ATIME]).tm_year - - elif r[2] == TOKCDAY: - r[2] = "%02d" % time.localtime(self.RenNames[target][STATS][ST_CTIME]).tm_mday - - elif r[2] == TOKCHOUR: - r[2] = "%02d" % time.localtime(self.RenNames[target][STATS][ST_CTIME]).tm_hour + # The first value of FILETIMETOKS table entry + # indicates the formatting string to use (if the entry + # is non null), or that we're doing a lookup for the + # name of a month (if the entry is null) + + if parms[0]: + r[2] = parms[0] % val + + else: + r[2] = MONTHS[val] - elif r[2] == TOKCMIN: - r[2] = "%02d" % time.localtime(self.RenNames[target][STATS][ST_CTIME]).tm_min - - elif r[2] == TOKCMON: - r[2] = "%02d" % time.localtime(self.RenNames[target][STATS][ST_CTIME]).tm_mon - - elif r[2] == TOKCMONTH: - r[2] = MONTHS[time.localtime(self.RenNames[target][STATS][ST_CTIME]).tm_mon] - - elif r[2] == TOKCSEC: - r[2] = "%02d" % time.localtime(self.RenNames[target][STATS][ST_CTIME]).tm_sec - - elif r[2] == TOKCYEAR: - r[2] = "%02d" % time.localtime(self.RenNames[target][STATS][ST_CTIME]).tm_year - - elif r[2] == TOKMDAY: - r[2] = "%02d" % time.localtime(self.RenNames[target][STATS][ST_MTIME]).tm_mday - - elif r[2] == TOKMHOUR: - r[2] = "%02d" % time.localtime(self.RenNames[target][STATS][ST_MTIME]).tm_hour - - elif r[2] == TOKMMIN: - r[2] = "%02d" % time.localtime(self.RenNames[target][STATS][ST_MTIME]).tm_min - - elif r[2] == TOKMMON: - r[2] = "%02d" % time.localtime(self.RenNames[target][STATS][ST_MTIME]).tm_mon - - elif r[2] == TOKMMONTH: - r[2] = MONTHS[time.localtime(self.RenNames[target][STATS][ST_MTIME]).tm_mon] - - elif r[2] == TOKMSEC: - r[2] = "%02d" % time.localtime(self.RenNames[target][STATS][ST_MTIME]).tm_sec - - elif r[2] == TOKMYEAR: - r[2] = "%02d" % time.localtime(self.RenNames[target][STATS][ST_MTIME]).tm_year - ### # System Renaming Tokens ### @@ -922,7 +912,14 @@ r[2] = output.replace("\n", "") ### - # Unrecognized renaming token + # Sequence Renaming Tokens + ### + + elif r[2] != "" and (r[2][0] == TOKASCEND or r[2][0] == TOKDESCEND): + pass + + ### + # Unrecognized Renaming Token ### else: