Implmenented UID, Uname, GID, and Gname renaming tokens.
1 parent 091d2c2 commit 938d5b85f90b01541fdef475ce4750494eb0df41
@tundra tundra authored on 6 Mar 2010
Showing 1 changed file
View
30
tren.py
 
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
 
#----------------------------------------------------------#
 
import copy
import getopt
import grp
import pwd
import os
import re
from stat import *
import sys
 
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
 
###
# 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]
 
###
# System Renaming Tokens
elif r[2].startswith(TOKCMDEXEC) and r[2].endswith(TOKCMDEXEC):
 
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')