-
Notifications
You must be signed in to change notification settings - Fork 0
/
analyzeLmodDB
executable file
·82 lines (58 loc) · 3.01 KB
/
analyzeLmodDB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python
# -*- python -*-
from __future__ import print_function
import os, sys, re, time, datetime, argparse
sys.path.append('/uufs/chpc.utah.edu/sys/srcdir/lmod/7.7.29/contrib/tracking_module_usage')
from LMODdb import LMODdb
from BeautifulTbl import BeautifulTbl
class CmdLineOptions(object):
""" Command line Options class """
def __init__(self):
""" Empty Ctor """
pass
def execute(self):
""" Specify command line arguments and parse the command line"""
parser = argparse.ArgumentParser()
parser.add_argument("--dbname", dest='dbname', action="store", default = "modlog", help="lmod db name")
parser.add_argument("--syshost", dest='syshost', action="store", default = "%", help="system host name")
parser.add_argument("--start", dest='startDate', action="store", default = "unknown", help="start date")
parser.add_argument("--end", dest='endDate', action="store", default = "unknown", help="end date")
parser.add_argument("--sqlPattern", dest='sqlPattern', action="store", default = "/opt/%", help="sql pattern for matching")
parser.add_argument("cmdA", nargs="+", help="commands: counts, usernames, modules_used_by")
parser.add_argument("--all", dest='allhosts', action="store_const", default = "unknown", const="allhosts", help="aggregate over all hosts")
parser.add_argument("--name", dest='modulename', action="store_const", default = "unknown", const="modulename", help="search over module name, not module path")
args = parser.parse_args()
return args
def dbConfigFn(dbname):
"""
Build config file name from dbname.
@param dbname: db name
"""
return dbname + "_db.conf"
def main():
args = CmdLineOptions().execute()
configFn = dbConfigFn(args.dbname)
if (not os.path.exists(configFn)):
configFn = os.path.join(os.path.dirname(os.path.realpath(__file__)),configFn)
lmod = LMODdb(configFn)
if (args.cmdA[0] == "counts"):
resultA = lmod.counts(args.sqlPattern, args.syshost, args.startDate, args.endDate, args.allhosts, args.modulename)
num = len(resultA) - 2
bt = BeautifulTbl(tbl=resultA, gap = 4, justify = "llr")
# Don't run this, it takes a long time
if (args.cmdA[0] == "numtimes"):
resultA = lmod.numtimes(args.sqlPattern, args.syshost, args.startDate, args.endDate)
num = len(resultA) - 2
bt = BeautifulTbl(tbl=resultA, gap = 4, justify = "llr")
if (args.cmdA[0] == "usernames"):
resultA = lmod.usernames(args.sqlPattern, args.syshost, args.startDate, args.endDate, args.modulename)
num = len(resultA) - 2
bt = BeautifulTbl(tbl=resultA, gap = 4, justify = "lll")
if (args.cmdA[0] == "modules_used_by"):
resultA = lmod.modules_used_by(args.sqlPattern, args.syshost, args.startDate, args.endDate, args.modulename)
num = len(resultA) - 2
bt = BeautifulTbl(tbl=resultA, gap = 4, justify = "lll")
print("\n")
print(bt.build_tbl())
print("\n\nNumber of entries: ",num)
if ( __name__ == '__main__'): main()