From 341a9123d6669d57a5cdeb7bd8a4ce3926909449 Mon Sep 17 00:00:00 2001 From: Antonio Gallo Date: Wed, 27 Apr 2011 00:32:59 +0000 Subject: h-client: improved the parsing of the lsusb command --- h-client/hlibrary.py | 53 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 3 deletions(-) (limited to 'h-client/hlibrary.py') diff --git a/h-client/hlibrary.py b/h-client/hlibrary.py index f0e84d6..500ac79 100644 --- a/h-client/hlibrary.py +++ b/h-client/hlibrary.py @@ -562,18 +562,64 @@ class Client: else: self.errors.append('tmp folder not writable') - #parse the poutput of the lspci command + + #parse the output of the lspci command if not os.system('lsusb -v > tmp/temp'): f = open('tmp/temp','r') + deviceDict = {} + while 1: row = f.readline() - - print row + crow = row.replace("\n","").lstrip().rstrip() if not row: break + #clear pid and vid if a new device has been found + if row.find('Device Descriptor:') != -1 and row.find('HID Device Descriptor:') == -1: + deviceDict = {} + + #find the vendor + if crow.find('idVendor') != -1: + #print crow + res = re.match('idVendor(.*)0x([a-zA-Z0-9]{4})(.*)',crow,re.I) + if res: + deviceDict['vendorId'] = res.group(2).lstrip().rstrip() + deviceDict['vendorName'] = res.group(3).lstrip().rstrip() + + #find the product + if crow.find('idProduct') != -1: + #print crow + res = re.match('idProduct(.*)0x([a-zA-Z0-9]{4})(.*)',crow,re.I) + if res: + deviceDict['productId'] = res.group(2).lstrip().rstrip() + deviceDict['productName'] = res.group(3).lstrip().rstrip() + + #find the class + if crow.find('bInterfaceClass') != -1: + #print crow + res = re.match('bInterfaceClass([\s]*)([0-9]*)(.*)',crow,re.I) + if res: + deviceDict['classId'] = res.group(2).lstrip().rstrip() + deviceDict['className'] = res.group(3).lstrip().rstrip() + + #find the subclass + if crow.find('bInterfaceSubClass') != -1: + #print crow + res = re.match('bInterfaceSubClass([\s]*)([0-9]*)(.*)',crow,re.I) + if res: + deviceDict['subclassId'] = res.group(2).lstrip().rstrip() + deviceDict['subclassName'] = res.group(3).lstrip().rstrip() + + #find the protocol + if crow.find('bInterfaceProtocol') != -1: + #print crow + res = re.match('bInterfaceProtocol([\s]*)([0-9]*)(.*)',crow,re.I) + if res: + deviceDict['protocolId'] = res.group(2).lstrip().rstrip() + deviceDict['protocolName'] = res.group(3).lstrip().rstrip() + f.close(); else: self.errors.append('tmp folder not writable') @@ -638,6 +684,7 @@ class Client: #print modelName dev[0].setModel(modelName) dev[0].setInterface(interface) + dev[0].setDistributions([]) dev[0].addDistributions(distribution) dev[0].setHowItWorks(works) dev[0].setYear(year) -- cgit v1.2.3