From b7a2393f9e78cf708e4c0d7e3858c8b646835a09 Mon Sep 17 00:00:00 2001 From: Antonio Gallo Date: Tue, 15 Mar 2011 22:36:00 +0000 Subject: improved the way the distribution entry is created --- h-client/hlibrary.py | 71 ++++++++++++++++------------------------------------ h-client/test.py | 49 ++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 49 deletions(-) create mode 100644 h-client/test.py (limited to 'h-client') diff --git a/h-client/hlibrary.py b/h-client/hlibrary.py index 4ec7bef..1a86d81 100644 --- a/h-client/hlibrary.py +++ b/h-client/hlibrary.py @@ -29,6 +29,8 @@ from xml.dom import minidom class Device(object): _distrosTable = { + 'deltah' : 'gnewsense_2_3', + 'metad' : 'gnewsense_3_0', 'awen' : 'trisquel_3_5', 'taranis' : 'trisquel_4_0', 'slaine' : 'trisquel_4_5' @@ -62,7 +64,7 @@ class Device(object): self._vendor = None self._model = None self._kernel = None - self._distributions = self.userDistribution() + self._distributions = [self.userDistribution()] self._interface = 'not-specified' self._year = 'not-specified' self._vendorId = None @@ -74,7 +76,7 @@ class Device(object): def setPost(self): self._post['model'] = self._model; self._post['kernel'] = self._kernel; - self._post['distribution'] = self._distributions; + self._post['distribution'] = self.createDistroEntry(); self._post['comm_year'] = self._year; self._post['pci_id'] = self._vendorId + ':' + self._productId; self._post['interface'] = self._interface; @@ -90,18 +92,25 @@ class Device(object): return self._distrosTable[codename] return '' - #add a distribution - def addDistribution(self,distroName): - distros = self._distributions.split(',') - distros.append(distroName.lstrip().rstrip()) + def createDistroEntry(self): + cleanDistros = [] + for distro in self._distributions: + cleanDistros.append(distro.lstrip().rstrip()) #remove duplicates - #distros = list(set(distros)) - - self._distributions = ' , '.join(distros) - #correct a strange behaviour - if self._distributions[0] == ' , ': - self._distributions = self._distributions[3:] + cleanDistros = list(set(cleanDistros)) + #sort the elements + cleanDistros = sorted(cleanDistros) + + dis = ' , '.join(cleanDistros) + #correct a strange python behaviour + if dis[0] == ' , ': + dis = dis[3:] + return dis + + #add a distribution + def addDistribution(self,distroName): + self._distributions.append(distroName) #add many distributions #distroList: comma separated list of distros @@ -488,40 +497,4 @@ class Client: self.request.setPost(post) self.request.perform(url.encode('utf-8')) - #print self.request.contents - -#d = Videocard() - -#d.setVendor('Acer') -#print d.getType() -#d.setDistributions('trisquel_4_0,gnewsense'); -#print d.getStatus() - -client = Client('http://h-source/') -client.createDevices() -#client.request.perform('download/all/it') -#print client.request.url -client.sync() - -#for key,dev in client.devices.iteritems(): - #print key - #print dev[0].getModel() - #print dev[0].getDistributions() - #print dev[0].getYear() - #print dev[3] - #print dev[0].getHowItWorks() - #print dev[0].getDescription()+"\n"+"\n" - #dev[0].addDistribution('taranis') - #dev[0].addDistribution('metad') - #dev[0].addDistribution('gingo') - #dev[0].addDistribution('taranis') - #print dev[0].getDistributions() - #print dev[0].userDistribution() - - -client.login('','') -#print client.isLogged() -client.submit() -client.logout() -#client.devices['p_14e4:4311'][0].setPost() -#print client.devices['p_14e4:4311'][0].getPost() \ No newline at end of file + #print self.request.contents \ No newline at end of file diff --git a/h-client/test.py b/h-client/test.py new file mode 100644 index 0000000..ca13ee7 --- /dev/null +++ b/h-client/test.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# hlibrary, a python library to manage the database of an h-source node +# Copyright (C) 2011 Antonio Gallo +# +# +# hlibrary is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# hlibrary is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with hlibrary. If not, see . + +from hlibrary import * + +client = Client('http://h-source/') +client.createDevices() +#client.request.perform('download/all/it') +#print client.request.url +client.sync() + +#for key,dev in client.devices.iteritems(): + #print key + #print dev[0].getModel() + #print dev[0].getDistributions() + #print dev[0].getYear() + #print dev[3] + #print dev[0].getHowItWorks() + #print dev[0].getDescription()+"\n"+"\n" + #dev[0].addDistribution('taranis') + #dev[0].addDistribution('metad') + #dev[0].addDistribution('gingo') + #dev[0].addDistribution('taranis') + #print dev[0].getDistributions() + #print dev[0].userDistribution() + + +client.login('','') +#print client.isLogged() +client.submit() +client.logout() + +#client.devices['p_14e4:4311'][0].setPost() +#print client.devices['p_14e4:4311'][0].getPost() \ No newline at end of file -- cgit v1.2.3