22 from builtins
import int
23 from builtins
import open
24 from builtins
import object
25 from smolt_config
import get_config_attr
49 HWDATA_DIRS = [
get_config_attr(
"HWDATA_DIR"),
'/usr/share/hwdata',
'/usr/share/misc',
'/usr/share/' ]
50 for hwd_file
in HWDATA_DIRS:
51 fn =
"%s/%s.ids" % (hwd_file, bus)
52 if os.path.isfile(fn +
".gz"):
56 fo = gzip.open(fn +
".gz",
'rt', encoding=
'latin1')
62 fo = open(fn,
'rt', encoding=
'latin1')
67 raise Exception(
'Hardware data file not found. Please set the location HWDATA_DIR in config.py')
74 for line
in fo.readlines():
75 if line.startswith(
'#')
or not line.strip():
77 elif not line.startswith(
'\t'):
80 curvendor.num = int(line[0:4], 16)
83 curvendor.name = line[6:-1]
84 vendors[curvendor.num] = curvendor
87 elif line.startswith(
'\t\t'):
88 line = line.replace(
'\t',
'')
91 thisdev.vendor = int(line[0:4], 16)
95 thisdev.num = int(line[5:9], 16)
98 thisdev.name = line[11:-1]
101 subvend.num = thisdev.vendor
106 if subvend.num
not in curdevice.subvendors:
107 curdevice.subvendors[subvend.num] = subvend
108 subvend.devices[thisdev.num] = thisdev
110 subvend = curdevice.subvendors[subvend.num]
111 subvend.devices[thisdev.num] = thisdev
115 elif line.startswith(
'\t'):
116 line = line.replace(
'\t',
'')
119 curdevice.num = int(line[0:4], 16)
122 curdevice.name = line[6:-1]
124 curdevice.vendor = int(curvendor.num)
127 curvendor.devices[curdevice.num] = curdevice
138 def vendor(self, vend, subvend=None, alt='N/A', bus='pci'):
146 return self.
vendors[bus][vend].devices[dev].subvendors[subvend].name +
"a"
149 return self.
vendors[bus][vend].name
153 def device(self, vend, dev, subvend=None, subdevice=None, alt='N/A', bus='pci'):
163 subvend = int(subvend)
167 subdevice = int(subdevice)
171 return self.
vendors[bus][vend].devices[dev].name
174 self.
vendors[bus][vend].devices[dev].name
178 def subdevice(self, vend, dev, subvend, subdevice, alt='N/A', bus='pci'):
191 subvend = int(subvend)
195 subdevice = int(subdevice)
199 var = self.
vendors[bus][vend].devices[dev].subvendors[subvend].devices[subdevice].name
203 return self.
vendors[bus][vend].devices[dev].name