]>
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. """
20 # pylint: disable=misplaced-bare-raise
23 """ Interace to usb.ids from hwdata package """
24 filename
= '/usr/share/misc/usb.ids'
27 def __init__(self
, filename
=None):
28 """ Load pci.ids from file to internal data structure.
29 parameter 'filename' can specify location of this file
32 self
.filename
= filename
34 self
.filename
= USB
.filename
37 if self
.cache
and not USB
.devices
:
41 f
= open(self
.filename
, encoding
='ISO8859-1')
47 for line
in f
.readlines():
50 if line
.startswith('#'):
51 if line
.startswith('# List of known device classes, subclasses and protocols'):
52 break # end of database of devices, rest is protocols, types etc.
57 elif line
.startswith('\t\t'):
58 interface_id
= l
[0].lower()
60 interface_name
= ' '.join(l
[1:])
64 USB
.devices
[vendor
][1][device
][0][interface_id
] = interface_name
66 sys
.stderr
.write("Unknown line at line {0} in {1}.\n".format(lineno
, self
.filename
))
67 elif line
.startswith('\t'):
69 device_name
= ' '.join(l
[1:])
70 USB
.devices
[vendor
][1][device
] = [device_name
, {}]
73 vendor_name
= ' '.join(l
[1:])
74 if vendor
not in USB
.devices
:
75 USB
.devices
[vendor
] = [vendor_name
, {}]
76 else: # this should not happen
77 USB
.devices
[vendor
][0] = vendor_name
79 def get_vendor(self
, vendor
):
80 """ Return description of vendor. Parameter is two byte code in hexa.
81 If vendor is unknown None is returned.
83 vendor
= vendor
.lower()
85 if vendor
in USB
.devices
:
86 return USB
.devices
[vendor
][0]
90 raise # not implemented yet
92 def get_device(self
, vendor
, device
):
93 """ Return description of device. Parameters are two byte code variables in hexa.
94 If device is unknown None is returned.
96 vendor
= vendor
.lower()
97 device
= device
.lower()
99 if vendor
in USB
.devices
:
100 if device
in USB
.devices
[vendor
][1]:
101 return USB
.devices
[vendor
][1][device
][0]
107 raise # not implemented yet
110 """ Interace to pci.ids from hwdata package """
111 filename
= '/usr/share/misc/pci.ids'
114 def __init__(self
, filename
=None):
115 """ Load pci.ids from file to internal data structure.
116 parameter 'filename' can specify location of this file
119 self
.filename
= filename
121 self
.filename
= PCI
.filename
124 if self
.cache
and not PCI
.devices
:
128 f
= open(self
.filename
, encoding
='ISO8859-1')
132 for line
in f
.readlines():
134 if line
.startswith('#'):
138 elif line
.startswith('\t\t'):
140 elif line
.startswith('\t'):
141 device
= l
[0].lower()
142 device_name
= ' '.join(l
[1:])
143 PCI
.devices
[vendor
][1][device
] = device_name
145 vendor
= l
[0].lower()
146 vendor_name
= ' '.join(l
[1:])
147 if not vendor
in list(PCI
.devices
.keys()):
148 PCI
.devices
[vendor
] = [vendor_name
, {}]
149 else: # this should not happen
150 PCI
.devices
[vendor
][0] = vendor_name
152 def get_vendor(self
, vendor
):
153 """ Return description of vendor. Parameter is two byte code in hexa.
154 If vendor is unknown None is returned.
156 vendor
= vendor
.lower()
158 if vendor
in list(PCI
.devices
.keys()):
159 return PCI
.devices
[vendor
][0]
163 raise # not implemented yet
165 def get_device(self
, vendor
, device
):
166 """ Return description of device. Parameters are two byte code variables in hexa.
167 If device is unknown None is returned.
169 vendor
= vendor
.lower()
170 device
= device
.lower()
172 if vendor
in list(PCI
.devices
.keys()):
173 if device
in list(PCI
.devices
[vendor
][1].keys()):
174 return PCI
.devices
[vendor
][1][device
]
180 raise # not implemented yet
183 """ Interace to pnp.ids from hwdata package """
184 filename
= '/usr/share/hwdata/pnp.ids'
187 def __init__(self
, filename
=None):
188 """ Load pnp.ids from file to internal data structure.
189 parameter 'filename' can specify location of this file
192 self
.filename
= filename
194 self
.filename
= PNP
.filename
197 if self
.cache
and not PNP
.VENDORS
:
201 f
= open(self
.filename
, encoding
='ISO8859-1')
204 for line
in f
.readlines():
206 if line
.startswith('#'):
211 vendor_id
= l
[0].upper()
212 PNP
.VENDORS
[vendor_id
] = ' '.join(l
[1:])
214 def get_vendor(self
, vendor_id
):
215 """ Return description of vendor. Parameter is 3 character long id of vendor.
216 If vendor is unknown None is returned.
218 vendor_id
= vendor_id
.upper()
220 if vendor_id
in list(PNP
.VENDORS
.keys()):
221 return PNP
.VENDORS
[vendor_id
]
225 raise # not implemented yet