PHP 8.2.30
Preview: hwdata.py Size: 7.95 KB
//usr/lib/python3.6/site-packages/hwdata.py

#
# Copyright (c) 1999--2012 Red Hat, Inc.
#
# This software is licensed to you under the GNU General Public License,
# version 2 (GPLv2). There is NO WARRANTY for this software, express or
# implied, including the implied warranties of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
# along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
#
# Red Hat trademarks are not licensed under GPLv2. No permission is
# granted to use or replicate Red Hat trademarks that are incorporated
# in this software or its documentation.
#
import sys
inPy3k = sys.version_info[0] == 3

""" Query hwdata database and return decription of vendor and/or device. """

# pylint: disable=misplaced-bare-raise

class USB(object):
    """ Interace to usb.ids from hwdata package """
    filename = '/usr/share/hwdata/usb.ids'
    devices = None

    def __init__(self, filename=None):
        """ Load pci.ids from file to internal data structure.
            parameter 'filename' can specify location of this file
        """
        if filename:
            self.filename = filename
        else:
            self.filename = USB.filename
        self.cache = 1

        if self.cache and not USB.devices:
            # parse usb.ids
            USB.devices = {}
            if inPy3k:
                f = open(self.filename, encoding='ISO8859-1')
            else:
                f = open(self.filename)
            lineno = 0
            vendor = None
            device = None
            for line in f.readlines():
                lineno += 1
                l = line.split()
                if line.startswith('#'):
                    if line.startswith('# List of known device classes, subclasses and protocols'):
                        break # end of database of devices, rest is protocols, types etc.
                    else:
                        continue
                elif len(l) == 0:
                    continue
                elif line.startswith('\t\t'):
                    interface_id = l[0].lower()
                    if len(l) > 2:
                        interface_name = ' '.join(l[1:])
                    else:
                        interface_name = ''
                    try:
                        USB.devices[vendor][1][device][0][interface_id] = interface_name
                    except TypeError:
                        sys.stderr.write("Unknown line at line {0} in {1}.\n".format(lineno, self.filename))
                elif line.startswith('\t'):
                    device = l[0].lower()
                    device_name = ' '.join(l[1:])
                    USB.devices[vendor][1][device] = [device_name, {}]
                else:
                    vendor = l[0].lower()
                    vendor_name = ' '.join(l[1:])
                    if vendor not in USB.devices:
                        USB.devices[vendor] = [vendor_name, {}]
                    else: # this should not happen
                        USB.devices[vendor][0] = vendor_name

    def get_vendor(self, vendor):
        """ Return description of vendor. Parameter is two byte code in hexa.
            If vendor is unknown None is returned.
        """
        vendor = vendor.lower()
        if self.cache:
            if vendor in USB.devices:
                return USB.devices[vendor][0]
            else:
                return None
        else:
            raise # not implemented yet

    def get_device(self, vendor, device):
        """ Return description of device. Parameters are two byte code variables in hexa.
            If device is unknown None is returned.
        """
        vendor = vendor.lower()
        device = device.lower()
        if self.cache:
            if vendor in USB.devices:
                if device in USB.devices[vendor][1]:
                    return USB.devices[vendor][1][device][0]
                else:
                    return None
            else:
                return None
        else:
            raise # not implemented yet

class PCI(object):
    """ Interace to pci.ids from hwdata package """
    filename = '/usr/share/hwdata/pci.ids'
    devices = None

    def __init__(self, filename=None):
        """ Load pci.ids from file to internal data structure.
            parameter 'filename' can specify location of this file
        """
        if filename:
            self.filename = filename
        else:
            self.filename = PCI.filename
        self.cache = 1

        if self.cache and not PCI.devices:
            # parse pci.ids
            PCI.devices = {}
            if inPy3k:
                f = open(self.filename, encoding='ISO8859-1')
            else:
                f = open(self.filename)
            vendor = None
            for line in f.readlines():
                l = line.split()
                if line.startswith('#'):
                    continue
                elif len(l) == 0:
                    continue
                elif line.startswith('\t\t'):
                    continue
                elif line.startswith('\t'):
                    device = l[0].lower()
                    device_name = ' '.join(l[1:])
                    PCI.devices[vendor][1][device] = device_name
                else:
                    vendor = l[0].lower()
                    vendor_name = ' '.join(l[1:])
                    if not vendor in  list(PCI.devices.keys()):
                        PCI.devices[vendor] = [vendor_name, {}]
                    else: # this should not happen
                        PCI.devices[vendor][0] = vendor_name

    def get_vendor(self, vendor):
        """ Return description of vendor. Parameter is two byte code in hexa.
            If vendor is unknown None is returned.
        """
        vendor = vendor.lower()
        if self.cache:
            if vendor in list(PCI.devices.keys()):
                return PCI.devices[vendor][0]
            else:
                return None
        else:
            raise # not implemented yet

    def get_device(self, vendor, device):
        """ Return description of device. Parameters are two byte code variables in hexa.
            If device is unknown None is returned.
        """
        vendor = vendor.lower()
        device = device.lower()
        if self.cache:
            if vendor in list(PCI.devices.keys()):
                if device in list(PCI.devices[vendor][1].keys()):
                    return PCI.devices[vendor][1][device]
                else:
                    return None
            else:
                return None
        else:
            raise # not implemented yet

class PNP(object):
    """ Interace to pnp.ids from hwdata package """
    filename = '/usr/share/hwdata/pnp.ids'
    VENDORS = None

    def __init__(self, filename=None):
        """ Load pnp.ids from file to internal data structure.
            parameter 'filename' can specify location of this file
        """
        if filename:
            self.filename = filename
        else:
            self.filename = PNP.filename
        self.cache = 1

        if self.cache and not PNP.VENDORS:
            # parse pnp.ids
            PNP.VENDORS = {}
            if inPy3k:
                f = open(self.filename, encoding='ISO8859-1')
            else:
                f = open(self.filename)
            for line in f.readlines():
                l = line.split()
                if line.startswith('#'):
                    continue
                elif len(l) == 0:
                    continue
                else:
                    vendor_id = l[0].upper()
                    PNP.VENDORS[vendor_id] = ' '.join(l[1:])

    def get_vendor(self, vendor_id):
        """ Return description of vendor. Parameter is 3 character long id of vendor.
            If vendor is unknown None is returned.
        """
        vendor_id = vendor_id.upper()
        if self.cache:
            if vendor_id in list(PNP.VENDORS.keys()):
                return PNP.VENDORS[vendor_id]
            else:
                return None
        else:
            raise # not implemented yet

Directory Contents

Dirs: 47 × Files: 14

