aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntonio Gallo <tonicucoz@gmail.com>2011-03-13 22:11:07 +0000
committerAntonio Gallo <tonicucoz@gmail.com>2011-03-13 22:11:07 +0000
commit5d9649f5af2d7d30c86d6fb0698090b2500c29be (patch)
treebce5e45452385a72e57f88a2347509db76ce40d0
parentd72ddb0f0211ea854292d445ac184a7b4bbe07b8 (diff)
hlibrary python library: now the user distribution is automatically selected
-rw-r--r--h-client/hlibrary.py126
1 files changed, 85 insertions, 41 deletions
diff --git a/h-client/hlibrary.py b/h-client/hlibrary.py
index 6e8f66f..8e3dd89 100644
--- a/h-client/hlibrary.py
+++ b/h-client/hlibrary.py
@@ -28,24 +28,30 @@ from xml.dom import minidom
class Device(object):
- _allowedDistros = {
- 'blag_90001' : 'BLAG 90001',
- 'blag_120000' : 'BLAG 120000',
- 'dragora_1_1' : 'Dragora 1.1',
- 'dragora_2_0' : 'Dragora 2.0 Ardi',
- 'dynebolic_2_5_2' : 'Dynebolic 2.5.2 DHORUBA',
- 'gnewsense_2_3' : 'gNewSense 2.3 Deltah',
- 'gnewsense_3_0' : 'gNewSense 3.0 Metad',
- 'musix_2_0' : 'Musix GNU+Linux 2.0 R0',
- 'trisquel_3_5' : 'Trisquel 3.5 Awen',
- 'trisquel_4_0' : 'Trisquel 4.0 Taranis',
- 'trisquel_4_5' : 'Trisquel 4.5 Slaine',
- 'ututo_xs_2009' : 'UTUTO XS 2009',
- 'ututo_xs_2010' : 'UTUTO XS 2010',
- 'venenux_0_8' : 'VENENUX 0.8',
- 'venenux_0_8_2' : 'VENENUX-EC 0.8.2'
+ _distrosTable = {
+ 'awen' : 'trisquel_3_5',
+ 'taranis' : 'trisquel_4_0',
+ 'slaine' : 'trisquel_4_5'
}
+ #_allowedDistros = {
+ #'blag_90001' : 'BLAG 90001',
+ #'blag_120000' : 'BLAG 120000',
+ #'dragora_1_1' : 'Dragora 1.1',
+ #'dragora_2_0' : 'Dragora 2.0 Ardi',
+ #'dynebolic_2_5_2' : 'Dynebolic 2.5.2 DHORUBA',
+ #'gnewsense_2_3' : 'gNewSense 2.3 Deltah',
+ #'gnewsense_3_0' : 'gNewSense 3.0 Metad',
+ #'musix_2_0' : 'Musix GNU+Linux 2.0 R0',
+ #'trisquel_3_5' : 'Trisquel 3.5 Awen',
+ #'trisquel_4_0' : 'Trisquel 4.0 Taranis',
+ #'trisquel_4_5' : 'Trisquel 4.5 Slaine',
+ #'ututo_xs_2009' : 'UTUTO XS 2009',
+ #'ututo_xs_2010' : 'UTUTO XS 2010',
+ #'venenux_0_8' : 'VENENUX 0.8',
+ #'venenux_0_8_2' : 'VENENUX-EC 0.8.2'
+ #}
+
_status = True
errors = []
@@ -56,14 +62,14 @@ class Device(object):
self._vendor = None
self._model = None
self._kernel = None
- self._distributions = None
+ self._distributions = self.userDistribution()
self._interface = 'not-specified'
self._year = 'not-specified'
self._vendorId = None
self._productId = None
self._howItWorks = None
self._driver = ''
- self._description = None
+ self._description = ''
def setPost(self):
self._post['model'] = self._model;
@@ -76,6 +82,35 @@ class Device(object):
self._post['driver'] = self._driver;
+ #get the distro h-source allowed code from the distro codename
+ def getDistroCode(self,codenameString):
+ codenames = self._distrosTable.keys()
+ for codename in codenames:
+ if codenameString.find(codename) != -1:
+ return self._distrosTable[codename]
+ return ''
+
+ #add a distribution to the comma-separated list of distros
+ def addDistribution(self,distroName):
+ distros = self._distributions.split(',')
+ distros.append(distroName)
+ #remove duplicates
+ distros = list(set(distros))
+ self._distributions = ','.join(distros)
+ #correct a strange behaviour
+ if self._distributions[0] == ',':
+ self._distributions = self._distributions[1:]
+
+ def userDistribution(self):
+ if not os.system('cat /etc/*-release | grep CODENAME > tmp/temp'):
+ f = open('tmp/temp','r')
+ row = f.readline().replace("\n","").lower()
+ return self.getDistroCode(row)
+ f.close();
+ else:
+ self._status = False
+ self.errors.append('tmp folder not writable')
+
def getType(self):
return self._type
@@ -125,15 +160,6 @@ class Device(object):
self._kernel = kernel
def setDistributions(self,distributions):
- distArray = distributions.split(',');
-
- allowedDistKeys = self._allowedDistros.keys()
-
- for dist in distArray:
- if dist not in allowedDistKeys:
- self._status = False
- self.errors.append('distribution ' + dist + ' not allowed')
-
self._distributions = distributions
def setInterface(self,interface):
@@ -167,7 +193,8 @@ class Videocard(Device):
def __init__(self):
super(Videocard, self).__init__()
- self._type = 'videocard';
+ self._type = 'videocard'
+ self._howItWorks = 'does_not_work'
def setPost(self):
super(Videocard, self).setPost()
@@ -177,7 +204,8 @@ class Wifi(Device):
def __init__(self):
super(Wifi, self).__init__()
- self._type = 'wifi';
+ self._type = 'wifi'
+ self._howItWorks = 'no'
def setPost(self):
super(Wifi, self).setPost()
@@ -187,7 +215,8 @@ class Soundcard(Device):
def __init__(self):
super(Soundcard, self).__init__()
- self._type = 'soundcard';
+ self._type = 'soundcard'
+ self._howItWorks = 'no'
def setPost(self):
super(Soundcard, self).setPost()
@@ -411,7 +440,10 @@ class Client:
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
- description = device.getElementsByTagName("description")[0].childNodes[0].data
+
+ if device.getElementsByTagName("description")[0].hasChildNodes():
+ description = device.getElementsByTagName("description")[0].childNodes[0].data
+ dev[0].setDescription(description)
#print modelName
dev[0].setModel(modelName)
@@ -419,7 +451,6 @@ class Client:
dev[0].setDistributions(distribution)
dev[0].setHowItWorks(works)
dev[0].setYear(year)
- dev[0].setDescription(description)
dev[2] = 'update'
dev[3] = idDevice
@@ -427,21 +458,28 @@ class Client:
for key,dev in self.devices.iteritems():
dev[0].setPost()
post = dev[0].getPost()
+
+ #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 node controller
- controller = self.getController(dev[1])
- #get the device id (inside the node database)
+
post['id_hard'] = dev[3]
post['updateAction'] = 'update'
- #get the user info
- info = self.getUserInfo()
- token = info['token']
url = controller + '/update/en/' + token
- self.request.setPost(post)
- self.request.perform(url.encode('utf-8'))
- #print self.request.contents
+ elif dev[2] == 'insert':
+
+ post['insertAction'] = 'insert'
+ url = controller + '/insert/en/' + token
+ self.request.setPost(post)
+ self.request.perform(url.encode('utf-8'))
+ #print self.request.contents
#d = Videocard()
@@ -464,6 +502,12 @@ client.sync()
#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('','')