aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--h-client/hclient.py6
-rw-r--r--h-client/hlibrary.py141
2 files changed, 78 insertions, 69 deletions
diff --git a/h-client/hclient.py b/h-client/hclient.py
index f042076..d6141c6 100644
--- a/h-client/hclient.py
+++ b/h-client/hclient.py
@@ -218,7 +218,7 @@ class hclient:
def submit(self,widget):
self.applyChanges(None)
- if self.client.isLogged():
+ if self.client.isLogged() == True:
result = self.client.submit(self.currentDeviceCode)
self.printErrors()
else:
@@ -432,11 +432,11 @@ class hclient:
#check if the user is logged
#hide or show the login/logout buttons
def updateStatus(self):
- if self.client.isLogged():
+ if self.client.isLogged() == True:
self.loginButton.hide()
self.logoutButton.show()
info = self.client.getUserInfo()
- if info != False:
+ if info == True:
self.statusLabel.set_markup("<i>hello</i> <b>"+info['username']+"</b>, <i>you are logged in</i>")
if self.currentDeviceCode != None:
diff --git a/h-client/hlibrary.py b/h-client/hlibrary.py
index 8388984..46454ea 100644
--- a/h-client/hlibrary.py
+++ b/h-client/hlibrary.py
@@ -425,14 +425,15 @@ class Client:
result = self.request.perform('users/login/en')
self.request.setPost(None)
if result:
- if self.isLogged():
- return True
- else:
- self.errors.append("wrong username or password")
+ result_login = self.isLogged()
+ if result_login != -2:
+ if result_login:
+ return True
+ else:
+ self.errors.append("wrong username or password")
else:
self.errors.append("unable to connect to server")
- return -1
-
+
return False
#log out
@@ -450,20 +451,23 @@ class Client:
result = self.request.perform('client/userinfo/en')
if result:
- xmldoc = minidom.parseString(self.request.contents)
- status = xmldoc.getElementsByTagName("status")[0].childNodes[0].data
+ try:
+ xmldoc = minidom.parseString(self.request.contents)
+ status = xmldoc.getElementsByTagName("status")[0].childNodes[0].data
- username = ''
- token = ''
- groups = ''
+ username = ''
+ token = ''
+ groups = ''
- if status == 'logged':
- username = xmldoc.getElementsByTagName("username")[0].childNodes[0].data
- token = xmldoc.getElementsByTagName("token")[0].childNodes[0].data
- groups = xmldoc.getElementsByTagName("groups")[0].childNodes[0].data
+ if status == 'logged':
+ username = xmldoc.getElementsByTagName("username")[0].childNodes[0].data
+ token = xmldoc.getElementsByTagName("token")[0].childNodes[0].data
+ groups = xmldoc.getElementsByTagName("groups")[0].childNodes[0].data
- return {'status':status,'username':username,'token':token,'groups':groups}
-
+ return {'status':status,'username':username,'token':token,'groups':groups}
+ except:
+ self.errors.append("the server is not up-to-date: unable to parse the xml database")
+ return -2
else:
self.errors.append("unable to connect to server")
return False
@@ -473,8 +477,11 @@ class Client:
info = self.getUserInfo()
if info != False:
- if info['status'] == 'logged':
- return True
+ if info != -2:
+ if info['status'] == 'logged':
+ return True
+ else:
+ return -2
return False
@@ -553,7 +560,7 @@ class Client:
self.request.contents = ''
result = self.request.perform('download/all/en')
-
+ #print result
if result:
#loop the found devices
@@ -568,54 +575,56 @@ class Client:
#self.request.contents = ''
#result = self.request.perform('download/' + controller + '/en')
-
+
#parse the xml database
- xmldoc = minidom.parseString(self.request.contents)
- devices = xmldoc.getElementsByTagName("device")
- for device in devices:
-
- #check it is not a notebook
- deviceType = device.getElementsByTagName("type")[0].childNodes[0].data.encode('utf-8')
-
- if deviceType != 'notebook':
- code = device.getElementsByTagName("vendorid_productid")[0]
- if code.hasChildNodes():
- if (code.childNodes[0].data == vendorid_productid):
-
- modelName = device.getElementsByTagName("model_name")[0].childNodes[0].data.encode('utf-8')
- 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')
- year = device.getElementsByTagName("year")[0].childNodes[0].data.encode('utf-8')
-
- if device.getElementsByTagName("description")[0].hasChildNodes():
- description = device.getElementsByTagName("description")[0].childNodes[0].data.encode('utf-8')
- dev[0].setDescription(dev[0].htmlentitiesDecode(description))
- else:
- dev[0].setDescription('')
-
- if device.getElementsByTagName("kernel_libre")[0].hasChildNodes():
- kernel_libre = device.getElementsByTagName("kernel_libre")[0].childNodes[0].data.encode('utf-8')
- dev[0].setKernel(kernel_libre)
-
- #driverNode = device.getElementsByTagName("driver")[0]
- #if driverNode:
- #if driverNode.hasChildNodes():
- #driver = driverNode.childNodes[0].data.encode('utf-8')
- #dev[0].setDriver(driver)
-
-
- #print modelName
- dev[0].setModel(modelName)
- dev[0].setInterface(interface)
- dev[0].addDistributions(distribution)
- dev[0].setHowItWorks(works)
- dev[0].setYear(year)
- dev[2] = 'update'
- dev[3] = idDevice
+ try:
+ xmldoc = minidom.parseString(self.request.contents)
+ devices = xmldoc.getElementsByTagName("device")
+ for device in devices:
+
+ #check it is not a notebook
+ deviceType = device.getElementsByTagName("type")[0].childNodes[0].data.encode('utf-8')
+
+ if deviceType != 'notebook':
+ code = device.getElementsByTagName("vendorid_productid")[0]
+ if code.hasChildNodes():
+ if (code.childNodes[0].data == vendorid_productid):
+
+ modelName = device.getElementsByTagName("model_name")[0].childNodes[0].data.encode('utf-8')
+ 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')
+ year = device.getElementsByTagName("year")[0].childNodes[0].data.encode('utf-8')
+
+ if device.getElementsByTagName("description")[0].hasChildNodes():
+ description = device.getElementsByTagName("description")[0].childNodes[0].data.encode('utf-8')
+ dev[0].setDescription(dev[0].htmlentitiesDecode(description))
+ else:
+ dev[0].setDescription('')
+
+ if device.getElementsByTagName("kernel_libre")[0].hasChildNodes():
+ kernel_libre = device.getElementsByTagName("kernel_libre")[0].childNodes[0].data.encode('utf-8')
+ dev[0].setKernel(kernel_libre)
+
+ #driverNode = device.getElementsByTagName("driver")[0]
+ #if driverNode:
+ #if driverNode.hasChildNodes():
+ #driver = driverNode.childNodes[0].data.encode('utf-8')
+ #dev[0].setDriver(driver)
+
+
+ #print modelName
+ dev[0].setModel(modelName)
+ dev[0].setInterface(interface)
+ dev[0].addDistributions(distribution)
+ dev[0].setHowItWorks(works)
+ dev[0].setYear(year)
+ dev[2] = 'update'
+ dev[3] = idDevice
+ except:
+ self.errors.append("the server is not up-to-date: unable to parse the xml database")
else:
- self._status = False
self.errors.append("unable to connect to server")