From d6272a60687f2e62218e036eb05fb127301d3a27 Mon Sep 17 00:00:00 2001 From: Antonio Gallo Date: Tue, 15 Mar 2011 14:00:54 +0000 Subject: improved the way distribution are retrieved --- h-client/hlibrary.py | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) (limited to 'h-client') diff --git a/h-client/hlibrary.py b/h-client/hlibrary.py index 8e3dd89..4ec7bef 100644 --- a/h-client/hlibrary.py +++ b/h-client/hlibrary.py @@ -90,16 +90,25 @@ class Device(object): return self._distrosTable[codename] return '' - #add a distribution to the comma-separated list of distros + #add a distribution def addDistribution(self,distroName): distros = self._distributions.split(',') - distros.append(distroName) + distros.append(distroName.lstrip().rstrip()) + #remove duplicates - distros = list(set(distros)) - self._distributions = ','.join(distros) + #distros = list(set(distros)) + + self._distributions = ' , '.join(distros) #correct a strange behaviour - if self._distributions[0] == ',': - self._distributions = self._distributions[1:] + if self._distributions[0] == ' , ': + self._distributions = self._distributions[3:] + + #add many distributions + #distroList: comma separated list of distros + def addDistributions(self,distroList): + distros = distroList.split(',') + for distro in distros: + self.addDistribution(distro) def userDistribution(self): if not os.system('cat /etc/*-release | grep CODENAME > tmp/temp'): @@ -434,21 +443,21 @@ class Client: if code.hasChildNodes(): if (code.childNodes[0].data == vendorid_productid): - modelName = device.getElementsByTagName("model_name")[0].childNodes[0].data - interface = device.getElementsByTagName("interface")[0].childNodes[0].data - distribution = device.getElementsByTagName("distribution")[0].childNodes[0].data - idDevice = device.getElementsByTagName("id")[0].childNodes[0].data - works = device.getElementsByTagName("it_works")[0].childNodes[0].data - year = device.getElementsByTagName("year")[0].childNodes[0].data + 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 + 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].setDistributions(distribution) + dev[0].addDistributions(distribution) dev[0].setHowItWorks(works) dev[0].setYear(year) dev[2] = 'update' -- cgit v1.2.3