-
Notifications
You must be signed in to change notification settings - Fork 2
/
lmparser.py
44 lines (39 loc) · 1.09 KB
/
lmparser.py
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
#!/usr/bin/python
import os, re, sys, getopt
lmstat="/path/to/flexlm/lmutil"
lmopts="lmstat"
def print_usage():
print "Usage:"
print os.path.basename(__file__), '-f <feature> -c <lic_server>'
def main(argv):
lic_server = ''
feature = ''
try:
opts, args = getopt.getopt(argv,"hf:c:",["feature=","lic_server="])
# Parse options
for opt, arg in opts:
if opt == '-h':
print_usage()
sys.exit()
elif opt in ("-f", "--feature"):
feature = arg
elif opt in ("-c", "--lic_server"):
lic_server = arg
if not feature and not lic_server:
raise getopt.GetoptError("")
except getopt.GetoptError:
print_usage()
sys.exit(2)
# Spawn lmutil
licenses=os.popen("%s %s -a -c %s -f %s" % (lmstat, lmopts, lic_server, feature))
# Parse lines
for line in licenses:
if re.search("^Users of " + feature + ":.*$", line):
# Test for line (Total of # licenses issued; Total of # licenses in use)
m=re.findall("([0-9]+) license", line)
if m and len(m) == 2:
free=int(m[0])-int(m[1])
# Return free licences
print free
if __name__ == "__main__":
main(sys.argv[1:])