Added option --list-unused listing all unused modules for given pattern.

This commit is contained in:
Christoph Niethammer 2014-02-05 11:49:08 +00:00
parent a02204d66d
commit 2759e769be

View file

@ -6,6 +6,7 @@
import os
import datetime
from optparse import OptionParser
import subprocess
modules = list()
@ -25,6 +26,7 @@ parser.add_option("--startdate", metavar="YYYY-MM-DD", dest="startdate")
parser.add_option("--enddate", metavar="YYYY-MM-DD", dest="enddate")
parser.add_option("--nohpc", action="store_true", default=False, dest="nohpc", help="Exclude hpc* accounts from stats")
parser.add_option("--printusers", action="store_true", default=False, dest="printusers", help="Print detailed user lists for module usage.")
parser.add_option("--list-unused", action="store_true", default=False, dest="list_unused", help="List only unused modules.")
(options, args) = parser.parse_args()
if options.logdir :
logdir = options.logdir
@ -69,18 +71,29 @@ for logfilename in os.listdir(logdir) :
# if ' swap' in line :
# print line.split()
print "-"*78
print "Module statistics for " + startdate.strftime('%Y-%m-%d') + " - " + enddate.strftime('%Y-%m-%d')
print "-"*78
print "{0:60s}{1:>8s} {2:>8s}".format('module name', '# uses', '# users')
print "-"*78
for (v,m) in sorted( ((v,k) for k,v in modulestats.iteritems()), reverse=True) :
print "{0:60s}{1:>8d} {2:>8d}".format(m, v, len(moduleusers[m].keys()))
if options.list_unused :
print "Unused modules:"
print "-"*78
avail_modules = []
p = subprocess.Popen("module -l av " + modulepattern, shell=True, stderr=subprocess.PIPE).stderr
for line in p :
if modulepattern in line :
avail_modules.append(line.split()[0])
for module in avail_modules :
if not module in modulestats :
print module
else :
print "{0:60s}{1:>8s} {2:>8s}".format('module name', '# uses', '# users')
print "-"*78
for (v,m) in sorted( ((v,k) for k,v in modulestats.iteritems()), reverse=True) :
print "{0:60s}{1:>8d} {2:>8d}".format(m, v, len(moduleusers[m].keys()))
if options.printusers :
print moduleusers[m]
print "-"*78
print "{0:60s}{1:>8d} {2:>8d}".format('total', total_modules, len(total_users))
if options.printusers :
print moduleusers[m]
print "-"*78
print "{0:60s}{1:>8d} {2:>8d}".format('total', total_modules, len(total_users))
if options.printusers :
print sorted([ (u) for u in total_users ])
print sorted([ (u) for u in total_users ])
print "-"*78