diff options
-rw-r--r-- | h-client/hclient.py | 35 | ||||
-rw-r--r-- | h-client/hlibrary.py | 79 |
2 files changed, 79 insertions, 35 deletions
diff --git a/h-client/hclient.py b/h-client/hclient.py index af5dc65..f042076 100644 --- a/h-client/hclient.py +++ b/h-client/hclient.py @@ -89,8 +89,7 @@ class hclient: self.applyButton.set_sensitive(True) self.resetButton.set_sensitive(True) - if self.client.isLogged(): - self.submitButton.set_sensitive(True) + self.updateStatus() else: #make non sensitive the apply button @@ -99,6 +98,7 @@ class hclient: self.submitButton.set_sensitive(False) self.currentDevice = None self.currentDeviceCode = None + self.updateStatus() #set the pyGTK device entries @@ -214,6 +214,20 @@ class hclient: #self.printErrors() self.loginWindow.destroy() + #submit data to the server + def submit(self,widget): + self.applyChanges(None) + + if self.client.isLogged(): + result = self.client.submit(self.currentDeviceCode) + self.printErrors() + else: + self.client.errors.append("you are not logged") + self.updateStatus() + + self.licenseNoticeWindow.destroy() + + #logout to the server def logout(self,widget): self.client.logout() @@ -224,6 +238,10 @@ class hclient: def closeLoginWindow(self,widget): self.loginWindow.destroy() + #close the license notice window + def closeLicenseNoticeWindow(self,widget): + self.licenseNoticeWindow.destroy() + #start the window containing the license notice def openLicenseNoticeWindow(self,widget): #window for preferences @@ -250,6 +268,11 @@ class hclient: sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_NEVER) noticeText = gtk.TextView() + #noticeText.set_decorated(False) + noticeText.set_editable(False) + #noticeText.modify_base(gtk.STATE_NORMAL, gtk.gdk.Color(50,100,150) ) + noticeText.modify_base(gtk.STATE_NORMAL, gtk.gdk.color_parse("#a3a3a3") ) + noticeText.set_wrap_mode(gtk.WRAP_CHAR) textbuffer = gtk.TextBuffer(table=None) @@ -266,8 +289,8 @@ class hclient: hbox.set_border_width(10) applyButton = gtk.Button(stock=gtk.STOCK_APPLY) closeButton = gtk.Button(stock=gtk.STOCK_CLOSE) - #applyButton.connect("clicked", self.login) - #closeButton.connect("clicked", self.closeLoginWindow) + applyButton.connect("clicked", self.submit) + closeButton.connect("clicked", self.closeLicenseNoticeWindow) hbox.pack_end(applyButton, False, True, 0) hbox.pack_end(closeButton, False, True, 3) vbox.pack_start(hbox, False, True, 0) @@ -397,7 +420,7 @@ class hclient: self.errorBarHBox = gtk.HBox(False, 0) for error in self.client.errors: - label = gtk.Label("error: " + error) + label = gtk.Label(error) self.errorBarHBox.pack_start(label, False, True, 10) self.errorBar.add_with_viewport(self.errorBarHBox) @@ -520,7 +543,7 @@ class hclient: self.treestore = gtk.TreeStore(str,str,int) - pci = self.treestore.append(None, ["PCI Devices","",800]) + pci = self.treestore.append(None, ["Your PCI Devices","",800]) for key,dev in self.client.devices.iteritems(): if key[0] == 'p': diff --git a/h-client/hlibrary.py b/h-client/hlibrary.py index 974fced..8388984 100644 --- a/h-client/hlibrary.py +++ b/h-client/hlibrary.py @@ -113,7 +113,7 @@ class Device(object): self._post['comm_year'] = self._year; self._post['pci_id'] = self._vendorId + ':' + self._productId; self._post['interface'] = self._interface; - self._post['description'] = self.htmlentitiesDecode(self._description.replace("\n","\r\n")); + self._post['description'] = self._description.replace("\n","\r\n"); self._post['driver'] = self._driver; #replace the HTML entitites with utf-8 characters @@ -143,8 +143,9 @@ class Device(object): dis = ' , '.join(cleanDistros) #correct a strange python behaviour - if dis[0] == ' , ': - dis = dis[3:] + if dis != '': + if dis[0] == ' , ': + dis = dis[3:] return dis #add a distribution @@ -436,7 +437,13 @@ class Client: #log out def logout(self): - self.request.perform('users/logout/en') + result = self.request.perform('users/logout/en') + + if result: + return True + else: + self.errors.append("unable to connect to server") + return False #get info about the user logged def getUserInfo(self): @@ -458,15 +465,14 @@ class Client: return {'status':status,'username':username,'token':token,'groups':groups} else: - self._status = False self.errors.append("unable to connect to server") - return -1 + return False #return True if the user is logged, else return False def isLogged(self): info = self.getUserInfo() - if info != -1: + if info != False: if info['status'] == 'logged': return True @@ -481,7 +487,7 @@ class Client: return notice else: self.errors.append("unable to connect to server") - return -1 + return False def createDevices(self): @@ -585,7 +591,7 @@ class Client: if device.getElementsByTagName("description")[0].hasChildNodes(): description = device.getElementsByTagName("description")[0].childNodes[0].data.encode('utf-8') - dev[0].setDescription(description) + dev[0].setDescription(dev[0].htmlentitiesDecode(description)) else: dev[0].setDescription('') @@ -611,30 +617,45 @@ class Client: else: self._status = False self.errors.append("unable to connect to server") - - def submit(self): + + + def submit(self,deviceCode = None): for key,dev in self.devices.iteritems(): - dev[0].setPost() - post = dev[0].getPost() + if key == deviceCode or deviceCode == None: + dev[0].setPost() + post = dev[0].getPost() - #get the node controller - controller = self.getController(dev[1]) + #get the node controller + controller = self.getController(dev[1]) - #get the user info - info = self.getUserInfo() - token = info['token'] - - if dev[2] == 'update': + #get the user info + info = self.getUserInfo() + token = info['token'] + + post['from_client'] = 'yes' - post['id_hard'] = dev[3] - post['updateAction'] = 'update' - url = controller + '/update/en/' + token + if dev[2] == 'update': - elif dev[2] == 'insert': + post['id_hard'] = dev[3] + post['updateAction'] = 'update' + url = controller + '/update/en/' + token - post['insertAction'] = 'insert' - url = controller + '/insert/en/' + token + elif dev[2] == 'insert': - self.request.setPost(post) - self.request.perform(url.encode('utf-8')) - #print self.request.contents
\ No newline at end of file + post['insertAction'] = 'insert' + url = controller + '/insert/en/' + token + + self.request.setPost(post) + self.request.perform(url.encode('utf-8')) + + #parse the response + xmldoc = minidom.parseString(self.request.contents) + deviceType = 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': + return True + else: + return False
\ No newline at end of file |