aboutsummaryrefslogtreecommitdiff
path: root/h-client/hlibrary.py
diff options
context:
space:
mode:
Diffstat (limited to 'h-client/hlibrary.py')
-rw-r--r--h-client/hlibrary.py118
1 files changed, 78 insertions, 40 deletions
diff --git a/h-client/hlibrary.py b/h-client/hlibrary.py
index c08239f..415b04b 100644
--- a/h-client/hlibrary.py
+++ b/h-client/hlibrary.py
@@ -304,6 +304,9 @@ class Mycurl:
self.contents = ''
self.setDomain(domain)
+ def getStatus(self):
+ return self._status
+
def setDomain(self,domain):
self.domain = domain
#check if the trailing slash is present
@@ -320,6 +323,7 @@ class Mycurl:
def body_callback(self, buf):
self.contents = self.contents + buf
+ #perform the HTTP request
def perform(self,requestUri = ''):
self.url = self.domain + requestUri;
@@ -332,8 +336,15 @@ class Mycurl:
if self._post != None:
c.setopt(c.POSTFIELDS, urllib.urlencode(self._post))
c.setopt(c.WRITEFUNCTION, self.body_callback)
+
c.perform()
+
+ result = False
+ if c.getinfo(c.HTTP_CODE) == 200:
+ result = True
+
c.close()
+ return result
class Client:
@@ -496,47 +507,74 @@ class Client:
#syncronize with the xml database
def sync(self):
- #loop the found devices
- for key,dev in self.devices.iteritems():
- #find the class
- Class = dev[1]
- vendorid_productid = key[2:]
- #find the controller
- controller = self.getController(Class)
-
- #perform an http request
- self.request.contents = ''
- self.request.perform('download/' + controller + '/en')
-
- #parse the xml database
- xmldoc = minidom.parseString(self.request.contents)
- devices = xmldoc.getElementsByTagName("device")
- for device in devices:
-
- 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(description)
-
- #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
+ #perform an http request
+ self.request.contents = ''
+
+ result = self.request.perform('download/all/en')
+
+ if result:
+
+ #loop the found devices
+ for key,dev in self.devices.iteritems():
+ #find the class
+ #Class = dev[1]
+ vendorid_productid = key[2:]
+ #find the controller
+ #controller = self.getController(Class)
+
+ ##perform an http request
+ #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(description)
+
+ 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
+ else:
+ self._status = False
+ self.errors.append("couldn't connect to host")
+
def submit(self):
for key,dev in self.devices.iteritems():
dev[0].setPost()