/usr/lib/python2.7/dist-packages/isenkram/usb.py is in isenkram-cli 0.36.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | #!/usr/bin/python
# Copyright (C) 2016 Petter Reinholdtsen <pere@hungry.com>
#
# Licensed under the GNU General Public License Version 2
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
__author__ = "Petter Reinholdtsen <pere@hungry.com>"
import re
class usbdb:
'''Easy access to the USB vendor and product database.'''
_dbfiles = [
'/var/lib/usbutils/usb.ids',
'/usr/share/misc/usb.ids',
]
def __init__(self):
self.vendors = {}
self.products = {}
for f in self._dbfiles:
try:
with open(f) as db:
lastvendor = None
for line in db.readlines():
if re.match('^#', line): continue # Skip comments
line = line.rstrip()
if re.match('^C ', line): break # Done parsing products
m = re.match('^([0-9a-f]{4})\s+(\S.*)$', line)
if m:
lastvendor = m.group(1)
self.vendors[lastvendor] = m.group(2)
else:
m = re.match('^\t([0-9a-f]{4})\s+(\S.*)$', line)
if m:
self.products["%s:%s" % (lastvendor, m.group(1))] \
= m.group(2)
return
except IOError, e:
pass
def product(self, vendorid, productid):
vendorname = productname = None
if "%04x" % vendorid in self.vendors:
vendorname = self.vendors["%04x" % vendorid]
id = "%04x:%04x" % (vendorid, productid)
if id in self.products:
productname = self.products[id]
info = {
'vendorid' : vendorid,
'productid' : productid,
'vendorname' : vendorname,
'productname' : productname,
}
return info
def main():
db = usbdb()
info = db.product(0x0694, 0x0002)
print info
if __name__ == '__main__':
main()
|