Implemented sort views, ORDERBYGROUP and ORDERBYUSER.
1 parent 3987e1d commit d6e91a8f9d4cbdd064c5a0ad58f45edfc91c27ba
@tundra tundra authored on 17 Mar 2010
Showing 1 changed file
View
75
tren.py
 
PROGNAME = "tren.py"
BASENAME = PROGNAME.split(".py")[0]
PROGENV = BASENAME.upper()
RCSID = "$Id: tren.py,v 1.196 2010/03/16 21:28:12 tundra Exp $"
RCSID = "$Id: tren.py,v 1.197 2010/03/17 15:16:48 tundra Exp $"
VERSION = RCSID.split()[2]
 
# Copyright Information
 
TOKFILCTIME = "CTIME"
TOKFILDEV = "DEV"
TOKFILFNAME = "FNAME"
TOKFILGID = "GID"
TOKFILGRP = "GNAME"
TOKFILGROUP = "GROUP"
TOKFILINODE = "INODE"
TOKFILMODE = "MODE"
TOKFILMTIME = "MTIME"
TOKFILNLINK = "NLINK"
TOKFILSIZE = "SIZE"
TOKFILUID = "UID"
TOKFILUNAM = "UNAME"
TOKFILUSER = "USER"
 
# File Time Renaming Tokens
 
TOKADAY = "ADAY" # mm replacement token
ORDERBYCTIME = TOKFILCTIME
ORDERBYDEV = TOKFILDEV
ORDERBYFNAME = TOKFILFNAME
ORDERBYGID = TOKFILGID
ORDERBYGROUP = TOKFILGROUP
ORDERBYINODE = TOKFILINODE
ORDERBYMODE = TOKFILMODE
ORDERBYMTIME = TOKFILMTIME
ORDERBYNLINK = TOKFILNLINK
ORDERBYSIZE = TOKFILSIZE
ORDERBYUID = TOKFILUID
ORDERBYUSER = TOKFILUSER
 
# Rename string keys
 
NEW = "NEW"
ORDERBYCTIME : [fullnames in ctimes order],
ORDERBYDEV : [fullnames in devs order],
ORDERBYFNAME : [fullnames in alphabetic order],
ORDERBYGID : [fullnames in gids order],
ORDERBYGROUP ; [fullnames in group name order],
ORDERBYINODE : [fullnames in inode order],
ORDERBYMODE : [fullnames in mode order],
ORDERBYMTIME : [fullnames in mtimes order],
ORDERBYNLINK : [fullnames in nlinks order],
ORDERBYSIZE : [fullnames in size order],
ORDERBYUID : [fullnames in uids order]
ORDERBYUID : [fullnames in uids order],
ORDERBYUSER : [fullnames in user name order]
}
 
self.RenRequests = [
{
 
self.RenRequests = []
 
 
# This data structure is used while we build up sort
# orders based on stat information.
 
SeqTypes = [ [ST_MODE, {}, ORDERBYMODE],
[ST_INO, {}, ORDERBYINODE],
[ST_DEV, {}, ORDERBYDEV],
[ST_NLINK, {}, ORDERBYNLINK],
[ST_UID, {}, ORDERBYUID],
[ST_GID, {}, ORDERBYGID],
# This data structure is used to build various sort views
 
SeqTypes = [
[ST_ATIME, {}, ORDERBYATIME],
[ST_CTIME, {}, ORDERBYCTIME],
[ST_DEV, {}, ORDERBYDEV],
[ST_GID, {}, ORDERBYGID],
["", {}, ORDERBYGROUP],
[ST_INO, {}, ORDERBYINODE],
[ST_MODE, {}, ORDERBYMODE],
[ST_MTIME, {}, ORDERBYMTIME],
[ST_NLINK, {}, ORDERBYNLINK],
[ST_SIZE, {}, ORDERBYSIZE],
[ST_UID, {}, ORDERBYUID],
["", {}, ORDERBYUSER],
]
 
# Populate the data structures with each targets' stat information
 
statflag, storage, order = seqtype
 
# Handle os.stat() values
 
statval = stats[statflag]
 
if statval in storage:
storage[statval].append(fullname)
if statflag:
sortkey = stats[statflag]
 
# Handle group name values
 
elif order == ORDERBYGROUP:
sortkey = grp.getgrgid(stats[ST_GID])[0]
 
# Handle user name values
 
elif order == ORDERBYUSER:
sortkey = pwd.getpwuid(stats[ST_UID])[0]
 
if sortkey in storage:
storage[sortkey].append(fullname)
else:
storage[statval] = [fullname]
storage[sortkey] = [fullname]
 
 
# Create the various sorted views we may need for sequence
# renaming tokens
 
elif r[2] == TOKFILGID:
r[2] = str(self.RenNames[target][STATS][ST_GID])
 
elif r[2] == TOKFILGRP:
elif r[2] == TOKFILGROUP:
r[2] = grp.getgrgid(self.RenNames[target][STATS][ST_GID])[0]
 
elif r[2] == TOKFILINODE:
r[2] = str(self.RenNames[target][STATS][ST_INO])
 
elif r[2] == TOKFILUID:
r[2] = str(self.RenNames[target][STATS][ST_UID])
 
elif r[2] == TOKFILUNAM:
elif r[2] == TOKFILUSER:
r[2] = pwd.getpwuid(self.RenNames[target][STATS][ST_UID])[0]
 
###