-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathram-slots-used.py
More file actions
executable file
·49 lines (41 loc) · 1.58 KB
/
Copy pathram-slots-used.py
File metadata and controls
executable file
·49 lines (41 loc) · 1.58 KB
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
#!/usr/bin/env python
'''
Takes the dmi file (from hdt dump) as an argument, tallies all the sections
within that have 'Memory Bank' *and* 'DIMM' or 'SODIMM' in them. If you count
just 'Memory Bank', you also pickup ROM chips on some machines, which is not
what we want.
'''
import re
import sys
# Define a function that returns a dictionary
def new_dict(): return {}
def main():
dicts = []
index = 0
f = open(sys.argv[1])
for line in f:
line = re.sub('"','',line) # strip out quotes; strip, below, only removes one instance of quote
line = line.strip('\n, ') # strip off newline, commas, whitespace
if re.match('^{', line):
dicts.append(new_dict())
elif re.match('^}{', line):
dicts.append(new_dict())
index += 1
elif re.match('^}$', line):
pass
else:
key,value = line.split(':',1) # don't use split because some values contain colons
key = key.strip() # get rid of extra white space
value = value.strip() # get rid of extra white space
dicts[index][key] = value.strip()
#print "key is", key, "and value is", value
banks = 0
for d in dicts:
if 'Memory Bank' in d.keys():
if re.match('DIMM', d['dmi.memory.form_factor']) or re.match('SODIMM', d['dmi.memory.form_factor']) or re.match('RIMM', d['dmi.memory.form_factor']):
if d['dmi.memory.size'] != 'Free':
#print 'Found Memory Bank'
banks += 1
print banks
if __name__ == '__main__':
main()