/usr/lib/python2.7/dist-packages/Globs/hwd.py is in globs 0.2.0~svn50-4ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | ## hwd.py
##
## GL O.B.S.: GL Open Benchmark Suite
## Copyright (C) 2006-2007 Angelo Theodorou <encelo@users.sourceforge.net>
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##
import os
class HWDetect:
"""Hardware detection class"""
def __init__(self):
self.__hostname = self.fetch_hostname()
self.__cpu_info = self.gather_CPU_info()
self.__gl_info = self.gather_GL_info()
self.__mem_info = self.gather_MEM_info()
def __getitem__(self, key):
"""Return hardware info"""
if key == 'host':
return self.__hostname
elif key == 'cpu':
return self.__cpu_info[0]
elif key == 'cpus':
return self.__cpu_info
elif key == 'gl':
return self.__gl_info
elif key == 'mem':
return self.__mem_info
else:
raise KeyError
def fetch_hostname(self):
"""Fetch and store machine hostname"""
try:
file = open('/proc/sys/kernel/hostname')
except IOError:
return None
line = file.readline()
file.close()
# Remove trailing '\n'
if line[len(line)-1] == '\n':
line = line[:len(line)-1]
return line
def gather_CPU_info(self):
"""Gather info about the CPU"""
try:
file = open('/proc/cpuinfo')
except IOError:
return None
lines = file.readlines()
file.close()
# Multi CPU support
cpu_list = []
for line in lines:
if line.find('processor') == 0:
splitted = line.split(':')
id = int(splitted[1].strip())
cpu = {}
cpu_list.append(cpu)
elif line.find('model name') == 0:
splitted = line.split(':')
cpu_list[id]['model'] = splitted[1].strip()
elif line.find('cpu MHz') == 0:
splitted = line.split(':')
cpu_list[id]['frequency'] = splitted[1].strip()
elif line.find('bogomips') == 0:
splitted = line.split(':')
cpu_list[id]['bogomips'] = splitted[1].strip()
return cpu_list
def gather_MEM_info(self):
"""Gather info about the memory installed"""
try:
file = open('/proc/meminfo')
except IOError:
return None
lines = file.readlines()
file.close()
for line in lines:
if line.find('MemTotal') == 0:
splitted = line.split(':')
physical = splitted[1].strip()
# removing 'kB' suffix
physical = physical.split(' ')
physical = physical[0].strip()
elif line.find('SwapTotal') == 0:
splitted = line.split(':')
swap = splitted[1].strip()
# removing 'kB' suffix
swap = swap.split(' ')
swap = swap[0].strip()
return {'physical': physical, 'swap': swap}
def gather_GL_info(self):
"""Gather info about the OpenGL subsystem"""
extensions = []
pipe = os.popen('glxinfo')
lines = pipe.readlines()
pipe.close()
# Default values if nothing relevant is found from glxinfo output
vendor = _('N/A')
renderer = _('N/A')
version = _('N/A')
extensions = []
for line in lines:
if line.find('OpenGL vendor string') == 0:
splitted = line.split(':')
vendor = splitted[1].strip()
elif line.find('OpenGL renderer string') == 0:
splitted = line.split(':')
renderer = splitted[1].strip()
elif line.find('OpenGL version string') == 0:
splitted = line.split(':')
version = splitted[1].strip()
elif line.find('GL_') != -1: # This line contains a list of extensions
splitted = line.split(',')
for ext in splitted:
if ext.find('\n') == -1:
extensions.append(ext.strip())
return {'vendor': vendor, 'renderer': renderer, 'version': version, 'extensions': extensions}
def get_hostname(self):
"""Return the hostname"""
return self.__hostname
def get_cpu_info(self):
"""Return info about the first cpu detected"""
return self.__cpu_info[0]
def get_cpus_info(self):
"""Return info about all the available cpus"""
return self.__cpu_info
def get_gl_info(self):
"""Return the OpenGL subsystem info"""
return self.__gl_info
def get_mem_info(self):
"""Return memory info"""
return self.__mem_info
|