diff --git a/tren.py b/tren.py index 4228274..dde703b 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.179 2010/03/09 23:01:57 tundra Exp $" +RCSID = "$Id: tren.py,v 1.180 2010/03/10 00:50:14 tundra Exp $" VERSION = RCSID.split()[2] # Copyright Information @@ -119,14 +119,23 @@ TOKDELIM = "/" # Delimiter for all renaming tokens -# File Attribute Renaming Tokens +# Shared File Attribute And Sequence Renaming Tokens -TOKFILGID = "GID" # File GID replacement token -TOKFILGRP = "GNAME" # File Group Name replacement token -TOKFILLEN = "LEN" # File Length replacement token -TOKFILNAM = "FNAME" # File Name replacement token -TOKFILUID = "UID" # File UID replacement token -TOKFILUNAM = "UNAME" # File User Name replacement token +TOKFILALPHA = "ALPHA" +TOKFILATIME = "ATIME" +TOKFILCMD = "CMDLINE" +TOKFILCTIME = "CTIME" +TOKFILDEV = "DEV" +TOKFILGID = "GID" +TOKFILGRP = "GNAME" +TOKFILINODE = "INODE" +TOKFILMODE = "MODE" +TOKFILMTIME = "MTIME" +TOKFILNAM = "FNAME" +TOKFILNLINK = "NLINK" +TOKFILSIZE = "SIZE" +TOKFILUID = "UID" +TOKFILUNAM = "UNAME" # File Time Renaming Tokens @@ -192,18 +201,24 @@ BASE = "BASENAME" PATHNAME = "PATHNAME" STATS = "STATS" -ORDERBYCMDLINE = "ORDERBYCOMMANDLINE" -ORDERBYALPHA = "ORDERBYALPHA" -ORDERBYMODE = "ORDERBYMODE" -ORDERBYINODE = "ORDERBYINODE" -ORDERBYDEV = "ORDERBYDEV" -ORDERBYNLINK = "ORDERBYNLINK" -ORDERBYUID = "ORDERBYUID" -ORDERBYGID = "ORDERBYGID" -ORDERBYATIME = "ORDERBYATIME" -ORDERBYCTIME = "ORDERBYCTIME" -ORDERBYMTIME = "ORDERBYMTIME" -ORDERBYSIZE = "ORDERBYSIZE" + +# These literals serve two purposes: +# +# 1) They are used as the type indicator in a Sequence Renaming Token +# 2) They are keys to the SortViews dictionary that stores the prestorted views + +ORDERBYALPHA = TOKFILALPHA +ORDERBYATIME = TOKFILATIME +ORDERBYCMDLINE = TOKFILCMD +ORDERBYCTIME = TOKFILCTIME +ORDERBYDEV = TOKFILDEV +ORDERBYGID = TOKFILGID +ORDERBYINODE = TOKFILINODE +ORDERBYMODE = TOKFILMODE +ORDERBYMTIME = TOKFILMTIME +ORDERBYNLINK = TOKFILNLINK +ORDERBYSIZE = TOKFILSIZE +ORDERBYUID = TOKFILUID # Rename string keys @@ -251,6 +266,7 @@ 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.)" +eNOROOTRENAME = "Cannot rename root of file tree!" eNULLARG = "%s cannot be empty!" eRENAMEFAIL = "Attempt to rename '%s' to '%s' failed : %s!" eTOKDELIM = "Renaming token '%s' missing delimiter!" @@ -470,8 +486,14 @@ ErrorMsg(eFILEOPEN % (fullname, e.args[1])) # Store fullname, basename, and stat info for this file + + if basename: + self.RenNames[fullname] = {BASE : basename, PATHNAME : fullname.split(basename)[0], STATS : stats} - self.RenNames[fullname] = {BASE : basename, PATHNAME : fullname.split(basename)[0], STATS : stats} + # Catch the case where they're trying to rename the root of the directory tree + + else: + ErrorMsg(eNOROOTRENAME) # Incrementally build lists of keys that will later be # used to create sequence renaming tokens @@ -831,18 +853,30 @@ # File Attribute Renaming Tokens ### - if r[2] == TOKFILGID: + if r[2] == TOKFILDEV: + r[2] = str(self.RenNames[target][STATS][ST_DEV]) + + elif r[2] == TOKFILGID: r[2] = str(self.RenNames[target][STATS][ST_GID]) elif r[2] == TOKFILGRP: r[2] = grp.getgrgid(self.RenNames[target][STATS][ST_GID])[0] - elif r[2] == TOKFILLEN: - r[2] = str(self.RenNames[target][STATS][ST_SIZE]) + elif r[2] == TOKFILINODE: + r[2] = str(self.RenNames[target][STATS][ST_INO]) + + elif r[2] == TOKFILMODE: + r[2] = str(self.RenNames[target][STATS][ST_MODE]) elif r[2] == TOKFILNAM: r[2] = os.path.basename(target) + elif r[2] == TOKFILNLINK: + r[2] = str(self.RenNames[target][STATS][ST_NLINK]) + + elif r[2] == TOKFILSIZE: + r[2] = str(self.RenNames[target][STATS][ST_SIZE]) + elif r[2] == TOKFILUID: r[2] = str(self.RenNames[target][STATS][ST_UID]) @@ -916,7 +950,9 @@ ### elif r[2] != "" and (r[2][0] == TOKASCEND or r[2][0] == TOKDESCEND): - pass + + for token in self.SortViews: + print token ### # Unrecognized Renaming Token