Further update to Linux exception handling for host info.

这个提交包含在:
Craig Warren
2017-02-28 11:30:22 +00:00
父节点 c8a79b8b34
当前提交 f046c567c7

查看文件

@@ -211,11 +211,10 @@ def get_host_info():
# Linux # Linux
elif sys.platform == 'linux': elif sys.platform == 'linux':
try: try:
manufacturer = subprocess.check_output("cat /sys/class/dmi/id/sys_vendor", shell=True).decode('utf-8').strip() manufacturer = subprocess.check_output("cat /sys/class/dmi/id/sys_vendor", shell=True, stderr=subprocess.STDOUT).decode('utf-8').strip()
model = subprocess.check_output("cat /sys/class/dmi/id/product_name", shell=True).decode('utf-8').strip() model = subprocess.check_output("cat /sys/class/dmi/id/product_name", shell=True, stderr=subprocess.STDOUT).decode('utf-8').strip()
machineID = manufacturer + ' ' + model machineID = manufacturer + ' ' + model
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError:
print(e.returncode)
machineID = 'unknown' machineID = 'unknown'
# CPU information # CPU information
@@ -223,6 +222,8 @@ def get_host_info():
for line in allcpuinfo.split('\n'): for line in allcpuinfo.split('\n'):
if re.search('Model name', line): if re.search('Model name', line):
cpuID = re.sub('.*Model name.*:', '', line, 1).strip() cpuID = re.sub('.*Model name.*:', '', line, 1).strip()
else:
cpuID = 'unknown'
if 'Thread(s) per core' in line: if 'Thread(s) per core' in line:
threadspercore = int(line.strip()[-1]) threadspercore = int(line.strip()[-1])
if 'Socket(s)' in line: if 'Socket(s)' in line: