aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntonio Gallo <tonicucoz@gmail.com>2011-04-27 00:32:59 +0000
committerAntonio Gallo <tonicucoz@gmail.com>2011-04-27 00:32:59 +0000
commit341a9123d6669d57a5cdeb7bd8a4ce3926909449 (patch)
tree435c48afcff3c1e469fd25908cfc9a32040d6cdc
parent118909b4774b47d0b84446e20fd8a6aeed1eabf7 (diff)
h-client: improved the parsing of the lsusb command
-rw-r--r--h-client/hlibrary.py53
1 files changed, 50 insertions, 3 deletions
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)