# -*- coding: iso-8859-1 -*- # Copyright 20003 - 2008: Julien Bourdaillet (julien.bourdaillet@lip6.fr), Jean-Gabriel Ganascia (jean-gabriel.ganascia@lip6.fr) # This file is part of MEDITE. # # MEDITE 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 2 of the License, or # (at your option) any later version. # # MEDITE 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 Foobar; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #---------------------------------------------------------------------------- # Nom: donneesInformations.py # Objet: Classe qui accede aux fichier xml #---------------------------------------------------------------------------- from xml.dom.minidom import * #from xml.dom.pulldom import * #import os, sys, gc from string import * from Donnees.informations import * from Donnees.commentaire import * from Donnees.transformations import * from Donnees.resultatAppli import * from Donnees.donnees import * from Utile.constantesDonnees import * from Utile.exceptionsDonnees import * from Utile.codageXml import * from Donnees.planTravail import * from Donnees.arbre import * from Controleurs.cMedite import * import traceback class DonneesInformations: # Methode qui renvoie vrai si des informations existent sur un couple de etats def existeInformations(self, pCheminInfos, pVersionSource, pEtatSource, pVersionCible, pEtatCible, pParametres): tmp1 = '%s'%pParametres.getp1() tmp2 = '%s'%pParametres.getp2() tmp3 = '%s'%pParametres.getp3() tmp4 = '%s'%pParametres.getp4() tmp5 = '%s'%pParametres.getp5() tmp6 = '%s'%pParametres.getp6() tmp7 = '%s'%pParametres.getp7() # sys.stderr.write("\nexisteInformations "+pParametres.toString()) # sys.stderr.flush() # Ouverture du fichier "informations" # On recupere dans fic les informations du fichier Informations.xml dont # le chemin est passe en parametre fic = lireDocXml(pCheminInfos) liste = fic.getElementsByTagName(B_INFORMATIONS) for node in liste : if (node.getAttribute(B_VERS_SOURCE)== pVersionSource and node.getAttribute(B_ETAT_SOURCE)== pEtatSource and node.getAttribute(B_VERS_CIBLE) == pVersionCible and node.getAttribute(B_ETAT_CIBLE) == pEtatCible and node.getAttribute(B_PARAM_1) == tmp1 and node.getAttribute(B_PARAM_2) == tmp2 and node.getAttribute(B_PARAM_3) == tmp3 and node.getAttribute(B_PARAM_4) == tmp4 and node.getAttribute(B_PARAM_5) == tmp5 and node.getAttribute(B_PARAM_6) == tmp6 and node.getAttribute(B_PARAM_7) == tmp7): # sys.stderr.write("existe \n") # sys.stderr.flush() return 1 ## VRAI # sys.stderr.write("existe pas \n") # sys.stderr.flush() return 0 ## FAUX # Methode qui enregistre les transformations d'un couple de etats def enregistrerTransformations(self, pCheminInfos, pVersionSource, pEtatSource, pVersionCible, pEtatCible, pParametres, pTransformations): ## print 'dans donneesInformations.enregistrerTransformations' if not self.existeInformations(pCheminInfos, pVersionSource, pEtatSource, pVersionCible, pEtatCible, pParametres ): xmlInfo = self.__creerInformations(pVersionSource, pEtatSource, pVersionCible, pEtatCible, pParametres, pTransformations) fic = lireDocXml(pCheminInfos) nodeRoot = fic._get_firstChild() nodeRoot.appendChild(xmlInfo) ecrireDocXml(pCheminInfos,fic) def enregistrerVersion(self,pCheminInfos, pName): xmlVersion = self.__creerVersion(pName) fic = lireDocXml(pCheminInfos) l = fic.getElementsByTagName(B_ARBRE) # renvoie un unique element arbre arbre = l[0] arbre.appendChild(xmlVersion) ecrireDocXml(pCheminInfos,fic) def enregistrerEtat(self,pCheminInfos,pName,pVersionName, pParentName=''): xmlEtat = self.__creerEtat(pName) fic = lireDocXml(pCheminInfos) for version in fic.getElementsByTagName(B_VERSION): if version.getAttribute(B_ID) == pVersionName: if pParentName == '': version.appendChild(xmlEtat) ecrireDocXml(pCheminInfos,fic) return else: for etat in version.getElementsByTagName(B_ETAT): if etat.getAttribute(B_ID) == pParentName: etat.appendChild(xmlEtat) ecrireDocXml(pCheminInfos,fic) return def __creerVersion(self,pName): xmldoc = Document() xmltagVersion = xmldoc.createElement(B_VERSION) xmltagVersion.setAttribute(B_ID,pName) return xmltagVersion def __creerEtat(self,pName): xmldoc = Document() xmltagEtat = xmldoc.createElement(B_ETAT) xmltagEtat.setAttribute(B_ID,pName) return xmltagEtat # Methode privee qui creer le noeud a inserer dans le fichier xml def __creerInformations(self, pVersionSource, pEtatSource, pVersionCible, pEtatCible, pParametres, pResultat): xmldoc = Document() # Balise Information xmltagInfo = xmldoc.createElement(B_INFORMATIONS) xmltagInfo.setAttribute(B_VERS_SOURCE,pVersionSource) xmltagInfo.setAttribute(B_ETAT_SOURCE,pEtatSource) xmltagInfo.setAttribute(B_VERS_CIBLE,pVersionCible) xmltagInfo.setAttribute(B_ETAT_CIBLE,pEtatCible) xmltagInfo.setAttribute(B_PARAM_1,'%s'%pParametres.getp1()) xmltagInfo.setAttribute(B_PARAM_2,'%s'%pParametres.getp2()) xmltagInfo.setAttribute(B_PARAM_3,'%s'%pParametres.getp3()) xmltagInfo.setAttribute(B_PARAM_4,'%s'%pParametres.getp4()) xmltagInfo.setAttribute(B_PARAM_5,'%s'%pParametres.getp5()) xmltagInfo.setAttribute(B_PARAM_6,'%s'%pParametres.getp6()) xmltagInfo.setAttribute(B_PARAM_7,'%s'%pParametres.getp7()) # Balise Transformations xmlTransfo = xmldoc.createElement(B_TRANSFORMATIONS) xmlLgsource = xmldoc.createElement(B_LGSOURCE) xmlLgsource.setAttribute(B_LG, str(pResultat.getLgSource())) xmlTransfo.appendChild(xmlLgsource) # Insertions xmlInsert = xmldoc.createElement(B_INSERTIONS) listeInsert = pResultat.getListeInsertions() for deb,fin in listeInsert : node = xmldoc.createElement(B_INS) node.setAttribute(B_DEB, str(deb)) node.setAttribute(B_FIN, str(fin)) xmlInsert.appendChild(node) xmlTransfo.appendChild(xmlInsert) # Suppressions xmlSupp = xmldoc.createElement(B_SUPPRESSIONS) listeSupp = pResultat.getListeSuppressions() for deb,fin in listeSupp : node = xmldoc.createElement(B_SUP) node.setAttribute(B_DEB, str(deb)) node.setAttribute(B_FIN, str(fin)) xmlSupp.appendChild(node) xmlTransfo.appendChild(xmlSupp) # Deplacements xmlDepl = xmldoc.createElement(B_DEPLACEMENTS) listeDepl = pResultat.getListeDeplacements() for deb,fin in listeDepl : node = xmldoc.createElement(B_DEP) node.setAttribute(B_DEB, str(deb)) node.setAttribute(B_FIN, str(fin)) xmlDepl.appendChild(node) xmlTransfo.appendChild(xmlDepl) # Remplacement xmlRemp = xmldoc.createElement(B_REMPLACEMENTS) listeRemp = pResultat.getListeRemplacements() for deb,fin in listeRemp : node = xmldoc.createElement(B_REMP) node.setAttribute(B_DEB, str(deb)) node.setAttribute(B_FIN, str(fin)) xmlRemp.appendChild(node) xmlTransfo.appendChild(xmlRemp) #blocs communs xmlBlocsCom = xmldoc.createElement(B_BLOCSCOMMUNS) listeBlocsCommuns = pResultat.getBlocsCommuns() for deb,fin in listeBlocsCommuns : node = xmldoc.createElement(B_BC) node.setAttribute(B_DEB, str(deb)) node.setAttribute(B_FIN, str(fin)) xmlBlocsCom.appendChild(node) xmlTransfo.appendChild(xmlBlocsCom) # blocs déplacés xmlBlocsDep = xmldoc.createElement(B_BLOCSDEPLACES) listeBlocsDep = pResultat.getPairesBlocsDeplaces() for (b1deb,b1fin),(b2deb,b2fin) in listeBlocsDep : node = xmldoc.createElement(B_DEP) node.setAttribute(B1_D, str(b1deb)) node.setAttribute(B1_F, str(b1fin)) node.setAttribute(B2_D, str(b2deb)) node.setAttribute(B2_F, str(b2fin)) xmlBlocsDep.appendChild(node) xmlTransfo.appendChild(xmlBlocsDep) # Insertion de la balise B_TRANSFORMATIONS dans la balise B_INFORMATIONS xmltagInfo.appendChild(xmlTransfo) return xmltagInfo # Methode privee qui creer le noeud a inserer dans le fichier xml # def __creerInformations(self, pVersionSource, pEtatSource, pVersionCible, # pEtatCible, pParametres, pTransformations): # xmldoc = Document() # # Balise Information # xmltagInfo = xmldoc.createElement(B_INFORMATIONS) # xmltagInfo.setAttribute(B_VERS_SOURCE,pVersionSource) # xmltagInfo.setAttribute(B_ETAT_SOURCE,pEtatSource) # xmltagInfo.setAttribute(B_VERS_CIBLE,pVersionCible) # xmltagInfo.setAttribute(B_ETAT_CIBLE,pEtatCible) # xmltagInfo.setAttribute(B_PARAM_1,'%s'%pParametres.getp1()) # xmltagInfo.setAttribute(B_PARAM_2,'%s'%pParametres.getp2()) # xmltagInfo.setAttribute(B_PARAM_3,'%s'%pParametres.getp3()) # xmltagInfo.setAttribute(B_PARAM_4,'%s'%pParametres.getp4()) # # Balise Transformations # xmlTransfo = xmldoc.createElement(B_TRANSFORMATIONS) # # Insertions # xmlInsert = xmldoc.createElement(B_INSERTIONS) # listeInsert = pTransformations.getInsertions() # for m in listeInsert : ### print m # xmlMot = xmldoc.createElement(B_MOT) # xmlMot.appendChild(xmldoc.createTextNode(m)) # xmlInsert.appendChild(xmlMot) # xmlTransfo.appendChild(xmlInsert) # # Suppressions # xmlSupp = xmldoc.createElement(B_SUPPRESSIONS) # listeSupp = pTransformations.getSuppressions() # for m in listeSupp : ### print m # xmlMot = xmldoc.createElement(B_MOT) # xmlMot.appendChild(xmldoc.createTextNode(m)) # xmlSupp.appendChild(xmlMot) # xmlTransfo.appendChild(xmlSupp) # # Deplacements # xmlDepl = xmldoc.createElement(B_DEPLACEMENTS) # listeDepl = pTransformations.getDeplacements() # for m in listeDepl : ### print m # xmlMot = xmldoc.createElement(B_MOT) # xmlMot.appendChild(xmldoc.createTextNode(m)) # xmlDepl.appendChild(xmlMot) # xmlTransfo.appendChild(xmlDepl) # # Remplacement # xmlRemp = xmldoc.createElement(B_REMPLACEMENTS) # listeRemp = pTransformations.getRemplacements() # for m in listeRemp : # xmlR = xmldoc.createElement(B_REMP) # # mot avant ### print m[0] # xmlMotAvant = xmldoc.createElement(B_MOT_AVANT) # xmlMotAvant.appendChild(xmldoc.createTextNode(m[0])) # xmlR.appendChild(xmlMotAvant) # # mot apres ### print m[1] # xmlMotApres = xmldoc.createElement(B_MOT_APRES) # xmlMotApres.appendChild(xmldoc.createTextNode(m[1])) # xmlR.appendChild(xmlMotApres) # xmlRemp.appendChild(xmlR) # xmlTransfo.appendChild(xmlRemp) # # texte source # xmlTransfo.appendChild(pTransformations.getSource()) # # texte cible # xmlTransfo.appendChild(pTransformations.getCible()) # # Insertion de la balise B_TRANSFORMATIONS dans la balise B_INFORMATIONS # xmltagInfo.appendChild(xmlTransfo) # # try: # sys.stderr.write(unicode(xmlTransfo.toxml()).encode("iso-8859-2", "replace")) # sys.stderr.flush() # except Exception,e: # sys.stderr.write( str(e)) # traceback.print_exc() # sys.stderr.flush() # return xmltagInfo # Methode qui renvoie toutes les informations existantes pour un dossier genetique def getToutesInformationsDG(self, pCheminInfos): ## print 'dans donneesInformations.getToutesInformationsDG' # On recupere dans fic les informations du fichier Informations.xml # dont le chemin est passe en parametre fic = lireDocXml(pCheminInfos) liste = fic.getElementsByTagName(B_INFORMATIONS) listeInfos = [] for node in liste : vSource = node.getAttribute(B_VERS_SOURCE) fSource = node.getAttribute(B_ETAT_SOURCE) vCible = node.getAttribute(B_VERS_CIBLE) fCible = node.getAttribute(B_ETAT_CIBLE) par1 = atoi(node.getAttribute(B_PARAM_1)) par2 = atoi(node.getAttribute(B_PARAM_2)) par3 = atoi(node.getAttribute(B_PARAM_3)) par4 = atoi(node.getAttribute(B_PARAM_4)) par5 = atoi(node.getAttribute(B_PARAM_5)) par6 = atoi(node.getAttribute(B_PARAM_6)) par7 = atoi(node.getAttribute(B_PARAM_7)) listeInfos.append([vSource,fSource,vCible,fCible,par1,par2,par3,par4,par5,par6,par7]) return listeInfos # Methode qui renvoie toutes les informations existantes # pour tous les couples d'états enregistrés d'un DG' # renvoie une liste d'objets Informations def getLInformationsDG(self, pCheminInfos, pNom, nomDG): #sys.stderr.write('dans donneesInformations.getToutesInformations\n') # On recupere dans fic les informations du fichier Informations.xml # dont le chemin est passe en parametre fic = lireDocXml(pCheminInfos) liste = fic.getElementsByTagName(B_INFORMATIONS) listeInfos = [] for infos in liste : tmpInfo = self.__getInformations(infos, pNom, nomDG) listeInfos.append(tmpInfo) return listeInfos # Methode qui renvoie toutes les informations existantes pour un couple de etats def getToutesInformations(self, pCheminInfos, pNom, nomDG, pVersionSource, pEtatSource, pVersionCible, pEtatCible): #sys.stderr.write('dans donneesInformations.getToutesInformations\n') # On recupere dans fic les informations du fichier Informations.xml # dont le chemin est passe en parametre fic = lireDocXml(pCheminInfos) liste = fic.getElementsByTagName(B_INFORMATIONS) listeInfos = [] for infos in liste : if (infos.getAttribute(B_VERS_SOURCE)== pVersionSource and infos.getAttribute(B_ETAT_SOURCE)== pEtatSource and infos.getAttribute(B_VERS_CIBLE) == pVersionCible and infos.getAttribute(B_ETAT_CIBLE) == pEtatCible): tmpInfo = self.__getInformations(infos, pNom, nomDG) listeInfos.append(tmpInfo) return listeInfos # Methode qui renvoie les informations existantes pour un couple de etats # et des parametres precis def getInformationsParam(self, pCheminInfos, pNom, nomDG, pVersionSource, pEtatSource, pVersionCible, pEtatCible, pParametres): tmp1 = '%s'%pParametres.getp1() tmp2 = '%s'%pParametres.getp2() tmp3 = '%s'%pParametres.getp3() tmp4 = '%s'%pParametres.getp4() tmp5 = '%s'%pParametres.getp5() tmp6 = '%s'%pParametres.getp6() tmp7 = '%s'%pParametres.getp7() # Ouverture du fichier "informations" # On recupere dans fic les informations du fichier Informations.xml dont le chemin est passe en parametre fic = lireDocXml(pCheminInfos) liste = fic.getElementsByTagName(B_INFORMATIONS) for node in liste : if (node.getAttribute(B_VERS_SOURCE)== pVersionSource and node.getAttribute(B_ETAT_SOURCE)== pEtatSource and node.getAttribute(B_VERS_CIBLE) == pVersionCible and node.getAttribute(B_ETAT_CIBLE) == pEtatCible and node.getAttribute(B_PARAM_1) == tmp1 and node.getAttribute(B_PARAM_2) == tmp2 and node.getAttribute(B_PARAM_3) == tmp3 and node.getAttribute(B_PARAM_4) == tmp4 and node.getAttribute(B_PARAM_5) == tmp5 and node.getAttribute(B_PARAM_6) == tmp6 and node.getAttribute(B_PARAM_7) == tmp7): return self.__getInformations(node,pNom,nomDG) return None def __getInformations(self,nodeInfos, pNom, nomDG): ## print 'dans donneesInformations.getInformations' # On recupere dans fic les informations du fichier Informations.xml dont # le chemin est passe en parametre pVersionSource = nodeInfos.getAttribute(B_VERS_SOURCE) pEtatSource = nodeInfos.getAttribute(B_ETAT_SOURCE) pVersionCible = nodeInfos.getAttribute(B_VERS_CIBLE) pEtatCible = nodeInfos.getAttribute(B_ETAT_CIBLE) pParametres = Parametres(atoi(nodeInfos.getAttribute(B_PARAM_1)), atoi(nodeInfos.getAttribute(B_PARAM_2)), atoi(nodeInfos.getAttribute(B_PARAM_3)),atoi(nodeInfos.getAttribute(B_PARAM_4)), atoi(nodeInfos.getAttribute(B_PARAM_5)),atoi(nodeInfos.getAttribute(B_PARAM_6)), atoi(nodeInfos.getAttribute(B_PARAM_7))) # on concatène les 2 fichiers pathSource=os.path.join(LEURREP,pNom,nomDG,pVersionSource,pEtatSource) pathCible=os.path.join(LEURREP,pNom,nomDG,pVersionCible,pEtatCible) fs = open(pathSource) fc = open(pathCible) textesConca = fs.read() + fc.read() fs.close() fc.close() ## creer un objet de type 'Transformations' i = nodeInfos.getElementsByTagName(B_LGSOURCE) lgsource=0 if i != []: lgsource = int(i[0].getAttribute(B_LG)) listInsert = [] i = nodeInfos.getElementsByTagName(B_INSERTIONS) if i != [] : li = i[0].getElementsByTagName(B_INS) for m in li : listInsert.append([int(m.getAttribute(B_DEB)),int(m.getAttribute(B_FIN))]) listSupp = [] s = nodeInfos.getElementsByTagName(B_SUPPRESSIONS) if s != [] : ls = s[0].getElementsByTagName(B_SUP) for m in ls : listSupp.append([int(m.getAttribute(B_DEB)),int(m.getAttribute(B_FIN))]) listDepl = [] d = nodeInfos.getElementsByTagName(B_DEPLACEMENTS) if d != []: ld = d[0].getElementsByTagName(B_DEP) for m in ld : listDepl.append([int(m.getAttribute(B_DEB)),int(m.getAttribute(B_FIN))]) listRemp = [] r = nodeInfos.getElementsByTagName(B_REMPLACEMENTS) if r != []: lr = r[0].getElementsByTagName(B_REMP) for m in lr : listRemp.append([int(m.getAttribute(B_DEB)),int(m.getAttribute(B_FIN))]) listBlocCom = [] r = nodeInfos.getElementsByTagName(B_BLOCSCOMMUNS) if r != []: lr = r[0].getElementsByTagName(B_BC) for m in lr : listBlocCom.append([int(m.getAttribute(B_DEB)),int(m.getAttribute(B_FIN))]) listBlocDep = [] r = nodeInfos.getElementsByTagName(B_BLOCSDEPLACES) if r != []: lr = r[0].getElementsByTagName(B_DEP) for m in lr : listBlocDep.append([[int(m.getAttribute(B1_D)),int(m.getAttribute(B1_F))], [int(m.getAttribute(B2_D)),int(m.getAttribute(B2_F))]]) #transfo = Transformations(listInsert, listSupp, listDepl, listRemp, textSource, textCible) res = Resultat(listInsert, listSupp, listDepl, listRemp,lgsource,textesConca,listBlocCom,listBlocDep) ## creer un objet de type 'Commentaire' si la balise B_COMMENTAIRE existe c = nodeInfos.getElementsByTagName(B_COMMENTAIRE) if c != []: comment = Commentaire((c[0]._get_firstChild()).toxml()) else : comment = Commentaire('') ## creer et retourner un objet du type 'Informations' return Informations(pVersionSource, pEtatSource, pVersionCible, pEtatCible,pParametres, res, comment) # # Methode qui renvoie les informations existantes pour un couple de etats # # et des parametres precis # #def getInformations(self, pCheminInfos, pVersionSource, pEtatSource, # # pVersionCible, pEtatCible, pParametres): # def getInformations(self,nodeInfos): ### print 'dans donneesInformations.getInformations' # # On recupere dans fic les informations du fichier Informations.xml dont # # le chemin est passe en parametre # # pVersionSource = nodeInfos.getAttribute(B_VERS_SOURCE) # pEtatSource = nodeInfos.getAttribute(B_ETAT_SOURCE) # pVersionCible = nodeInfos.getAttribute(B_VERS_CIBLE) # pEtatCible = nodeInfos.getAttribute(B_ETAT_CIBLE) # pParametres = Parametres(atoi(nodeInfos.getAttribute(B_PARAM_1)), atoi(nodeInfos.getAttribute(B_PARAM_2)), # atoi(nodeInfos.getAttribute(B_PARAM_3)),atoi(nodeInfos.getAttribute(B_PARAM_4))) # ## creer un objet de type 'Transformations' # listInsert = [] # i = nodeInfos.getElementsByTagName(B_INSERTIONS) # if i != [] : # li = i[0].getElementsByTagName(B_MOT) # for m in li : # listInsert.append((m._get_firstChild()).toxml()) # # listSupp = [] # s = nodeInfos.getElementsByTagName(B_SUPPRESSIONS) # if s != [] : # ls = s[0].getElementsByTagName(B_MOT) # for m in ls : # listSupp.append((m._get_firstChild()).toxml()) # # listDepl = [] # d = nodeInfos.getElementsByTagName(B_DEPLACEMENTS) # if d != []: # ld = d[0].getElementsByTagName(B_MOT) # for m in ld : # listDepl.append((m._get_firstChild()).toxml()) # # listRemp = [] # r = nodeInfos.getElementsByTagName(B_DEPLACEMENTS) # if r != []: # lr = r[0].getElementsByTagName(B_MOT) # for m in lr : # listRemp.append((m._get_firstChild()).toxml()) # # ts = nodeInfos.getElementsByTagName(B_TEXT_SOURCE) # textSource = ts[0] # tc = nodeInfos.getElementsByTagName(B_TEXT_CIBLE) # textCible = tc[0] # # transfo = Transformations(listInsert, listSupp, listDepl, listRemp, textSource, textCible) # # ## creer un objet de type 'Commentaire' si la balise B_COMMENTAIRE existe # c = nodeInfos.getElementsByTagName(B_COMMENTAIRE) # if c != []: # comment = Commentaire((c[0]._get_firstChild()).toxml()) # else : # comment = Commentaire('') # # ## creer et retourner un objet du type 'Informations' # return Informations(pVersionSource, pEtatSource, pVersionCible, # pEtatCible,pParametres, transfo, comment) # Methode qui enregistre le commentaire d'un couple de etats def enregistrerCommentaire(self, pCheminInfos, pVersionSource, pEtatSource, pVersionCible, pEtatCible, pParametres, pCommentaire): ## print 'dans donneesInformations.enregistrerCommentaire' # On recupere dans fic les informations du fichier Informations.xml dont # le chemin est passe en parametre fic = lireDocXml(pCheminInfos) liste = fic.getElementsByTagName(B_INFORMATIONS) infos = self.__rechercherInfos(liste, pVersionSource, pEtatSource, pVersionCible, pEtatCible, pParametres) lc = infos.getElementsByTagName(B_COMMENTAIRE) if lc == [] : ## creer et ajouter le noeud 'commentaire' comment = self.__creerCommentaire(pCommentaire) infos.appendChild(comment) ecrireDocXml(pCheminInfos,fic) else : # il existe deja un commentaire, une exception est lancee c = (lc[0]._get_firstChild()).toxml() comment = Commentaire(c) raise CommentaireDejaExistant('le commentaire de"'+ pVersionSource+'/'+pEtatSource+ '" et "'+pVersionCible+'/'+pEtatCible+ '" est deja existant', comment) # Methode privee qui creer le noeud a inserer dans le fichier xml def __creerCommentaire(self, pCommentaire): comment = pCommentaire.getCommentaire() xmldoc = Document() xmltagComment = xmldoc.createElement(B_COMMENTAIRE) xmltagComment.appendChild(xmldoc.createTextNode(comment)) return xmltagComment # Methode qui ajoute un commentaire a l'ancien def ajouterCommentaire(self, pCheminInfos, pVersionSource, pEtatSource, pVersionCible, pEtatCible, pParametres, pCommentaire): ## print 'dans donneesInformations.ajouterCommentaire' # On recupere dans fic les informations du fichier Informations.xml dont # le chemin est passe en parametre fic = lireDocXml(pCheminInfos) liste = fic.getElementsByTagName(B_INFORMATIONS) infos = self.__rechercherInfos(liste, pVersionSource, pEtatSource, pVersionCible, pEtatCible, pParametres) lc = infos.getElementsByTagName(B_COMMENTAIRE) if lc == []: ## creer et ajouter le noeud 'commentaire' comment = self.__creerCommentaire(pCommentaire) infos.appendChild(comment) else : xmldoc=Document() comment =' '+ pCommentaire.getCommentaire() lc[0].appendChild(xmldoc.createTextNode(comment)) ecrireDocXml(pCheminInfos, fic) # Methode qui remplace l'ancien commentaire par le nouveau def remplacerCommentaire(self, pCheminInfos, pVersionSource, pEtatSource, pVersionCible, pEtatCible, pParametres, pCommentaire): ## print 'dans donneesInformations.remplacerCommentaire' # On recupere dans fic les informations du fichier Informations.xml dont le chemin est passe en parametre fic = lireDocXml(pCheminInfos) liste = fic.getElementsByTagName(B_INFORMATIONS) infos = self.__rechercherInfos(liste, pVersionSource, pEtatSource, pVersionCible, pEtatCible, pParametres) lc = infos.getElementsByTagName(B_COMMENTAIRE) comment = self.__creerCommentaire(pCommentaire) if lc != [] : infos.removeChild(lc[0]) infos.appendChild(comment) ecrireDocXml(pCheminInfos,fic) # Methode qui supprime le commentaire d'un couple de etat def supprimerCommentaire(self, pCheminInfos, pVersionSource, pEtatSource, pVersionCible, pEtatCible, pParametres): ## print 'dans donneesInformations.supprimerCommentaire' # On recupere dans fic les informations du fichier Informations.xml dont le chemin est passe en parametre fic = lireDocXml(pCheminInfos) liste = fic.getElementsByTagName(B_INFORMATIONS) infos = self.__rechercherInfos(liste, pVersionSource, pEtatSource, pVersionCible, pEtatCible, pParametres) lc = infos.getElementsByTagName(B_COMMENTAIRE) if lc != [] : infos.removeChild(lc[0]) ecrireDocXml(pCheminInfos, fic) else : raise CommentaireNonTrouve('les informations de "'+pVersionSource+'/' +pEtatSource+'" et "'+pVersionCible+'/' +pEtatCible+'" n\'ont pas de commentaire') # Methode qui supprimme les informations d'un couple de etat def supprimerInformations(self, pCheminInfos, pVersionSource, pEtatSource, pVersionCible, pEtatCible, pParametres): ## print 'dans donneesInformations.supprimerInformations' # On recupere dans fic les informations du fichier Informations.xml dont # le chemin est passe en parametre fic = lireDocXml(pCheminInfos) noderoot = fic.getElementsByTagName(B_ROOT) liste = fic.getElementsByTagName(B_INFORMATIONS) infos = self.__rechercherInfos(liste, pVersionSource, pEtatSource, pVersionCible, pEtatCible, pParametres) if infos != None: ## suppression du noeud noderoot[0].removeChild(infos) ecrireDocXml(pCheminInfos,fic) # Methode qui supprimme la version de l'arbre def supprimerVersion(self, pCheminInfos,pVersionName): fic = lireDocXml(pCheminInfos) larbre = fic.getElementsByTagName(B_ARBRE) lVersions = larbre[0].getElementsByTagName(B_VERSION) for version in lVersions: if version.getAttribute(B_ID)==pVersionName: # suppression du noeud larbre[0].removeChild(version) ecrireDocXml(pCheminInfos,fic) return # Methode qui supprimme un état d'une version def supprimerEtat(self, pCheminInfos,pVersionName,pEtatName): fic = lireDocXml(pCheminInfos) lVersions = fic.getElementsByTagName(B_VERSION) for version in lVersions: if version.getAttribute(B_ID) == pVersionName: for etat in version.getElementsByTagName(B_ETAT): if etat.getAttribute(B_ID) == pEtatName: # pas forcément version car un état peut avoir une autre version comme parent parent = etat.parentNode parent.removeChild(etat) ecrireDocXml(pCheminInfos,fic) return # Methode qui enregistre les informations (transformations + commentaire) d'un couple de etats def enregistrerInformations(self, pCheminInfos, pVersionSource, pEtatSource, pVersionCible, pEtatCible, pParametres, pTransformations, pCommentaire): ## print 'dans donneesInformations.enregistrerInformations' if not self.existeInformations(pCheminInfos, pVersionSource, pEtatSource, pVersionCible, pEtatCible, pParametres ): self.enregistrerTransformations(pCheminInfos, pVersionSource, pEtatSource, pVersionCible, pEtatCible, pParametres, pTransformations) self.enregistrerCommentaire(pCheminInfos, pVersionSource, pEtatSource, pVersionCible, pEtatCible, pParametres, pCommentaire) # Methode privee qui renvoie la balise "informations" recherchee def __rechercherInfos(self, pListeBalise, pVersionSource, pEtatSource, pVersionCible, pEtatCible, pParametres): tmp1 = '%s' %pParametres.getp1() tmp2 = '%s' %pParametres.getp2() tmp3 = '%s' %pParametres.getp3() tmp4 = '%s' %pParametres.getp4() tmp5 = '%s' %pParametres.getp5() tmp6 = '%s' %pParametres.getp6() tmp7 = '%s' %pParametres.getp7() # sys.stderr.write("__rechercherInfos "+pParametres.toString()) # sys.stderr.flush() for node in pListeBalise : if (node.getAttribute(B_VERS_SOURCE)== pVersionSource and node.getAttribute(B_ETAT_SOURCE)== pEtatSource and node.getAttribute(B_VERS_CIBLE) == pVersionCible and node.getAttribute(B_ETAT_CIBLE) == pEtatCible and node.getAttribute(B_PARAM_1) == tmp1 and node.getAttribute(B_PARAM_2) == tmp2 and node.getAttribute(B_PARAM_3) == tmp3 and node.getAttribute(B_PARAM_4) == tmp4 and node.getAttribute(B_PARAM_5) == tmp5 and node.getAttribute(B_PARAM_6) == tmp6 and node.getAttribute(B_PARAM_7) == tmp7): return node return None # raise InformationsNonTrouvees('les informations de "'+pVersionSource+ # '/'+pEtatSource+'" et "'+pVersionCible+ # '/'+pEtatCible+'" n\'existent pas') # retourne le nom des ID des etats fils d'un état # qui correspondent aux noms de fichier def getListeEtatsFils(self,pCheminInfos, pName, pNomVersion): lef = [] fic = lireDocXml(pCheminInfos) larbre = fic.getElementsByTagName(B_ARBRE) for version in larbre[0].getElementsByTagName(B_VERSION): if version.getAttribute(B_ID) == pNomVersion: for etat in version.getElementsByTagName(B_ETAT): if etat.getAttribute(B_ID) == pName: lEtatsFils = etat.getElementsByTagName(B_ETAT) for etatFils in lEtatsFils: lef.append(etatFils.getAttribute(B_ID)) return lef return [] # lit l'arbre des versions à partir du fichier xml # renvoie un Arbre def getArbre(self,pCheminInfos): lFils = [] fic = lireDocXml(pCheminInfos) larbre = fic.getElementsByTagName(B_ARBRE) for version in larbre[0].getElementsByTagName(B_VERSION): lFils.append(self.__getFils(version)) return Arbre(lFils) # lit les fils d'un noeud version ou état # et retourne ce noeud en tant que Version ou Etat def __getFils(self,pere): lFils = [] name = pere.getAttribute(B_ID) for fils in pere.childNodes: lFils.append(self.__getFils(fils)) if pere.tagName == B_VERSION: return Version(name, lFils) else: return Etat(name, lFils)