]>
git.ipfire.org Git - ipfire.org.git/blob - src/backend/hwdata.py
2 # Copyright (c) 1999--2012 Red Hat, Inc.
4 # This software is licensed to you under the GNU General Public License,
5 # version 2 (GPLv2). There is NO WARRANTY for this software, express or
6 # implied, including the implied warranties of MERCHANTABILITY or FITNESS
7 # FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
8 # along with this software; if not, see
9 # http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
11 # Red Hat trademarks are not licensed under GPLv2. No permission is
12 # granted to use or replicate Red Hat trademarks that are incorporated
13 # in this software or its documentation.
16 """ Query hwdata database and return decription of vendor and/or device. """
18 # pylint: disable=misplaced-bare-raise
21 """ Interace to usb.ids from hwdata package """
22 filename
= '/usr/share/misc/usb.ids'
25 def __init__(self
, filename
=None):
26 """ Load pci.ids from file to internal data structure.
27 parameter 'filename' can specify location of this file
30 self
.filename
= filename
32 self
.filename
= USB
.filename
35 if self
.cache
and not USB
.devices
:
39 f
= open(self
.filename
, encoding
='ISO8859-1')
45 for line
in f
.readlines():
48 if line
.startswith('#'):
49 if line
.startswith('# List of known device classes, subclasses and protocols'):
50 break # end of database of devices, rest is protocols, types etc.
55 elif line
.startswith('\t\t'):
56 interface_id
= l
[0].lower()
58 interface_name
= ' '.join(l
[1:])
62 USB
.devices
[vendor
][1][device
][0][interface_id
] = interface_name
64 sys
.stderr
.write("Unknown line at line {0} in {1}.\n".format(lineno
, self
.filename
))
65 elif line
.startswith('\t'):
67 device_name
= ' '.join(l
[1:])
68 USB
.devices
[vendor
][1][device
] = [device_name
, {}]
71 vendor_name
= ' '.join(l
[1:])
72 if vendor
not in USB
.devices
:
73 USB
.devices
[vendor
] = [vendor_name
, {}]
74 else: # this should not happen
75 USB
.devices
[vendor
][0] = vendor_name
77 def get_vendor(self
, vendor
):
78 """ Return description of vendor. Parameter is two byte code in hexa.
79 If vendor is unknown None is returned.
81 vendor
= vendor
.lower()
83 if vendor
in USB
.devices
:
84 return USB
.devices
[vendor
][0]
88 raise # not implemented yet
90 def get_device(self
, vendor
, device
):
91 """ Return description of device. Parameters are two byte code variables in hexa.
92 If device is unknown None is returned.
94 vendor
= vendor
.lower()
95 device
= device
.lower()
97 if vendor
in USB
.devices
:
98 if device
in USB
.devices
[vendor
][1]:
99 return USB
.devices
[vendor
][1][device
][0]
105 raise # not implemented yet
108 """ Interace to pci.ids from hwdata package """
109 filename
= '/usr/share/misc/pci.ids'
112 def __init__(self
, filename
=None):
113 """ Load pci.ids from file to internal data structure.
114 parameter 'filename' can specify location of this file
117 self
.filename
= filename
119 self
.filename
= PCI
.filename
122 if self
.cache
and not PCI
.devices
:
126 f
= open(self
.filename
, encoding
='ISO8859-1')
130 for line
in f
.readlines():
132 if line
.startswith('#'):
136 elif line
.startswith('\t\t'):
138 elif line
.startswith('\t'):
139 device
= l
[0].lower()
140 device_name
= ' '.join(l
[1:])
141 PCI
.devices
[vendor
][1][device
] = device_name
143 vendor
= l
[0].lower()
144 vendor_name
= ' '.join(l
[1:])
145 if not vendor
in list(PCI
.devices
.keys()):
146 PCI
.devices
[vendor
] = [vendor_name
, {}]
147 else: # this should not happen
148 PCI
.devices
[vendor
][0] = vendor_name
150 def get_vendor(self
, vendor
):
151 """ Return description of vendor. Parameter is two byte code in hexa.
152 If vendor is unknown None is returned.
154 vendor
= vendor
.lower()
156 if vendor
in list(PCI
.devices
.keys()):
157 return PCI
.devices
[vendor
][0]
161 raise # not implemented yet
163 def get_device(self
, vendor
, device
):
164 """ Return description of device. Parameters are two byte code variables in hexa.
165 If device is unknown None is returned.
167 vendor
= vendor
.lower()
168 device
= device
.lower()
170 if vendor
in list(PCI
.devices
.keys()):
171 if device
in list(PCI
.devices
[vendor
][1].keys()):
172 return PCI
.devices
[vendor
][1][device
]
178 raise # not implemented yet
181 """ Interace to pnp.ids from hwdata package """
182 filename
= '/usr/share/hwdata/pnp.ids'
185 def __init__(self
, filename
=None):
186 """ Load pnp.ids from file to internal data structure.
187 parameter 'filename' can specify location of this file
190 self
.filename
= filename
192 self
.filename
= PNP
.filename
195 if self
.cache
and not PNP
.VENDORS
:
199 f
= open(self
.filename
, encoding
='ISO8859-1')
202 for line
in f
.readlines():
204 if line
.startswith('#'):
209 vendor_id
= l
[0].upper()
210 PNP
.VENDORS
[vendor_id
] = ' '.join(l
[1:])
212 def get_vendor(self
, vendor_id
):
213 """ Return description of vendor. Parameter is 3 character long id of vendor.
214 If vendor is unknown None is returned.
216 vendor_id
= vendor_id
.upper()
218 if vendor_id
in list(PNP
.VENDORS
.keys()):
219 return PNP
.VENDORS
[vendor_id
]
223 raise # not implemented yet