diff --git a/tren.py b/tren.py index 97fdbd3..b2c4085 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.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 @@ -146,14 +146,14 @@ 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 @@ -233,12 +233,14 @@ 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 @@ -463,12 +465,14 @@ 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 = [ @@ -528,19 +532,21 @@ self.RenRequests = [] - # This data structure is used while we build up sort - # orders based on stat information. + # This data structure is used to build various sort views - SeqTypes = [ [ST_MODE, {}, ORDERBYMODE], - [ST_INO, {}, ORDERBYINODE], - [ST_DEV, {}, ORDERBYDEV], - [ST_NLINK, {}, ORDERBYNLINK], - [ST_UID, {}, ORDERBYUID], - [ST_GID, {}, ORDERBYGID], + 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 @@ -572,12 +578,23 @@ # Handle os.stat() values - statval = stats[statflag] + if statflag: + sortkey = stats[statflag] - if statval in storage: - storage[statval].append(fullname) + # 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 @@ -968,7 +985,7 @@ 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: @@ -986,7 +1003,7 @@ 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]