22 from __future__
import print_function
23 from __future__
import unicode_literals
24 from __future__
import division
25 from __future__
import absolute_import
26 from builtins
import int
27 from builtins
import open
28 from builtins
import object
29 from smolt_config
import get_config_attr
53 HWDATA_DIRS = [
get_config_attr(
"HWDATA_DIR"),
'/usr/share/hwdata',
'/usr/share/misc',
'/usr/share/' ]
54 for hwd_file
in HWDATA_DIRS:
55 fn =
"%s/%s.ids" % (hwd_file, bus)
56 if os.path.isfile(fn +
".gz"):
60 fo = gzip.open(fn +
".gz",
'rt', encoding=
'latin1')
66 fo = open(fn,
'rt', encoding=
'latin1')
71 raise Exception(
'Hardware data file not found. Please set the location HWDATA_DIR in config.py')
78 for line
in fo.readlines():
79 if line.startswith(
'#')
or not line.strip():
81 elif not line.startswith(
'\t'):
84 curvendor.num = int(line[0:4], 16)
87 curvendor.name = line[6:-1]
88 vendors[curvendor.num] = curvendor
91 elif line.startswith(
'\t\t'):
92 line = line.replace(
'\t',
'')
95 thisdev.vendor = int(line[0:4], 16)
99 thisdev.num = int(line[5:9], 16)
102 thisdev.name = line[11:-1]
105 subvend.num = thisdev.vendor
110 if subvend.num
not in curdevice.subvendors:
111 curdevice.subvendors[subvend.num] = subvend
112 subvend.devices[thisdev.num] = thisdev
114 subvend = curdevice.subvendors[subvend.num]
115 subvend.devices[thisdev.num] = thisdev
119 elif line.startswith(
'\t'):
120 line = line.replace(
'\t',
'')
123 curdevice.num = int(line[0:4], 16)
126 curdevice.name = line[6:-1]
128 curdevice.vendor = int(curvendor.num)
131 curvendor.devices[curdevice.num] = curdevice
142 def vendor(self, vend, subvend=None, alt='N/A', bus='pci'):
150 return self.
vendors[bus][vend].devices[dev].subvendors[subvend].name +
"a"
153 return self.
vendors[bus][vend].name
157 def device(self, vend, dev, subvend=None, subdevice=None, alt='N/A', bus='pci'):
167 subvend = int(subvend)
171 subdevice = int(subdevice)
175 return self.
vendors[bus][vend].devices[dev].name
178 self.
vendors[bus][vend].devices[dev].name
182 def subdevice(self, vend, dev, subvend, subdevice, alt='N/A', bus='pci'):
195 subvend = int(subvend)
199 subdevice = int(subdevice)
203 var = self.
vendors[bus][vend].devices[dev].subvendors[subvend].devices[subdevice].name
207 return self.
vendors[bus][vend].devices[dev].name