From f7b8505501a7ad129499c26830bb47a06882e745 Mon Sep 17 00:00:00 2001 From: Antonio Gallo Date: Wed, 27 Apr 2011 21:35:00 +0000 Subject: h-client: USB printers listed in the device tree in the client --- h-client/hlibrary.py | 96 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 81 insertions(+), 15 deletions(-) (limited to 'h-client/hlibrary.py') diff --git a/h-client/hlibrary.py b/h-client/hlibrary.py index 500ac79..7523e35 100644 --- a/h-client/hlibrary.py +++ b/h-client/hlibrary.py @@ -284,7 +284,20 @@ class Soundcard(Device): super(Soundcard, self).setPost() self._post['sound_card_works'] = self._howItWorks +class Printer(Device): + def __init__(self): + super(Printer, self).__init__() + self._type = 'printer' + self._howItWorks = 'C-None' + self._interfaces = ['not-specified','USB','Serial','Parallel','Firewire','SCSI','Ethernet'] + self._howItWorksOptions = ['A-Full','B-Partial','C-None'] + self._icon = 'printer.png' + + def setPost(self): + super(Printer, self).setPost() + self._post['compatibility'] = self._howItWorks + #class to carry out http requests by means of pycurl class Mycurl: @@ -361,6 +374,26 @@ class Client: '0300' : { 'type' : 'videocard', 'controller': 'videocards' + }, + '070100' : { + 'type' : 'printer', + 'controller': 'printers' + }, + '070101' : { + 'type' : 'printer', + 'controller': 'printers' + }, + '070102' : { + 'type' : 'printer', + 'controller': 'printers' + }, + '070103' : { + 'type' : 'printer', + 'controller': 'printers' + }, + '0701ff' : { + 'type' : 'printer', + 'controller': 'printers' } } @@ -422,6 +455,8 @@ class Client: return Wifi() elif Class == '0300': return Videocard() + elif Class == '070100' or Class == '070101' or Class == '070102' or Class == '070103' or Class == '0701ff': + return Printer() else: return None @@ -508,6 +543,11 @@ class Client: self.errors.append("unable to connect to server") return False + + def addLeadingZero(self,string): + if len(string) == 1: + return '0'+string + def createDevices(self): #parse the poutput of the lspci command @@ -568,6 +608,8 @@ class Client: f = open('tmp/temp','r') deviceDict = {} + + keyNumber = 0 while 1: row = f.readline() @@ -578,49 +620,68 @@ class Client: #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 = {} + keyNumber = keyNumber + 1 + keyString = str(keyNumber) + deviceDict[keyString] = {} #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() + deviceDict[keyString]['vendorId'] = res.group(2).lstrip().rstrip() + deviceDict[keyString]['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() + deviceDict[keyString]['productId'] = res.group(2).lstrip().rstrip() + deviceDict[keyString]['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() + deviceDict[keyString]['classId'] = self.addLeadingZero(res.group(2).lstrip().rstrip()) + deviceDict[keyString]['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() + deviceDict[keyString]['subclassId'] = self.addLeadingZero(res.group(2).lstrip().rstrip()) + deviceDict[keyString]['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() - + deviceDict[keyString]['protocolId'] = self.addLeadingZero(res.group(2).lstrip().rstrip()) + deviceDict[keyString]['protocolName'] = res.group(3).lstrip().rstrip() + + f.close(); + + #create the USB devices + for key,value in deviceDict.iteritems(): + Class = str(value['classId']) + str(value['subclassId']) + str(value['protocolId']) + #get the USB object + dev = self.getObject(Class) + if dev: + dev.setType(self.getType(Class)) + dev.setVendorId(value['vendorId']) + dev.setProductId(value['productId']) + dev.setModel(value['productName']) + + dev.setKernel(self.getKernel()) + + self.devices['u_' + dev.getVendorId() + ':' + dev.getProductId()] = [dev,Class,'insert','0'] + else: self.errors.append('tmp folder not writable') @@ -662,7 +723,12 @@ class Client: interface = device.getElementsByTagName("interface")[0].childNodes[0].data.encode('utf-8') distribution = device.getElementsByTagName("distribution")[0].childNodes[0].data.encode('utf-8') idDevice = device.getElementsByTagName("id")[0].childNodes[0].data.encode('utf-8') - works = device.getElementsByTagName("it_works")[0].childNodes[0].data.encode('utf-8') + + if deviceType == 'printer': + works = device.getElementsByTagName("compatibility")[0].childNodes[0].data.encode('utf-8') + else: + works = device.getElementsByTagName("it_works")[0].childNodes[0].data.encode('utf-8') + year = device.getElementsByTagName("year")[0].childNodes[0].data.encode('utf-8') if device.getElementsByTagName("description")[0].hasChildNodes(): @@ -727,12 +793,12 @@ class Client: #parse the response xmldoc = minidom.parseString(self.request.contents) - deviceType = xmldoc.getElementsByTagName("status")[0].childNodes[0].data.encode('utf-8') + response = xmldoc.getElementsByTagName("status")[0].childNodes[0].data.encode('utf-8') notice = xmldoc.getElementsByTagName("notice")[0].childNodes[1].data.encode('utf-8') self.errors.append(notice.lstrip().rstrip()) - if deviceType == 'executed': + if response == 'executed': return True else: return False \ No newline at end of file -- cgit v1.2.3