Created
June 9, 2009 04:02
-
-
Save khsing/126255 to your computer and use it in GitHub Desktop.
取dmidecode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# coding: utf-8 | |
import os | |
def getdmi(): | |
all = [] | |
single = [] | |
for l in os.popen('/usr/sbin/dmidecode'): #replace dmidecode with yours. | |
l = l.strip() | |
if l[0:6] == 'Handle': | |
all.append(single) | |
single = [l] | |
elif l[0:8] == 'DMI type': | |
pass | |
else: | |
single.append(l) | |
return all | |
def procDMI(dmi): | |
all = [] | |
for i in dmi: | |
s = {} | |
v = [] | |
l = '' | |
for j in i[3:]: | |
if j.rfind(':') != -1: | |
l,r = [k.strip() for k in j.split(':',1)] | |
v = [r] | |
else: | |
v.append(j.strip()) | |
s[l] = '\n'.join([x for x in v if x]) | |
all.append((i[1],s)) | |
return all | |
def main(): | |
c = ('System Information','Processor Information','Memory Device') | |
print filter(lambda x: x[0] in c,procDMI(getdmi())) | |
if __name__=="__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment