Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../lib/python3..../site-pac...
File: hwdata.py
#
[0] Fix | Delete
# Copyright (c) 1999--2012 Red Hat, Inc.
[1] Fix | Delete
#
[2] Fix | Delete
# This software is licensed to you under the GNU General Public License,
[3] Fix | Delete
# version 2 (GPLv2). There is NO WARRANTY for this software, express or
[4] Fix | Delete
# implied, including the implied warranties of MERCHANTABILITY or FITNESS
[5] Fix | Delete
# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
[6] Fix | Delete
# along with this software; if not, see
[7] Fix | Delete
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
[8] Fix | Delete
#
[9] Fix | Delete
# Red Hat trademarks are not licensed under GPLv2. No permission is
[10] Fix | Delete
# granted to use or replicate Red Hat trademarks that are incorporated
[11] Fix | Delete
# in this software or its documentation.
[12] Fix | Delete
#
[13] Fix | Delete
import sys
[14] Fix | Delete
inPy3k = sys.version_info[0] == 3
[15] Fix | Delete
[16] Fix | Delete
""" Query hwdata database and return decription of vendor and/or device. """
[17] Fix | Delete
[18] Fix | Delete
# pylint: disable=misplaced-bare-raise
[19] Fix | Delete
[20] Fix | Delete
class USB(object):
[21] Fix | Delete
""" Interace to usb.ids from hwdata package """
[22] Fix | Delete
filename = '/usr/share/hwdata/usb.ids'
[23] Fix | Delete
devices = None
[24] Fix | Delete
[25] Fix | Delete
def __init__(self, filename=None):
[26] Fix | Delete
""" Load pci.ids from file to internal data structure.
[27] Fix | Delete
parameter 'filename' can specify location of this file
[28] Fix | Delete
"""
[29] Fix | Delete
if filename:
[30] Fix | Delete
self.filename = filename
[31] Fix | Delete
else:
[32] Fix | Delete
self.filename = USB.filename
[33] Fix | Delete
self.cache = 1
[34] Fix | Delete
[35] Fix | Delete
if self.cache and not USB.devices:
[36] Fix | Delete
# parse usb.ids
[37] Fix | Delete
USB.devices = {}
[38] Fix | Delete
if inPy3k:
[39] Fix | Delete
f = open(self.filename, encoding='ISO8859-1')
[40] Fix | Delete
else:
[41] Fix | Delete
f = open(self.filename)
[42] Fix | Delete
lineno = 0
[43] Fix | Delete
vendor = None
[44] Fix | Delete
device = None
[45] Fix | Delete
for line in f.readlines():
[46] Fix | Delete
lineno += 1
[47] Fix | Delete
l = line.split()
[48] Fix | Delete
if line.startswith('#'):
[49] Fix | Delete
if line.startswith('# List of known device classes, subclasses and protocols'):
[50] Fix | Delete
break # end of database of devices, rest is protocols, types etc.
[51] Fix | Delete
else:
[52] Fix | Delete
continue
[53] Fix | Delete
elif len(l) == 0:
[54] Fix | Delete
continue
[55] Fix | Delete
elif line.startswith('\t\t'):
[56] Fix | Delete
interface_id = l[0].lower()
[57] Fix | Delete
if len(l) > 2:
[58] Fix | Delete
interface_name = ' '.join(l[1:])
[59] Fix | Delete
else:
[60] Fix | Delete
interface_name = ''
[61] Fix | Delete
try:
[62] Fix | Delete
USB.devices[vendor][1][device][0][interface_id] = interface_name
[63] Fix | Delete
except TypeError:
[64] Fix | Delete
sys.stderr.write("Unknown line at line {0} in {1}.\n".format(lineno, self.filename))
[65] Fix | Delete
elif line.startswith('\t'):
[66] Fix | Delete
device = l[0].lower()
[67] Fix | Delete
device_name = ' '.join(l[1:])
[68] Fix | Delete
USB.devices[vendor][1][device] = [device_name, {}]
[69] Fix | Delete
else:
[70] Fix | Delete
vendor = l[0].lower()
[71] Fix | Delete
vendor_name = ' '.join(l[1:])
[72] Fix | Delete
if vendor not in USB.devices:
[73] Fix | Delete
USB.devices[vendor] = [vendor_name, {}]
[74] Fix | Delete
else: # this should not happen
[75] Fix | Delete
USB.devices[vendor][0] = vendor_name
[76] Fix | Delete
[77] Fix | Delete
def get_vendor(self, vendor):
[78] Fix | Delete
""" Return description of vendor. Parameter is two byte code in hexa.
[79] Fix | Delete
If vendor is unknown None is returned.
[80] Fix | Delete
"""
[81] Fix | Delete
vendor = vendor.lower()
[82] Fix | Delete
if self.cache:
[83] Fix | Delete
if vendor in USB.devices:
[84] Fix | Delete
return USB.devices[vendor][0]
[85] Fix | Delete
else:
[86] Fix | Delete
return None
[87] Fix | Delete
else:
[88] Fix | Delete
raise # not implemented yet
[89] Fix | Delete
[90] Fix | Delete
def get_device(self, vendor, device):
[91] Fix | Delete
""" Return description of device. Parameters are two byte code variables in hexa.
[92] Fix | Delete
If device is unknown None is returned.
[93] Fix | Delete
"""
[94] Fix | Delete
vendor = vendor.lower()
[95] Fix | Delete
device = device.lower()
[96] Fix | Delete
if self.cache:
[97] Fix | Delete
if vendor in USB.devices:
[98] Fix | Delete
if device in USB.devices[vendor][1]:
[99] Fix | Delete
return USB.devices[vendor][1][device][0]
[100] Fix | Delete
else:
[101] Fix | Delete
return None
[102] Fix | Delete
else:
[103] Fix | Delete
return None
[104] Fix | Delete
else:
[105] Fix | Delete
raise # not implemented yet
[106] Fix | Delete
[107] Fix | Delete
class PCI(object):
[108] Fix | Delete
""" Interace to pci.ids from hwdata package """
[109] Fix | Delete
filename = '/usr/share/hwdata/pci.ids'
[110] Fix | Delete
devices = None
[111] Fix | Delete
[112] Fix | Delete
def __init__(self, filename=None):
[113] Fix | Delete
""" Load pci.ids from file to internal data structure.
[114] Fix | Delete
parameter 'filename' can specify location of this file
[115] Fix | Delete
"""
[116] Fix | Delete
if filename:
[117] Fix | Delete
self.filename = filename
[118] Fix | Delete
else:
[119] Fix | Delete
self.filename = PCI.filename
[120] Fix | Delete
self.cache = 1
[121] Fix | Delete
[122] Fix | Delete
if self.cache and not PCI.devices:
[123] Fix | Delete
# parse pci.ids
[124] Fix | Delete
PCI.devices = {}
[125] Fix | Delete
if inPy3k:
[126] Fix | Delete
f = open(self.filename, encoding='ISO8859-1')
[127] Fix | Delete
else:
[128] Fix | Delete
f = open(self.filename)
[129] Fix | Delete
vendor = None
[130] Fix | Delete
for line in f.readlines():
[131] Fix | Delete
l = line.split()
[132] Fix | Delete
if line.startswith('#'):
[133] Fix | Delete
continue
[134] Fix | Delete
elif len(l) == 0:
[135] Fix | Delete
continue
[136] Fix | Delete
elif line.startswith('\t\t'):
[137] Fix | Delete
continue
[138] Fix | Delete
elif line.startswith('\t'):
[139] Fix | Delete
device = l[0].lower()
[140] Fix | Delete
device_name = ' '.join(l[1:])
[141] Fix | Delete
PCI.devices[vendor][1][device] = device_name
[142] Fix | Delete
else:
[143] Fix | Delete
vendor = l[0].lower()
[144] Fix | Delete
vendor_name = ' '.join(l[1:])
[145] Fix | Delete
if not vendor in list(PCI.devices.keys()):
[146] Fix | Delete
PCI.devices[vendor] = [vendor_name, {}]
[147] Fix | Delete
else: # this should not happen
[148] Fix | Delete
PCI.devices[vendor][0] = vendor_name
[149] Fix | Delete
[150] Fix | Delete
def get_vendor(self, vendor):
[151] Fix | Delete
""" Return description of vendor. Parameter is two byte code in hexa.
[152] Fix | Delete
If vendor is unknown None is returned.
[153] Fix | Delete
"""
[154] Fix | Delete
vendor = vendor.lower()
[155] Fix | Delete
if self.cache:
[156] Fix | Delete
if vendor in list(PCI.devices.keys()):
[157] Fix | Delete
return PCI.devices[vendor][0]
[158] Fix | Delete
else:
[159] Fix | Delete
return None
[160] Fix | Delete
else:
[161] Fix | Delete
raise # not implemented yet
[162] Fix | Delete
[163] Fix | Delete
def get_device(self, vendor, device):
[164] Fix | Delete
""" Return description of device. Parameters are two byte code variables in hexa.
[165] Fix | Delete
If device is unknown None is returned.
[166] Fix | Delete
"""
[167] Fix | Delete
vendor = vendor.lower()
[168] Fix | Delete
device = device.lower()
[169] Fix | Delete
if self.cache:
[170] Fix | Delete
if vendor in list(PCI.devices.keys()):
[171] Fix | Delete
if device in list(PCI.devices[vendor][1].keys()):
[172] Fix | Delete
return PCI.devices[vendor][1][device]
[173] Fix | Delete
else:
[174] Fix | Delete
return None
[175] Fix | Delete
else:
[176] Fix | Delete
return None
[177] Fix | Delete
else:
[178] Fix | Delete
raise # not implemented yet
[179] Fix | Delete
[180] Fix | Delete
class PNP(object):
[181] Fix | Delete
""" Interace to pnp.ids from hwdata package """
[182] Fix | Delete
filename = '/usr/share/hwdata/pnp.ids'
[183] Fix | Delete
VENDORS = None
[184] Fix | Delete
[185] Fix | Delete
def __init__(self, filename=None):
[186] Fix | Delete
""" Load pnp.ids from file to internal data structure.
[187] Fix | Delete
parameter 'filename' can specify location of this file
[188] Fix | Delete
"""
[189] Fix | Delete
if filename:
[190] Fix | Delete
self.filename = filename
[191] Fix | Delete
else:
[192] Fix | Delete
self.filename = PNP.filename
[193] Fix | Delete
self.cache = 1
[194] Fix | Delete
[195] Fix | Delete
if self.cache and not PNP.VENDORS:
[196] Fix | Delete
# parse pnp.ids
[197] Fix | Delete
PNP.VENDORS = {}
[198] Fix | Delete
if inPy3k:
[199] Fix | Delete
f = open(self.filename, encoding='ISO8859-1')
[200] Fix | Delete
else:
[201] Fix | Delete
f = open(self.filename)
[202] Fix | Delete
for line in f.readlines():
[203] Fix | Delete
l = line.split()
[204] Fix | Delete
if line.startswith('#'):
[205] Fix | Delete
continue
[206] Fix | Delete
elif len(l) == 0:
[207] Fix | Delete
continue
[208] Fix | Delete
else:
[209] Fix | Delete
vendor_id = l[0].upper()
[210] Fix | Delete
PNP.VENDORS[vendor_id] = ' '.join(l[1:])
[211] Fix | Delete
[212] Fix | Delete
def get_vendor(self, vendor_id):
[213] Fix | Delete
""" Return description of vendor. Parameter is 3 character long id of vendor.
[214] Fix | Delete
If vendor is unknown None is returned.
[215] Fix | Delete
"""
[216] Fix | Delete
vendor_id = vendor_id.upper()
[217] Fix | Delete
if self.cache:
[218] Fix | Delete
if vendor_id in list(PNP.VENDORS.keys()):
[219] Fix | Delete
return PNP.VENDORS[vendor_id]
[220] Fix | Delete
else:
[221] Fix | Delete
return None
[222] Fix | Delete
else:
[223] Fix | Delete
raise # not implemented yet
[224] Fix | Delete
[225] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function