Package medite :: Package Donnees :: Module donneesInformations
[hide private]
[frames] | no frames]

Source Code for Module medite.Donnees.donneesInformations

  1  # -*- coding: iso-8859-1 -*- 
  2  # Copyright 20003 - 2008: Julien Bourdaillet (julien.bourdaillet@lip6.fr), Jean-Gabriel Ganascia (jean-gabriel.ganascia@lip6.fr) 
  3  # This file is part of MEDITE. 
  4  # 
  5  #    MEDITE is free software; you can redistribute it and/or modify 
  6  #    it under the terms of the GNU General Public License as published by 
  7  #    the Free Software Foundation; either version 2 of the License, or 
  8  #    (at your option) any later version. 
  9  # 
 10  #    MEDITE is distributed in the hope that it will be useful, 
 11  #    but WITHOUT ANY WARRANTY; without even the implied warranty of 
 12  #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 13  #    GNU General Public License for more details. 
 14  # 
 15  #    You should have received a copy of the GNU General Public License 
 16  #    along with Foobar; if not, write to the Free Software 
 17  #    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
 18  #---------------------------------------------------------------------------- 
 19  # Nom:          donneesInformations.py 
 20  # Objet:        Classe qui accede aux fichier xml 
 21  #---------------------------------------------------------------------------- 
 22   
 23  from xml.dom.minidom import * 
 24  #from xml.dom.pulldom import * 
 25  #import os, sys, gc 
 26  from string import * 
 27   
 28  from Donnees.informations import * 
 29  from Donnees.commentaire import * 
 30  from Donnees.transformations import * 
 31  from Donnees.resultatAppli import * 
 32  from Donnees.donnees import * 
 33  from Utile.constantesDonnees import * 
 34  from Utile.exceptionsDonnees import * 
 35  from Utile.codageXml import * 
 36  from Donnees.planTravail import * 
 37  from Donnees.arbre import * 
 38  from Controleurs.cMedite import * 
 39  import traceback 
 40   
