Salome HOME
bug
[tools/eficas.git] / Traducteur / dictErreurs.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2017   EDF R&D
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License.
8 #
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20
21 import logging
22 from Traducteur.load import jdcSet 
23
24
25 def ecritErreur(listeGena,ligne=None) :
26     from sys import dict_erreurs
27     maCle=""
28     for Mot in listeGena :
29         maCle=maCle+"_"+Mot
30     #try :
31     if ( 1 == 1) :
32         maClef=maCle[1:]
33         if maClef in dict_erreurs :
34            if ligne != None :
35               logging.warning("ligne %d : %s ",ligne,dict_erreurs[maClef])
36            else :
37               logging.warning("%s",dict_erreurs[maClef])
38         else :
39            maCle=""
40            for Mot in listeGena[:-1] :
41               maCle=maCle+"_"+Mot
42            maClef=maCle[1:]
43            maClef=maCle+"_"+"VALEUR"
44            if maClef in dict_erreurs :
45               if ligne != None :
46                   logging.warning("ligne %d : %s ",ligne,dict_erreurs[maClef])
47               else :
48                   logging.warning("%s",dict_erreurs[maClef])
49     #except :
50     #    pass
51
52 def genereErreurPourCommande(jdc,listeCommande) :
53     commands= jdc.root.childNodes[:]
54     commands.reverse()
55     for c in commands:
56         if type(listeCommande)==list: 
57             for Mot in listeCommande :
58                if c.name != Mot :continue
59                ecritErreur((Mot,),c.lineno)
60         else:
61             if c.name != listeCommande :continue
62             ecritErreur((listeCommande,),c.lineno)
63
64 def genereErreurMotCleInFact(jdc,command,fact,mocle):
65     for c in jdc.root.childNodes:
66         if c.name != command:continue
67         for mc in c.childNodes:
68             if mc.name != fact:continue
69             l=mc.childNodes[:]
70             for ll in l:
71                 for n in ll.childNodes:
72                     if n.name != mocle:
73                        continue
74                     else :
75                        ecritErreur((command,fact,mocle,),c.lineno)
76
77 def genereErreurMCF(jdc,command,fact):
78     for c in jdc.root.childNodes:
79         if c.name != command:continue
80         for mc in c.childNodes:
81             if mc.name != fact:
82                 continue
83             else : 
84                 ecritErreur((command,fact,),c.lineno)
85
86 def genereErreurValeur(jdc,command,fact,list_valeur):
87     for c in jdc.root.childNodes:
88         if c.name != command:continue
89         for mc in c.childNodes:
90             if mc.name != fact:continue
91             texte=mc.getText(jdc)
92             for valeur in list_valeur:
93                trouve=texte.find(valeur)
94                if trouve > -1 :  
95                   logging.warning("%s doit etre supprimee ou modifiee dans %s : ligne %d",valeur,c.name,mc.lineno)
96
97 def genereErreurValeurDsMCF(jdc,command,fact,mocle,list_valeur):
98     for c in jdc.root.childNodes:
99         if c.name != command:continue
100         for mc in c.childNodes:
101             if mc.name != fact:continue
102             l=mc.childNodes[:]
103             for ll in l:
104                 for n in ll.childNodes:
105                     if n.name != mocle:continue
106                     texte=n.getText(jdc)
107                     for valeur in list_valeur:
108                         trouve=texte.find(valeur)
109                         if trouve > -1 :  
110                             logging.warning("%s doit etre supprimee ou modifiee dans %s : ligne %d",valeur,c.name,n.lineno)