forked from archerslaw/pysam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
read_dmidecode_var_subprocess.py
39 lines (35 loc) · 1.14 KB
/
read_dmidecode_var_subprocess.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
#!/usr/bin/python
#coding=utf-8
'''
通过subprocess读取dmidecode内容,
System Information: Manufacturer, Product Name, Version, Serial Number, Family
'''
from subprocess import Popen, PIPE
def getDMI():
p = Popen('dmidecode', stdout=PIPE, shell=True)
stdout, stderr = p.communicate()
return stdout
def parserDMI(dmidata):
pd = {}
line_in = False
for line in dmidata.split("\n"):
if line.startswith('System Information'):
line_in = True
continue
if line.startswith('\t') and line_in:
#print line
k, v = [i.strip() for i in line.split(':')]
pd[k] = v
else:
line_in = False
return pd
if __name__ == "__main__":
dmidata = getDMI()
#print dmidata
print parserDMI(dmidata)
print '-----------------------------'
print 'Manufacturer : ' + parserDMI(dmidata)['Manufacturer']
print 'Product Name : ' + parserDMI(dmidata)['Product Name']
print 'Version : ' + parserDMI(dmidata)['Version']
print 'Serial Number: ' + parserDMI(dmidata)['Serial Number']
print 'Family : ' + parserDMI(dmidata)['Family']