1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 """ Query hwdata database and return decription of vendor and/or device. """
17
19 """ Interace to usb.ids from hwdata package """
20 filename = '/usr/share/hwdata/usb.ids'
21 devices = None
22
24 """ Load pci.ids from file to internal data structure.
25 parameter 'filename' can specify location of this file
26 """
27 if filename:
28 self.filename = filename
29 else:
30 self.filename = USB.filename
31 self.cache = 1
32
33 if self.cache and not USB.devices:
34
35 USB.devices = {}
36 for line in open(self.filename).readlines():
37 l = line.split()
38 if line.startswith('#'):
39 if line.startswith('# List of known device classes, subclasses and protocols'):
40 break
41 else:
42 continue
43 elif len(l) == 0:
44 continue
45 elif line.startswith('\t\t'):
46 interface_id = l[0].lower()
47 if len(l) > 2:
48 interface_name = ' '.join(l[1:])
49 else:
50 interface_name = ''
51 USB.devices[vendor][1][device][0][interface_id] = interface_name
52 elif line.startswith('\t'):
53 device = l[0].lower()
54 device_name = ' '.join(l[1:])
55 USB.devices[vendor][1][device] = [device_name, {}]
56 else:
57 vendor = l[0].lower()
58 vendor_name = ' '.join(l[1:])
59 if not USB.devices.has_key(vendor):
60 USB.devices[vendor] = [vendor_name, {}]
61 else:
62 USB.devices[vendor][0] = vendor_name
63
65 """ Return description of vendor. Parameter is two byte code in hexa.
66 If vendor is unknown None is returned.
67 """
68 vendor = vendor.lower()
69 if self.cache:
70 if USB.devices.has_key(vendor):
71 return USB.devices[vendor][0]
72 else:
73 return None
74 else:
75 raise
76
78 """ Return description of device. Parameters are two byte code variables in hexa.
79 If device is unknown None is returned.
80 """
81 vendor = vendor.lower()
82 device = device.lower()
83 if self.cache:
84 if USB.devices.has_key(vendor):
85 if USB.devices[vendor][1].has_key(device):
86 return USB.devices[vendor][1][device][0]
87 else:
88 return None
89 else:
90 return None
91 else:
92 raise
93
95 """ Interace to pci.ids from hwdata package """
96 filename = '/usr/share/hwdata/pci.ids'
97 devices = None
98
100 """ Load pci.ids from file to internal data structure.
101 parameter 'filename' can specify location of this file
102 """
103 if filename:
104 self.filename = filename
105 else:
106 self.filename = PCI.filename
107 self.cache = 1
108
109 if self.cache and not PCI.devices:
110
111 pcirec = {}
112 PCI.devices = {}
113 for line in open(self.filename).readlines():
114 l = line.split()
115 if line.startswith('#'):
116 continue
117 elif len(l) == 0:
118 continue
119 elif line.startswith('\t\t'):
120 subvendor = l[0].lower()
121 if len(l) > 2:
122 subdevice = l[1].lower()
123 else:
124 subdevice = ''
125 if len(l) > 3:
126 subsystem_name = ' '.join(l[2:])
127 else:
128 subsystem_name = ''
129 if not PCI.devices.has_key(subvendor):
130 PCI.devices[subvendor] = [vendor_name, {subdevice: subsystem_name}]
131 else:
132 PCI.devices[subvendor][1][subdevice] = subsystem_name
133 elif line.startswith('\t'):
134 device = l[0].lower()
135 device_name = ' '.join(l[1:])
136 PCI.devices[vendor][1][device] = device_name
137 else:
138 vendor = l[0].lower()
139 vendor_name = ' '.join(l[1:])
140 if not PCI.devices.has_key(vendor):
141 PCI.devices[vendor] = [vendor_name, {}]
142 else:
143 PCI.devices[vendor][0] = vendor_name
144
146 """ Return description of vendor. Parameter is two byte code in hexa.
147 If vendor is unknown None is returned.
148 """
149 vendor = vendor.lower()
150 if self.cache:
151 if PCI.devices.has_key(vendor):
152 return PCI.devices[vendor][0]
153 else:
154 return None
155 else:
156 raise
157
159 """ Return description of device. Parameters are two byte code variables in hexa.
160 If device is unknown None is returned.
161 """
162 vendor = vendor.lower()
163 device = device.lower()
164 if self.cache:
165 if PCI.devices.has_key(vendor):
166 if PCI.devices[vendor][1].has_key(device):
167 return PCI.devices[vendor][1][device]
168 else:
169 return None
170 else:
171 return None
172 else:
173 raise
174