41 -class DonneesInformations:
42 43 # Methode qui renvoie vrai si des informations existent sur un couple de etats
44 - def existeInformations(self, pCheminInfos, pVersionSource, pEtatSource, 45 pVersionCible, pEtatCible, pParametres):
46 tmp1 = '%s'%pParametres.getp1() 47 tmp2 = '%s'%pParametres.getp2() 48 tmp3 = '%s'%pParametres.getp3() 49 tmp4 = '%s'%pParametres.getp4() 50 tmp5 = '%s'%pParametres.getp5() 51 tmp6 = '%s'%pParametres.getp6() 52 tmp7 = '%s'%pParametres.getp7() 53 # sys.stderr.write("\nexisteInformations "+pParametres.toString()) 54 # sys.stderr.flush() 55 # Ouverture du fichier "informations" 56 # On recupere dans fic les informations du fichier Informations.xml dont 57 # le chemin est passe en parametre 58 fic = lireDocXml(pCheminInfos) 59 liste = fic.getElementsByTagName(B_INFORMATIONS) 60 for node in liste : 61 if (node.getAttribute(B_VERS_SOURCE)== pVersionSource and 62 node.getAttribute(B_ETAT_SOURCE)== pEtatSource and 63 node.getAttribute(B_VERS_CIBLE) == pVersionCible and 64 node.getAttribute(B_ETAT_CIBLE) == pEtatCible and 65 node.getAttribute(B_PARAM_1) == tmp1 and 66 node.getAttribute(B_PARAM_2) == tmp2 and 67 node.getAttribute(B_PARAM_3) == tmp3 and 68 node.getAttribute(B_PARAM_4) == tmp4 and 69 node.getAttribute(B_PARAM_5) == tmp5 and 70 node.getAttribute(B_PARAM_6) == tmp6 and 71 node.getAttribute(B_PARAM_7) == tmp7): 72 # sys.stderr.write("existe \n") 73 # sys.stderr.flush() 74 return 1 ## VRAI 75 # sys.stderr.write("existe pas \n") 76 # sys.stderr.flush() 77 return 0 ## FAUX
78 79 # Methode qui enregistre les transformations d'un couple de etats
80 - def enregistrerTransformations(self, pCheminInfos, pVersionSource, pEtatSource, 81 pVersionCible, pEtatCible, 82 pParametres, pTransformations):
83 ## print 'dans donneesInformations.enregistrerTransformations' 84 if not self.existeInformations(pCheminInfos, pVersionSource, pEtatSource, 85 pVersionCible, pEtatCible, pParametres ): 86 xmlInfo = self.__creerInformations(pVersionSource, pEtatSource, 87 pVersionCible, pEtatCible, 88 pParametres, pTransformations) 89 fic = lireDocXml(pCheminInfos) 90 nodeRoot = fic._get_firstChild() 91 nodeRoot.appendChild(xmlInfo) 92 ecrireDocXml(pCheminInfos,fic)
93
94 - def enregistrerVersion(self,pCheminInfos, pName):
95 xmlVersion = self.__creerVersion(pName) 96 fic = lireDocXml(pCheminInfos) 97 l = fic.getElementsByTagName(B_ARBRE) # renvoie un unique element arbre 98 arbre = l[0] 99 arbre.appendChild(xmlVersion) 100 ecrireDocXml(pCheminInfos,fic)
101
102 - def enregistrerEtat(self,pCheminInfos,pName,pVersionName, pParentName=''):
103 xmlEtat = self.__creerEtat(pName) 104 fic = lireDocXml(pCheminInfos) 105 for version in fic.getElementsByTagName(B_VERSION): 106 if version.getAttribute(B_ID) == pVersionName: 107 if pParentName == '': 108 version.appendChild(xmlEtat) 109 ecrireDocXml(pCheminInfos,fic) 110 return 111 else: 112 for etat in version.getElementsByTagName(B_ETAT): 113 if etat.getAttribute(B_ID) == pParentName: 114 etat.appendChild(xmlEtat) 115 ecrireDocXml(pCheminInfos,fic) 116 return
117
118 - def __creerVersion(self,pName):
119 xmldoc = Document() 120 xmltagVersion = xmldoc.createElement(B_VERSION) 121 xmltagVersion.setAttribute(B_ID,pName) 122 return xmltagVersion
123
124 - def __creerEtat(self,pName):
125 xmldoc = Document() 126 xmltagEtat = xmldoc.createElement(B_ETAT) 127 xmltagEtat.setAttribute(B_ID,pName) 128 return xmltagEtat
129 130 # Methode privee qui creer le noeud <information> a inserer dans le fichier xml
131 - def __creerInformations(self, pVersionSource, pEtatSource, pVersionCible, 132 pEtatCible, pParametres, pResultat):
133 xmldoc = Document() 134 # Balise Information 135 xmltagInfo = xmldoc.createElement(B_INFORMATIONS) 136 xmltagInfo.setAttribute(B_VERS_SOURCE,pVersionSource) 137 xmltagInfo.setAttribute(B_ETAT_SOURCE,pEtatSource) 138 xmltagInfo.setAttribute(B_VERS_CIBLE,pVersionCible) 139 xmltagInfo.setAttribute(B_ETAT_CIBLE,pEtatCible) 140 xmltagInfo.setAttribute(B_PARAM_1,'%s'%pParametres.getp1()) 141 xmltagInfo.setAttribute(B_PARAM_2,'%s'%pParametres.getp2()) 142 xmltagInfo.setAttribute(B_PARAM_3,'%s'%pParametres.getp3()) 143 xmltagInfo.setAttribute(B_PARAM_4,'%s'%pParametres.getp4()) 144 xmltagInfo.setAttribute(B_PARAM_5,'%s'%pParametres.getp5()) 145 xmltagInfo.setAttribute(B_PARAM_6,'%s'%pParametres.getp6()) 146 xmltagInfo.setAttribute(B_PARAM_7,'%s'%pParametres.getp7()) 147 # Balise Transformations 148 xmlTransfo = xmldoc.createElement(B_TRANSFORMATIONS) 149 xmlLgsource = xmldoc.createElement(B_LGSOURCE) 150 xmlLgsource.setAttribute(B_LG, str(pResultat.getLgSource())) 151 xmlTransfo.appendChild(xmlLgsource) 152 # Insertions 153 xmlInsert = xmldoc.createElement(B_INSERTIONS) 154 listeInsert = pResultat.getListeInsertions() 155 for deb,fin in listeInsert : 156 node = xmldoc.createElement(B_INS) 157 node.setAttribute(B_DEB, str(deb)) 158 node.setAttribute(B_FIN, str(fin)) 159 xmlInsert.appendChild(node) 160 xmlTransfo.appendChild(xmlInsert) 161 # Suppressions 162 xmlSupp = xmldoc.createElement(B_SUPPRESSIONS) 163 listeSupp = pResultat.getListeSuppressions() 164 for deb,fin in listeSupp : 165 node = xmldoc.createElement(B_SUP) 166 node.setAttribute(B_DEB, str(deb)) 167 node.setAttribute(B_FIN, str(fin)) 168 xmlSupp.appendChild(node) 169 xmlTransfo.appendChild(xmlSupp) 170 # Deplacements 171 xmlDepl = xmldoc.createElement(B_DEPLACEMENTS) 172 listeDepl = pResultat.getListeDeplacements() 173 for deb,fin in listeDepl : 174 node = xmldoc.createElement(B_DEP) 175 node.setAttribute(B_DEB, str(deb)) 176 node.setAttribute(B_FIN, str(fin)) 177 xmlDepl.appendChild(node) 178 xmlTransfo.appendChild(xmlDepl) 179 # Remplacement 180 xmlRemp = xmldoc.createElement(B_REMPLACEMENTS) 181 listeRemp = pResultat.getListeRemplacements() 182 for deb,fin in listeRemp : 183 node = xmldoc.createElement(B_REMP) 184 node.setAttribute(B_DEB, str(deb)) 185 node.setAttribute(B_FIN, str(fin)) 186 xmlRemp.appendChild(node) 187 xmlTransfo.appendChild(xmlRemp) 188 #blocs communs 189 xmlBlocsCom = xmldoc.createElement(B_BLOCSCOMMUNS) 190 listeBlocsCommuns = pResultat.getBlocsCommuns() 191 for deb,fin in listeBlocsCommuns : 192 node = xmldoc.createElement(B_BC) 193 node.setAttribute(B_DEB, str(deb)) 194 node.setAttribute(B_FIN, str(fin)) 195 xmlBlocsCom.appendChild(node) 196 xmlTransfo.appendChild(xmlBlocsCom) 197 # blocs déplacés 198 xmlBlocsDep = xmldoc.createElement(B_BLOCSDEPLACES) 199 listeBlocsDep = pResultat.getPairesBlocsDeplaces() 200 for (b1deb,b1fin),(b2deb,b2fin) in listeBlocsDep : 201 node = xmldoc.createElement(B_DEP) 202 node.setAttribute(B1_D, str(b1deb)) 203 node.setAttribute(B1_F, str(b1fin)) 204 node.setAttribute(B2_D, str(b2deb)) 205 node.setAttribute(B2_F, str(b2fin)) 206 xmlBlocsDep.appendChild(node) 207 xmlTransfo.appendChild(xmlBlocsDep) 208 # Insertion de la balise B_TRANSFORMATIONS dans la balise B_INFORMATIONS 209 xmltagInfo.appendChild(xmlTransfo) 210 211 return xmltagInfo
212 213 # Methode privee qui creer le noeud <information> a inserer dans le fichier xml 214 # def __creerInformations(self, pVersionSource, pEtatSource, pVersionCible, 215 # pEtatCible, pParametres, pTransformations): 216 # xmldoc = Document() 217 # # Balise Information 218 # xmltagInfo = xmldoc.createElement(B_INFORMATIONS) 219 # xmltagInfo.setAttribute(B_VERS_SOURCE,pVersionSource) 220 # xmltagInfo.setAttribute(B_ETAT_SOURCE,pEtatSource) 221 # xmltagInfo.setAttribute(B_VERS_CIBLE,pVersionCible) 222 # xmltagInfo.setAttribute(B_ETAT_CIBLE,pEtatCible) 223 # xmltagInfo.setAttribute(B_PARAM_1,'%s'%pParametres.getp1()) 224 # xmltagInfo.setAttribute(B_PARAM_2,'%s'%pParametres.getp2()) 225 # xmltagInfo.setAttribute(B_PARAM_3,'%s'%pParametres.getp3()) 226 # xmltagInfo.setAttribute(B_PARAM_4,'%s'%pParametres.getp4()) 227 # # Balise Transformations 228 # xmlTransfo = xmldoc.createElement(B_TRANSFORMATIONS) 229 # # Insertions 230 # xmlInsert = xmldoc.createElement(B_INSERTIONS) 231 # listeInsert = pTransformations.getInsertions() 232 # for m in listeInsert : 233 ### print m 234 # xmlMot = xmldoc.createElement(B_MOT) 235 # xmlMot.appendChild(xmldoc.createTextNode(m)) 236 # xmlInsert.appendChild(xmlMot) 237 # xmlTransfo.appendChild(xmlInsert) 238 # # Suppressions 239 # xmlSupp = xmldoc.createElement(B_SUPPRESSIONS) 240 # listeSupp = pTransformations.getSuppressions() 241 # for m in listeSupp : 242 ### print m 243 # xmlMot = xmldoc.createElement(B_MOT) 244 # xmlMot.appendChild(xmldoc.createTextNode(m)) 245 # xmlSupp.appendChild(xmlMot) 246 # xmlTransfo.appendChild(xmlSupp) 247 # # Deplacements 248 # xmlDepl = xmldoc.createElement(B_DEPLACEMENTS) 249 # listeDepl = pTransformations.getDeplacements() 250 # for m in listeDepl : 251 ### print m 252 # xmlMot = xmldoc.createElement(B_MOT) 253 # xmlMot.appendChild(xmldoc.createTextNode(m)) 254 # xmlDepl.appendChild(xmlMot) 255 # xmlTransfo.appendChild(xmlDepl) 256 # # Remplacement 257 # xmlRemp = xmldoc.createElement(B_REMPLACEMENTS) 258 # listeRemp = pTransformations.getRemplacements() 259 # for m in listeRemp : 260 # xmlR = xmldoc.createElement(B_REMP) 261 # # mot avant 262 ### print m[0] 263 # xmlMotAvant = xmldoc.createElement(B_MOT_AVANT) 264 # xmlMotAvant.appendChild(xmldoc.createTextNode(m[0])) 265 # xmlR.appendChild(xmlMotAvant) 266 # # mot apres 267 ### print m[1] 268 # xmlMotApres = xmldoc.createElement(B_MOT_APRES) 269 # xmlMotApres.appendChild(xmldoc.createTextNode(m[1])) 270 # xmlR.appendChild(xmlMotApres) 271 # xmlRemp.appendChild(xmlR) 272 # xmlTransfo.appendChild(xmlRemp) 273 # # texte source 274 # xmlTransfo.appendChild(pTransformations.getSource()) 275 # # texte cible 276 # xmlTransfo.appendChild(pTransformations.getCible()) 277 # # Insertion de la balise B_TRANSFORMATIONS dans la balise B_INFORMATIONS 278 # xmltagInfo.appendChild(xmlTransfo) 279 # 280 # try: 281 # sys.stderr.write(unicode(xmlTransfo.toxml()).encode("iso-8859-2", "replace")) 282 # sys.stderr.flush() 283 # except Exception,e: 284 # sys.stderr.write( str(e)) 285 # traceback.print_exc() 286 # sys.stderr.flush() 287 # return xmltagInfo 288 289 290 # Methode qui renvoie toutes les informations existantes pour un dossier genetique
291 - def getToutesInformationsDG(self, pCheminInfos):
292 ## print 'dans donneesInformations.getToutesInformationsDG' 293 # On recupere dans fic les informations du fichier Informations.xml 294 # dont le chemin est passe en parametre 295 fic = lireDocXml(pCheminInfos) 296 liste = fic.getElementsByTagName(B_INFORMATIONS) 297 listeInfos = [] 298 for node in liste : 299 vSource = node.getAttribute(B_VERS_SOURCE) 300 fSource = node.getAttribute(B_ETAT_SOURCE) 301 vCible = node.getAttribute(B_VERS_CIBLE) 302 fCible = node.getAttribute(B_ETAT_CIBLE) 303 par1 = atoi(node.getAttribute(B_PARAM_1)) 304 par2 = atoi(node.getAttribute(B_PARAM_2)) 305 par3 = atoi(node.getAttribute(B_PARAM_3)) 306 par4 = atoi(node.getAttribute(B_PARAM_4)) 307 par5 = atoi(node.getAttribute(B_PARAM_5)) 308 par6 = atoi(node.getAttribute(B_PARAM_6)) 309 par7 = atoi(node.getAttribute(B_PARAM_7)) 310 listeInfos.append([vSource,fSource,vCible,fCible,par1,par2,par3,par4,par5,par6,par7]) 311 return listeInfos
312 313 # Methode qui renvoie toutes les informations existantes 314 # pour tous les couples d'états enregistrés d'un DG' 315 # renvoie une liste d'objets Informations
316 - def getLInformationsDG(self, pCheminInfos, pNom, nomDG):
317 #sys.stderr.write('dans donneesInformations.getToutesInformations\n') 318 # On recupere dans fic les informations du fichier Informations.xml 319 # dont le chemin est passe en parametre 320 fic = lireDocXml(pCheminInfos) 321 liste = fic.getElementsByTagName(B_INFORMATIONS) 322 listeInfos = [] 323 for infos in liste : 324 tmpInfo = self.__getInformations(infos, pNom, nomDG) 325 listeInfos.append(tmpInfo) 326 return listeInfos
327 328 # Methode qui renvoie toutes les informations existantes pour un couple de etats
329 - def getToutesInformations(self, pCheminInfos, pNom, nomDG, pVersionSource, pEtatSource, 330 pVersionCible, pEtatCible):
331 #sys.stderr.write('dans donneesInformations.getToutesInformations\n') 332 # On recupere dans fic les informations du fichier Informations.xml 333 # dont le chemin est passe en parametre 334 fic = lireDocXml(pCheminInfos) 335 liste = fic.getElementsByTagName(B_INFORMATIONS) 336 listeInfos = [] 337 for infos in liste : 338 if (infos.getAttribute(B_VERS_SOURCE)== pVersionSource and 339 infos.getAttribute(B_ETAT_SOURCE)== pEtatSource and 340 infos.getAttribute(B_VERS_CIBLE) == pVersionCible and 341 infos.getAttribute(B_ETAT_CIBLE) == pEtatCible): 342 tmpInfo = self.__getInformations(infos, pNom, nomDG) 343 listeInfos.append(tmpInfo) 344 return listeInfos
345 346 # Methode qui renvoie les informations existantes pour un couple de etats 347 # et des parametres precis
348 - def getInformationsParam(self, pCheminInfos, pNom, nomDG, pVersionSource, pEtatSource, 349 pVersionCible, pEtatCible, pParametres):
350 tmp1 = '%s'%pParametres.getp1() 351 tmp2 = '%s'%pParametres.getp2() 352 tmp3 = '%s'%pParametres.getp3() 353 tmp4 = '%s'%pParametres.getp4() 354 tmp5 = '%s'%pParametres.getp5() 355 tmp6 = '%s'%pParametres.getp6() 356 tmp7 = '%s'%pParametres.getp7() 357 # Ouverture du fichier "informations" 358 # On recupere dans fic les informations du fichier Informations.xml dont le chemin est passe en parametre 359 fic = lireDocXml(pCheminInfos) 360 liste = fic.getElementsByTagName(B_INFORMATIONS) 361 for node in liste : 362 if (node.getAttribute(B_VERS_SOURCE)== pVersionSource and 363 node.getAttribute(B_ETAT_SOURCE)== pEtatSource and 364 node.getAttribute(B_VERS_CIBLE) == pVersionCible and 365 node.getAttribute(B_ETAT_CIBLE) == pEtatCible and 366 node.getAttribute(B_PARAM_1) == tmp1 and 367 node.getAttribute(B_PARAM_2) == tmp2 and 368 node.getAttribute(B_PARAM_3) == tmp3 and 369 node.getAttribute(B_PARAM_4) == tmp4 and 370 node.getAttribute(B_PARAM_5) == tmp5 and 371 node.getAttribute(B_PARAM_6) == tmp6 and 372 node.getAttribute(B_PARAM_7) == tmp7): 373 return self.__getInformations(node,pNom,nomDG) 374 return None
375
376 - def __getInformations(self,nodeInfos, pNom, nomDG):
377 ## print 'dans donneesInformations.getInformations' 378 # On recupere dans fic les informations du fichier Informations.xml dont 379 # le chemin est passe en parametre 380 381 pVersionSource = nodeInfos.getAttribute(B_VERS_SOURCE) 382 pEtatSource = nodeInfos.getAttribute(B_ETAT_SOURCE) 383 pVersionCible = nodeInfos.getAttribute(B_VERS_CIBLE) 384 pEtatCible = nodeInfos.getAttribute(B_ETAT_CIBLE) 385 pParametres = Parametres(atoi(nodeInfos.getAttribute(B_PARAM_1)), atoi(nodeInfos.getAttribute(B_PARAM_2)), 386 atoi(nodeInfos.getAttribute(B_PARAM_3)),atoi(nodeInfos.getAttribute(B_PARAM_4)), 387 atoi(nodeInfos.getAttribute(B_PARAM_5)),atoi(nodeInfos.getAttribute(B_PARAM_6)), 388 atoi(nodeInfos.getAttribute(B_PARAM_7))) 389 # on concatène les 2 fichiers 390 pathSource=os.path.join(LEURREP,pNom,nomDG,pVersionSource,pEtatSource) 391 pathCible=os.path.join(LEURREP,pNom,nomDG,pVersionCible,pEtatCible) 392 fs = open(pathSource) 393 fc = open(pathCible) 394 textesConca = fs.read() + fc.read() 395 fs.close() 396 fc.close() 397 ## creer un objet de type 'Transformations' 398 i = nodeInfos.getElementsByTagName(B_LGSOURCE) 399 lgsource=0 400 if i != []: 401 lgsource = int(i[0].getAttribute(B_LG)) 402 403 listInsert = [] 404 i = nodeInfos.getElementsByTagName(B_INSERTIONS) 405 if i != [] : 406 li = i[0].getElementsByTagName(B_INS) 407 for m in li : 408 listInsert.append([int(m.getAttribute(B_DEB)),int(m.getAttribute(B_FIN))]) 409 410 listSupp = [] 411 s = nodeInfos.getElementsByTagName(B_SUPPRESSIONS) 412 if s != [] : 413 ls = s[0].getElementsByTagName(B_SUP) 414 for m in ls : 415 listSupp.append([int(m.getAttribute(B_DEB)),int(m.getAttribute(B_FIN))]) 416 417 listDepl = [] 418 d = nodeInfos.getElementsByTagName(B_DEPLACEMENTS) 419 if d != []: 420 ld = d[0].getElementsByTagName(B_DEP) 421 for m in ld : 422 listDepl.append([int(m.getAttribute(B_DEB)),int(m.getAttribute(B_FIN))]) 423 424 listRemp = [] 425 r = nodeInfos.getElementsByTagName(B_REMPLACEMENTS) 426 if r != []: 427 lr = r[0].getElementsByTagName(B_REMP) 428 for m in lr : 429 listRemp.append([int(m.getAttribute(B_DEB)),int(m.getAttribute(B_FIN))]) 430 431 listBlocCom = [] 432 r = nodeInfos.getElementsByTagName(B_BLOCSCOMMUNS) 433 if r != []: 434 lr = r[0].getElementsByTagName(B_BC) 435 for m in lr : 436 listBlocCom.append([int(m.getAttribute(B_DEB)),int(m.getAttribute(B_FIN))]) 437 438 listBlocDep = [] 439 r = nodeInfos.getElementsByTagName(B_BLOCSDEPLACES) 440 if r != []: 441 lr = r[0].getElementsByTagName(B_DEP) 442 for m in lr : 443 listBlocDep.append([[int(m.getAttribute(B1_D)),int(m.getAttribute(B1_F))], 444 [int(m.getAttribute(B2_D)),int(m.getAttribute(B2_F))]]) 445 446 #transfo = Transformations(listInsert, listSupp, listDepl, listRemp, textSource, textCible) 447 res = Resultat(listInsert, listSupp, listDepl, listRemp,lgsource,textesConca,listBlocCom,listBlocDep) 448 ## creer un objet de type 'Commentaire' si la balise B_COMMENTAIRE existe 449 c = nodeInfos.getElementsByTagName(B_COMMENTAIRE) 450 if c != []: 451 comment = Commentaire((c[0]._get_firstChild()).toxml()) 452 else : 453 comment = Commentaire('') 454 455 ## creer et retourner un objet du type 'Informations' 456 return Informations(pVersionSource, pEtatSource, pVersionCible, 457 pEtatCible,pParametres, res, comment)
458 459 460 # # Methode qui renvoie les informations existantes pour un couple de etats 461 # # et des parametres precis 462 # #def getInformations(self, pCheminInfos, pVersionSource, pEtatSource, 463 # # pVersionCible, pEtatCible, pParametres): 464 # def getInformations(self,nodeInfos): 465 ### print 'dans donneesInformations.getInformations' 466 # # On recupere dans fic les informations du fichier Informations.xml dont 467 # # le chemin est passe en parametre 468 # 469 # pVersionSource = nodeInfos.getAttribute(B_VERS_SOURCE) 470 # pEtatSource = nodeInfos.getAttribute(B_ETAT_SOURCE) 471 # pVersionCible = nodeInfos.getAttribute(B_VERS_CIBLE) 472 # pEtatCible = nodeInfos.getAttribute(B_ETAT_CIBLE) 473 # pParametres = Parametres(atoi(nodeInfos.getAttribute(B_PARAM_1)), atoi(nodeInfos.getAttribute(B_PARAM_2)), 474 # atoi(nodeInfos.getAttribute(B_PARAM_3)),atoi(nodeInfos.getAttribute(B_PARAM_4))) 475 # ## creer un objet de type 'Transformations' 476 # listInsert = [] 477 # i = nodeInfos.getElementsByTagName(B_INSERTIONS) 478 # if i != [] : 479 # li = i[0].getElementsByTagName(B_MOT) 480 # for m in li : 481 # listInsert.append((m._get_firstChild()).toxml()) 482 # 483 # listSupp = [] 484 # s = nodeInfos.getElementsByTagName(B_SUPPRESSIONS) 485 # if s != [] : 486 # ls = s[0].getElementsByTagName(B_MOT) 487 # for m in ls : 488 # listSupp.append((m._get_firstChild()).toxml()) 489 # 490 # listDepl = [] 491 # d = nodeInfos.getElementsByTagName(B_DEPLACEMENTS) 492 # if d != []: 493 # ld = d[0].getElementsByTagName(B_MOT) 494 # for m in ld : 495 # listDepl.append((m._get_firstChild()).toxml()) 496 # 497 # listRemp = [] 498 # r = nodeInfos.getElementsByTagName(B_DEPLACEMENTS) 499 # if r != []: 500 # lr = r[0].getElementsByTagName(B_MOT) 501 # for m in lr : 502 # listRemp.append((m._get_firstChild()).toxml()) 503 # 504 # ts = nodeInfos.getElementsByTagName(B_TEXT_SOURCE) 505 # textSource = ts[0] 506 # tc = nodeInfos.getElementsByTagName(B_TEXT_CIBLE) 507 # textCible = tc[0] 508 # 509 # transfo = Transformations(listInsert, listSupp, listDepl, listRemp, textSource, textCible) 510 # 511 # ## creer un objet de type 'Commentaire' si la balise B_COMMENTAIRE existe 512 # c = nodeInfos.getElementsByTagName(B_COMMENTAIRE) 513 # if c != []: 514 # comment = Commentaire((c[0]._get_firstChild()).toxml()) 515 # else : 516 # comment = Commentaire('') 517 # 518 # ## creer et retourner un objet du type 'Informations' 519 # return Informations(pVersionSource, pEtatSource, pVersionCible, 520 # pEtatCible,pParametres, transfo, comment) 521 522 523 # Methode qui enregistre le commentaire d'un couple de etats
524 - def enregistrerCommentaire(self, pCheminInfos, pVersionSource, pEtatSource, 525 pVersionCible, pEtatCible, pParametres, pCommentaire):
526 ## print 'dans donneesInformations.enregistrerCommentaire' 527 # On recupere dans fic les informations du fichier Informations.xml dont 528 # le chemin est passe en parametre 529 fic = lireDocXml(pCheminInfos) 530 liste = fic.getElementsByTagName(B_INFORMATIONS) 531 infos = self.__rechercherInfos(liste, pVersionSource, pEtatSource, 532 pVersionCible, pEtatCible, pParametres) 533 lc = infos.getElementsByTagName(B_COMMENTAIRE) 534 if lc == [] : 535 ## creer et ajouter le noeud 'commentaire' 536 comment = self.__creerCommentaire(pCommentaire) 537 infos.appendChild(comment) 538 ecrireDocXml(pCheminInfos,fic) 539 else : 540 # il existe deja un commentaire, une exception est lancee 541 c = (lc[0]._get_firstChild()).toxml() 542 comment = Commentaire(c) 543 raise CommentaireDejaExistant('le commentaire de"'+ 544 pVersionSource+'/'+pEtatSource+ 545 '" et "'+pVersionCible+'/'+pEtatCible+ 546 '" est deja existant', comment)
547 548 # Methode privee qui creer le noeud <commentaire> a inserer dans le fichier xml
549 - def __creerCommentaire(self, pCommentaire):
550 comment = pCommentaire.getCommentaire() 551 xmldoc = Document() 552 xmltagComment = xmldoc.createElement(B_COMMENTAIRE) 553 xmltagComment.appendChild(xmldoc.createTextNode(comment)) 554 return xmltagComment
555 556 # Methode qui ajoute un commentaire a l'ancien
557 - def ajouterCommentaire(self, pCheminInfos, pVersionSource, pEtatSource, 558 pVersionCible, pEtatCible, pParametres, pCommentaire):
559 ## print 'dans donneesInformations.ajouterCommentaire' 560 # On recupere dans fic les informations du fichier Informations.xml dont 561 # le chemin est passe en parametre 562 fic = lireDocXml(pCheminInfos) 563 liste = fic.getElementsByTagName(B_INFORMATIONS) 564 infos = self.__rechercherInfos(liste, pVersionSource, pEtatSource, 565 pVersionCible, pEtatCible, pParametres) 566 lc = infos.getElementsByTagName(B_COMMENTAIRE) 567 if lc == []: 568 ## creer et ajouter le noeud 'commentaire' 569 comment = self.__creerCommentaire(pCommentaire) 570 infos.appendChild(comment) 571 else : 572 xmldoc=Document() 573 comment =' '+ pCommentaire.getCommentaire() 574 lc[0].appendChild(xmldoc.createTextNode(comment)) 575 ecrireDocXml(pCheminInfos, fic)
576 577 # Methode qui remplace l'ancien commentaire par le nouveau
578 - def remplacerCommentaire(self, pCheminInfos, pVersionSource, pEtatSource, 579 pVersionCible, pEtatCible, pParametres, pCommentaire):
580 ## print 'dans donneesInformations.remplacerCommentaire' 581 # On recupere dans fic les informations du fichier Informations.xml dont le chemin est passe en parametre 582 fic = lireDocXml(pCheminInfos) 583 liste = fic.getElementsByTagName(B_INFORMATIONS) 584 infos = self.__rechercherInfos(liste, pVersionSource, pEtatSource, 585 pVersionCible, pEtatCible, pParametres) 586 lc = infos.getElementsByTagName(B_COMMENTAIRE) 587 comment = self.__creerCommentaire(pCommentaire) 588 if lc != [] : 589 infos.removeChild(lc[0]) 590 infos.appendChild(comment) 591 ecrireDocXml(pCheminInfos,fic)
592 593 # Methode qui supprime le commentaire d'un couple de etat
594 - def supprimerCommentaire(self, pCheminInfos, pVersionSource, pEtatSource, 595 pVersionCible, pEtatCible, pParametres):
596 ## print 'dans donneesInformations.supprimerCommentaire' 597 # On recupere dans fic les informations du fichier Informations.xml dont le chemin est passe en parametre 598 fic = lireDocXml(pCheminInfos) 599 liste = fic.getElementsByTagName(B_INFORMATIONS) 600 infos = self.__rechercherInfos(liste, pVersionSource, pEtatSource, 601 pVersionCible, pEtatCible, pParametres) 602 lc = infos.getElementsByTagName(B_COMMENTAIRE) 603 if lc != [] : 604 infos.removeChild(lc[0]) 605 ecrireDocXml(pCheminInfos, fic) 606 else : 607 raise CommentaireNonTrouve('les informations de "'+pVersionSource+'/' 608 +pEtatSource+'" et "'+pVersionCible+'/' 609 +pEtatCible+'" n\'ont pas de commentaire')
610 611 # Methode qui supprimme les informations d'un couple de etat
612 - def supprimerInformations(self, pCheminInfos, pVersionSource, pEtatSource, 613 pVersionCible, pEtatCible, pParametres):
614 ## print 'dans donneesInformations.supprimerInformations' 615 # On recupere dans fic les informations du fichier Informations.xml dont 616 # le chemin est passe en parametre 617 fic = lireDocXml(pCheminInfos) 618 noderoot = fic.getElementsByTagName(B_ROOT) 619 liste = fic.getElementsByTagName(B_INFORMATIONS) 620 infos = self.__rechercherInfos(liste, pVersionSource, pEtatSource, 621 pVersionCible, pEtatCible, pParametres) 622 if infos != None: 623 ## suppression du noeud 624 noderoot[0].removeChild(infos) 625 ecrireDocXml(pCheminInfos,fic)
626 627 # Methode qui supprimme la version de l'arbre
628 - def supprimerVersion(self, pCheminInfos,pVersionName):
629 fic = lireDocXml(pCheminInfos) 630 larbre = fic.getElementsByTagName(B_ARBRE) 631 lVersions = larbre[0].getElementsByTagName(B_VERSION) 632 for version in lVersions: 633 if version.getAttribute(B_ID)==pVersionName: 634 # suppression du noeud 635 larbre[0].removeChild(version) 636 ecrireDocXml(pCheminInfos,fic) 637 return
638 639 # Methode qui supprimme un état d'une version
640 - def supprimerEtat(self, pCheminInfos,pVersionName,pEtatName):
641 fic = lireDocXml(pCheminInfos) 642 lVersions = fic.getElementsByTagName(B_VERSION) 643 for version in lVersions: 644 if version.getAttribute(B_ID) == pVersionName: 645 for etat in version.getElementsByTagName(B_ETAT): 646 if etat.getAttribute(B_ID) == pEtatName: 647 # pas forcément version car un état peut avoir une autre version comme parent 648 parent = etat.parentNode 649 parent.removeChild(etat) 650 ecrireDocXml(pCheminInfos,fic) 651 return
652 653 # Methode qui enregistre les informations (transformations + commentaire) d'un couple de etats
654 - def enregistrerInformations(self, pCheminInfos, pVersionSource, pEtatSource, 655 pVersionCible, pEtatCible, pParametres, 656 pTransformations, pCommentaire):
657 ## print 'dans donneesInformations.enregistrerInformations' 658 if not self.existeInformations(pCheminInfos, pVersionSource, pEtatSource, 659 pVersionCible, pEtatCible, pParametres ): 660 self.enregistrerTransformations(pCheminInfos, pVersionSource, pEtatSource, 661 pVersionCible, pEtatCible, pParametres, 662 pTransformations) 663 self.enregistrerCommentaire(pCheminInfos, pVersionSource, pEtatSource, 664 pVersionCible, pEtatCible, pParametres, 665 pCommentaire)
666 667 # Methode privee qui renvoie la balise "informations" recherchee
668 - def __rechercherInfos(self, pListeBalise, pVersionSource, pEtatSource, 669 pVersionCible, pEtatCible, pParametres):
670 tmp1 = '%s' %pParametres.getp1() 671 tmp2 = '%s' %pParametres.getp2() 672 tmp3 = '%s' %pParametres.getp3() 673 tmp4 = '%s' %pParametres.getp4() 674 tmp5 = '%s' %pParametres.getp5() 675 tmp6 = '%s' %pParametres.getp6() 676 tmp7 = '%s' %pParametres.getp7() 677 # sys.stderr.write("__rechercherInfos "+pParametres.toString()) 678 # sys.stderr.flush() 679 for node in pListeBalise : 680 if (node.getAttribute(B_VERS_SOURCE)== pVersionSource and 681 node.getAttribute(B_ETAT_SOURCE)== pEtatSource and 682 node.getAttribute(B_VERS_CIBLE) == pVersionCible and 683 node.getAttribute(B_ETAT_CIBLE) == pEtatCible and 684 node.getAttribute(B_PARAM_1) == tmp1 and 685 node.getAttribute(B_PARAM_2) == tmp2 and 686 node.getAttribute(B_PARAM_3) == tmp3 and 687 node.getAttribute(B_PARAM_4) == tmp4 and 688 node.getAttribute(B_PARAM_5) == tmp5 and 689 node.getAttribute(B_PARAM_6) == tmp6 and 690 node.getAttribute(B_PARAM_7) == tmp7): 691 return node 692 693 return None
694 # raise InformationsNonTrouvees('les informations de "'+pVersionSource+ 695 # '/'+pEtatSource+'" et "'+pVersionCible+ 696 # '/'+pEtatCible+'" n\'existent pas') 697 698 # retourne le nom des ID des etats fils d'un état 699 # qui correspondent aux noms de fichier
700 - def getListeEtatsFils(self,pCheminInfos, pName, pNomVersion):
701 lef = [] 702 fic = lireDocXml(pCheminInfos) 703 larbre = fic.getElementsByTagName(B_ARBRE) 704 for version in larbre[0].getElementsByTagName(B_VERSION): 705 if version.getAttribute(B_ID) == pNomVersion: 706 for etat in version.getElementsByTagName(B_ETAT): 707 if etat.getAttribute(B_ID) == pName: 708 lEtatsFils = etat.getElementsByTagName(B_ETAT) 709 for etatFils in lEtatsFils: 710 lef.append(etatFils.getAttribute(B_ID)) 711 return lef 712 return []
713 714 # lit l'arbre des versions à partir du fichier xml 715 # renvoie un Arbre
716 - def getArbre(self,pCheminInfos):
717 lFils = [] 718 fic = lireDocXml(pCheminInfos) 719 720 larbre = fic.getElementsByTagName(B_ARBRE) 721 for version in larbre[0].getElementsByTagName(B_VERSION): 722 lFils.append(self.__getFils(version)) 723 return Arbre(lFils)
724 725 # lit les fils d'un noeud version ou état 726 # et retourne ce noeud en tant que Version ou Etat
727 - def __getFils(self,pere):
728 lFils = [] 729 name = pere.getAttribute(B_ID) 730 for fils in pere.childNodes: 731 lFils.append(self.__getFils(fils)) 732 if pere.tagName == B_VERSION: 733 return Version(name, lFils) 734 else: 735 return Etat(name, lFils)
736