diff --git a/tren.py b/tren.py index 7c91d86..7d05e50 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.171 2010/03/06 15:57:21 tundra Exp $" +RCSID = "$Id: tren.py,v 1.172 2010/03/06 16:26:17 tundra Exp $" VERSION = RCSID.split()[2] # Copyright Information @@ -39,6 +39,8 @@ import copy import getopt +import grp +import pwd import os import re from stat import * @@ -107,8 +109,12 @@ TOKCMDEXEC = "`" # Delimiter for command execution renaming tokens TOKDELIM = "/" # Delimiter for all renaming tokens TOKENV = "$" # Introducer for environment variable replacement tokens +TOKFILGID = "g" # File GID replacement token +TOKFILGRP = "G" # File Group Name replacement token TOKFILLEN = "L" # File Length replacement token TOKFILNAM = "F" # File Name replacement token +TOKFILUID = "u" # File UID replacement token +TOKFILUNAM = "U" # File User Name replacement token # Internal program state literals @@ -719,11 +725,23 @@ # File Attribute Renaming Tokens ### - if r[2] == TOKFILLEN: + if 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] == TOKFILNAM: r[2] = os.path.basename(target) + + elif r[2] == TOKFILUID: + r[2] = str(self.RenNames[target][STATS][ST_UID]) + + elif r[2] == TOKFILUNAM: + r[2] = pwd.getpwuid(self.RenNames[target][STATS][ST_UID])[0] ### @@ -741,7 +759,7 @@ command = r[2][1:-1] - # Handle Windows variants which act differently + # Handle Windows variants - they act differently if os.name != 'posix': pipe = os.popen(command, 'r')