forked from hrbeu/learnpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_cpuinfo.py
More file actions
26 lines (24 loc) · 856 Bytes
/
get_cpuinfo.py
File metadata and controls
26 lines (24 loc) · 856 Bytes
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
#-*-coding:utf-8-*-
from collections import OrderedDict
def CPUINFO():
#CPU_info like {'0':{'':'','':'',...},'1':{'':'','':'',...},...}
CPU_info=OrderedDict()
proc_info=OrderedDict()
proc_id=0
with open('/proc/cpuinfo') as f:
for line in f:
#start of the info on one processor
if line.strip():
if line.split(':')[0] is not None and line.split(':')[1] is not None:
proc_info[line.split(':')[0].strip()]=line.split(':')[1].strip()
else:
proc_info[line.split(':')[0].strip()]=''
#end of the info on one processor
else:
CPU_info[proc_id]=proc_info
proc_id=proc_id+1
return CPU_info
if __name__=="__main__":
cpu_info=CPUINFO()
for id in cpu_info.keys():
print cpu_info[id]['model name']