aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntonio Gallo <tonicucoz@gmail.com>2011-04-27 21:35:00 +0000
committerAntonio Gallo <tonicucoz@gmail.com>2011-04-27 21:35:00 +0000
commitf7b8505501a7ad129499c26830bb47a06882e745 (patch)
treec0db1752d00a545efa588655ab3640dae35a618f
parent341a9123d6669d57a5cdeb7bd8a4ce3926909449 (diff)
h-client: USB printers listed in the device tree in the client
-rw-r--r--h-client/credits.txt3
-rw-r--r--h-client/hclient.py4
-rw-r--r--h-client/hlibrary.py96
-rwxr-xr-xh-client/img/devices/big/printer.pngbin0 -> 2004 bytes
-rwxr-xr-xh-client/img/devices/small/printer.pngbin0 -> 877 bytes
5 files changed, 87 insertions, 16 deletions
diff --git a/h-client/credits.txt b/h-client/credits.txt
index e772eff..c272430 100644
--- a/h-client/credits.txt
+++ b/h-client/credits.txt
@@ -5,11 +5,12 @@ icons taken from the H2O Icon Theme 0.0.5 (http://kde-look.org/content/show.php/
img/devices/small/unknown.png
img/devices/small/soundcard.png
img/devices/small/wifi.png
+img/devices/small/printer.png
img/devices/big/unknown.png
img/devices/big/soundcard.png
img/devices/big/wifi.png
-
+img/devices/big/printer.png
icons taken from the Crystal Projects icons (http://www.everaldo.com/crystal/?action=downloads), licensed under the LGPL license
diff --git a/h-client/hclient.py b/h-client/hclient.py
index 1dc6135..ab15ce2 100644
--- a/h-client/hclient.py
+++ b/h-client/hclient.py
@@ -679,11 +679,15 @@ class hclient:
self.treestore = gtk.TreeStore(str,str,int,gtk.gdk.Pixbuf,int)
pci = self.treestore.append(None, ["Your PCI Devices","",800,gtk.gdk.pixbuf_new_from_file('img/title_png.png'),4])
+ usb = self.treestore.append(None, ["Your USB Devices","",800,gtk.gdk.pixbuf_new_from_file('img/title_png.png'),4])
for key,dev in self.client.devices.iteritems():
if key[0] == 'p':
self.treestore.append(pci, [dev[0].getType(),key,400,gtk.gdk.pixbuf_new_from_file('img/devices/small/'+dev[0].getIcon()),4])
+ if key[0] == 'u':
+ self.treestore.append(usb, [dev[0].getType(),key,400,gtk.gdk.pixbuf_new_from_file('img/devices/small/'+dev[0].getIcon()),4])
+
selection = self.tree.get_selection()
selection.connect('changed', self.setCurrentDevice)
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
diff --git a/h-client/img/devices/big/printer.png b/h-client/img/devices/big/printer.png
new file mode 100755
index 0000000..b857d9e
--- /dev/null
+++ b/h-client/img/devices/big/printer.png
Binary files differ
diff --git a/h-client/img/devices/small/printer.png b/h-client/img/devices/small/printer.png
new file mode 100755
index 0000000..6e110de
--- /dev/null
+++ b/h-client/img/devices/small/printer.png
Binary files differ