Changeset 24


Ignore:
Timestamp:
Nov 18, 2004, 3:52:52 PM (20 years ago)
Author:
ole
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/pytools/diskreport.py

    r23 r24  
    88
    99
    10 def tally(FN, col):
     10def tally(FN, col=4):
    1111
    1212    #Tally the size
     
    2525    return x   
    2626
     27def 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
    2757   
    2858
     
    6595fid.close()
    6696
    67 #Tally the size
    68 #x = tally('top50.txt', 0) #Meaningless
    69 
    7097
    7198txt = 'The top 50 largest directories are stored in top50.txt'
    7299print txt
    73 
    74 
    75100
    76101
     
    87112
    88113
     114txt = 'The oldest files'
    89115os.system('echo "%s" > oldfiles.txt' %txt)
    90116oldfiles = []
     
    96122    os.system(cmd)
    97123
     124
     125sort_and_clean('oldfiles.txt')
     126
    98127#Tally the size
    99128x = tally('oldfiles.txt', 4)
    100  
     129
    101130
    102131txt = '%d files haven\'t been accessed for at least %d days and take up a total of %.2f MB. ' %(len(oldfiles), days, x/1000000)
     
    116145fid.close()
    117146
     147txt = 'The biggest files'
    118148os.system('echo "%s" > bigfiles.txt' %txt)
    119149bigfiles = []
     
    127157
    128158
     159
    129160#Tally the size
    130161x = tally('bigfiles.txt', 4)
    131162
     163sort_and_clean('bigfiles.txt')
    132164
    133165txt = '%d files are larger than %.2f MB and take up a total of %.2f MB'\
     
    156188x = tally('intersection.txt', 4)
    157189
     190sort_and_clean('intersection.txt')
     191
    158192txt = '%d files are larger than %.2f MB,'\
    159193      %(len(intersection), filesize/1000000.0)
Note: See TracChangeset for help on using the changeset viewer.