Name Size Perms Modified Actions
chardet DIR
- drwxr-xr-x 2024-03-03 19:12:31
Edit Download
- drwxr-xr-x 2024-03-03 19:12:31
Edit Download
dateutil DIR
- drwxr-xr-x 2024-03-03 19:11:31
Edit Download
- drwxr-xr-x 2024-03-03 19:11:22
Edit Download
dnf DIR
- drwxr-xr-x 2025-03-13 07:09:55
Edit Download
- drwxr-xr-x 2025-07-25 07:00:48
Edit Download
- drwxr-xr-x 2024-06-15 07:05:20
Edit Download
dns DIR
- drwxr-xr-x 2024-06-15 07:05:45
Edit Download
- drwxr-xr-x 2024-06-15 07:05:45
Edit Download
firewall DIR
- drwxr-xr-x 2025-03-13 07:09:54
Edit Download
html2text DIR
- drwxr-xr-x 2025-04-16 09:56:27
Edit Download
- drwxr-xr-x 2025-04-16 09:56:27
Edit Download
idna DIR
- drwxr-xr-x 2024-07-04 07:01:53
Edit Download
- drwxr-xr-x 2024-07-04 07:01:53
Edit Download
iotop DIR
- drwxr-xr-x 2024-06-15 07:05:44
Edit Download
isc DIR
- drwxr-xr-x 2025-11-07 16:33:23
Edit Download
nftables DIR
- drwxr-xr-x 2025-01-30 08:10:22
Edit Download
OpenSSL DIR
- drwxr-xr-x 2024-03-03 19:12:33
Edit Download
pip DIR
- drwxr-xr-x 2024-06-15 07:03:53
Edit Download
- drwxr-xr-x 2024-06-15 07:03:53
Edit Download
- drwxr-xr-x 2025-07-17 07:18:27
Edit Download
ply DIR
- drwxr-xr-x 2024-03-03 19:12:32
Edit Download
- drwxr-xr-x 2024-03-03 19:12:32
Edit Download
procfs DIR
- drwxr-xr-x 2024-06-15 07:03:57
Edit Download
pycparser DIR
- drwxr-xr-x 2024-03-03 19:12:32
Edit Download
- drwxr-xr-x 2024-03-03 19:12:32
Edit Download
- drwxr-xr-x 2024-03-03 19:12:33
Edit Download
- drwxr-xr-x 2024-03-03 19:12:33
Edit Download
- drwxr-xr-x 2024-03-03 19:12:34
Edit Download
- drwxr-xr-x 2024-03-03 19:11:31
Edit Download
- drwxr-xr-x 2024-06-15 07:03:57
Edit Download
pyudev DIR
- drwxr-xr-x 2024-03-03 19:11:31
Edit Download
- drwxr-xr-x 2024-03-03 19:11:31
Edit Download
requests DIR
- drwxr-xr-x 2025-08-06 21:33:47
Edit Download
- drwxr-xr-x 2025-08-06 21:33:47
Edit Download
rhn DIR
- drwxr-xr-x 2025-05-29 13:47:19
Edit Download
- drwxr-xr-x 2025-07-17 07:18:27
Edit Download
- drwxr-xr-x 2025-07-17 07:18:27
Edit Download
- drwxr-xr-x 2024-03-03 19:11:10
Edit Download
slip DIR
- drwxr-xr-x 2024-03-03 19:12:32
Edit Download
- drwxr-xr-x 2025-07-17 07:18:28
Edit Download
- drwxr-xr-x 2025-07-17 07:18:28
Edit Download
tuned DIR
- drwxr-xr-x 2025-03-13 07:10:07
Edit Download
- drwxr-xr-x 2025-07-18 07:00:48
Edit Download
urllib3 DIR
- drwxr-xr-x 2026-01-29 22:33:26
Edit Download
- drwxr-xr-x 2026-01-29 22:33:26
Edit Download
- drwxr-xr-x 2026-03-24 13:15:18
Edit Download
16.18 KB lrw-r--r-- 2018-01-14 10:00:21
Edit Download
126 B lrw-r--r-- 2025-07-15 09:13:40
Edit Download
7.95 KB lrw-r--r-- 2018-02-12 08:49:28
Edit Download
348 B lrw-r--r-- 2024-04-06 14:56:52
Edit Download
267 B lrw-r--r-- 2025-11-06 07:45:03
Edit Download
623 B lrw-r--r-- 2025-01-28 01:24:56
Edit Download
242 B lrw-r--r-- 2019-11-19 06:36:19
Edit Download
224.48 KB lrw-r--r-- 2019-11-13 10:36:46
Edit Download
343 B lrw-r--r-- 2024-09-17 10:10:55
Edit Download
30.16 KB lrw-r--r-- 2019-11-13 14:45:19
Edit Download
196 B lrw-r--r-- 2022-10-08 13:05:12
Edit Download
269 B lrw-r--r-- 2022-10-08 13:05:12
Edit Download
31.52 KB lrw-r--r-- 2017-12-21 04:05:00
Edit Download
2.84 KB lrw-r--r-- 2017-12-21 04:05:00
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).