Added option --list-unused listing all unused modules for given pattern.
This commit is contained in:
parent
a02204d66d
commit
2759e769be
1 changed files with 23 additions and 10 deletions
|
@ -6,6 +6,7 @@
|
||||||
import os
|
import os
|
||||||
import datetime
|
import datetime
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
|
||||||
modules = list()
|
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("--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("--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("--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()
|
(options, args) = parser.parse_args()
|
||||||
if options.logdir :
|
if options.logdir :
|
||||||
logdir = options.logdir
|
logdir = options.logdir
|
||||||
|
@ -69,18 +71,29 @@ for logfilename in os.listdir(logdir) :
|
||||||
# if ' swap' in line :
|
# if ' swap' in line :
|
||||||
# print line.split()
|
# print line.split()
|
||||||
|
|
||||||
|
|
||||||
print "-"*78
|
print "-"*78
|
||||||
print "Module statistics for " + startdate.strftime('%Y-%m-%d') + " - " + enddate.strftime('%Y-%m-%d')
|
print "Module statistics for " + startdate.strftime('%Y-%m-%d') + " - " + enddate.strftime('%Y-%m-%d')
|
||||||
print "-"*78
|
print "-"*78
|
||||||
print "{0:60s}{1:>8s} {2:>8s}".format('module name', '# uses', '# users')
|
if options.list_unused :
|
||||||
print "-"*78
|
print "Unused modules:"
|
||||||
for (v,m) in sorted( ((v,k) for k,v in modulestats.iteritems()), reverse=True) :
|
print "-"*78
|
||||||
print "{0:60s}{1:>8d} {2:>8d}".format(m, v, len(moduleusers[m].keys()))
|
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 :
|
if options.printusers :
|
||||||
print moduleusers[m]
|
print sorted([ (u) for u in total_users ])
|
||||||
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 "-"*78
|
print "-"*78
|
||||||
|
|
Loading…
Reference in a new issue