Changeset 24
- Timestamp:
- Nov 18, 2004, 3:52:52 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/pytools/diskreport.py
r23 r24 8 8 9 9 10 def tally(FN, col ):10 def tally(FN, col=4): 11 11 12 12 #Tally the size … … 25 25 return x 26 26 27 def sort_and_clean(FN): 28 fid = open(FN) 29 lines = fid.readlines() 30 fid.close() 31 32 fid = open(FN, 'w') 33 34 fid.write(lines[0]) #Header 35 36 sizes = [] 37 A = [] 38 for line in lines[1:]: 39 fields = line.split() 40 41 try: 42 x = float(fields[col]) 43 except: 44 pass 45 else: 46 sizes.append(x) 47 A.append( fields ) 48 49 50 S = map(None, sizes, A) 51 52 S.sort() 53 54 B = map(lambda x: x[1], A) 55 56 print B 27 57 28 58 … … 65 95 fid.close() 66 96 67 #Tally the size68 #x = tally('top50.txt', 0) #Meaningless69 70 97 71 98 txt = 'The top 50 largest directories are stored in top50.txt' 72 99 print txt 73 74 75 100 76 101 … … 87 112 88 113 114 txt = 'The oldest files' 89 115 os.system('echo "%s" > oldfiles.txt' %txt) 90 116 oldfiles = [] … … 96 122 os.system(cmd) 97 123 124 125 sort_and_clean('oldfiles.txt') 126 98 127 #Tally the size 99 128 x = tally('oldfiles.txt', 4) 100 129 101 130 102 131 txt = '%d files haven\'t been accessed for at least %d days and take up a total of %.2f MB. ' %(len(oldfiles), days, x/1000000) … … 116 145 fid.close() 117 146 147 txt = 'The biggest files' 118 148 os.system('echo "%s" > bigfiles.txt' %txt) 119 149 bigfiles = [] … … 127 157 128 158 159 129 160 #Tally the size 130 161 x = tally('bigfiles.txt', 4) 131 162 163 sort_and_clean('bigfiles.txt') 132 164 133 165 txt = '%d files are larger than %.2f MB and take up a total of %.2f MB'\ … … 156 188 x = tally('intersection.txt', 4) 157 189 190 sort_and_clean('intersection.txt') 191 158 192 txt = '%d files are larger than %.2f MB,'\ 159 193 %(len(intersection), filesize/1000000.0)
Note: See TracChangeset
for help on using the changeset viewer.