1 # -*- coding: utf-8 -*-
3 from dictErreurs import EcritErreur
4 from dictErreurs import jdcSet
5 from renamemocle import decaleLignesdeNBlancs
6 from removemocle import removeMotCleInFact
9 #--------------------------------------------------------------------------
10 def ChangementValeur(jdc,command,motcle,DictNouvVal,liste=(),defaut=0):
11 #--------------------------------------------------------------------------
12 if command not in jdcSet : return
14 for c in jdc.root.childNodes:
15 if c.name != command : continue
17 for mc in c.childNodes:
18 if mc.name != motcle : continue
20 TexteMC=mc.getText(jdc)
21 liste_ligne_MC=TexteMC.splitlines()
22 indexLigneGlob=mc.lineno-1
24 while indexLigneGlob < mc.endline :
25 if indexTexteMC > len(liste_ligne_MC)-1 : break
26 MaLigneGlob=jdc.getLines()[indexLigneGlob]
27 MaLigneTexte=liste_ligne_MC[indexTexteMC]
28 for Valeur in DictNouvVal.keys() :
29 trouve=MaLigneTexte.find(Valeur)
31 debut=MaLigneGlob.find(motcle)
32 if debut==-1 : debut=0
33 Nouveau=MaLigneGlob[debut:].replace(Valeur,DictNouvVal[Valeur])
34 Nouveau=MaLigneGlob[0:debut]+Nouveau
35 jdc.getLines()[indexLigneGlob]=Nouveau
36 MaLigneTexte=Nouveau # raccourci honteux mais ...
39 EcritErreur((command,motcle,Valeur),indexLigneGlob)
41 logging.info("Changement de %s par %s dans %s ligne %d",Valeur,DictNouvVal[Valeur],command,indexLigneGlob)
43 indexLigneGlob=indexLigneGlob+1
44 indexTexteMC=indexTexteMC+1
45 if (trouveUnMC == 0) and ( defaut == 1):
46 EcritErreur((command,motcle,"DEFAUT"),c.lineno)
47 if boolChange : jdc.reset(jdc.getSource())
49 #--------------------------------------------------------------------------------
50 def ChangementValeurDsMCF(jdc,command,fact,motcle,DictNouvVal,liste=(),defaut=0):
51 #--------------------------------------------------------------------------------
53 if command not in jdcSet : return
55 for c in jdc.root.childNodes:
56 if c.name != command : continue
57 for mcF in c.childNodes:
58 if mcF.name != fact : continue
63 for mc in ll.childNodes:
64 if mc.name != motcle:continue
66 TexteMC=mc.getText(jdc)
67 liste_ligne_MC=TexteMC.splitlines()
68 indexLigneGlob=mc.lineno-1
70 while indexLigneGlob < mc.endline :
71 if indexTexteMC > len(liste_ligne_MC)-1 : break
72 MaLigneGlob=jdc.getLines()[indexLigneGlob]
73 MaLigneTexte=liste_ligne_MC[indexTexteMC]
74 for Valeur in DictNouvVal.keys() :
75 trouve=MaLigneTexte.find(Valeur)
77 debut=MaLigneGlob.find(motcle)
78 if debut==-1 : debut=0
79 Nouveau=MaLigneGlob[debut:].replace(Valeur,DictNouvVal[Valeur])
80 Nouveau=MaLigneGlob[0:debut]+Nouveau
81 jdc.getLines()[indexLigneGlob]=Nouveau
82 MaLigneTexte=Nouveau # raccourci honteux mais ...
85 EcritErreur((command,fact,motcle,Valeur),indexLigneGlob)
87 logging.info("Changement de %s par %s dans %s ligne %d",Valeur,DictNouvVal[Valeur],command,indexLigneGlob)
89 indexLigneGlob=indexLigneGlob+1
90 indexTexteMC=indexTexteMC+1
91 if (trouveUnMC == 0) and ( defaut == 1):
92 logging.warning("OPTION (defaut) de CALCG à verifier ligne %s" ,c.lineno )
93 EcritErreur((command,fact,motcle,"DEFAUT"),c.lineno)
94 if boolChange : jdc.reset(jdc.getSource())
96 #---------------------------------------------------------------------------------------
97 def ChangementValeurDsMCFAvecAvertissement(jdc, command, fact,motcle,DictNouvVal,liste):
98 #---------------------------------------------------------------------------------------
99 if command not in jdcSet : return
101 if liste[-1] == "defaut" :
103 ChangementValeurDsMCF(jdc,command,fact,motcle,DictNouvVal,liste,defaut)
105 #--------------------------------------------------------------------------
106 def ChangementValeurAvecAvertissement(jdc, command,motcle,DictNouvVal,liste):
107 #--------------------------------------------------------------------------
108 if command not in jdcSet : return
110 if liste[-1] == "defaut" :
112 ChangementValeur(jdc,command,motcle,DictNouvVal,liste,defaut)
114 #--------------------------------------------------------------------------
115 def SuppressionValeurs(jdc, command,motcle,liste):
116 #--------------------------------------------------------------------------
118 if command not in jdcSet : return
120 for c in jdc.root.childNodes:
121 if c.name != command : continue
122 for mc in c.childNodes:
123 if mc.name != motcle : continue
124 indexLigneGlob=mc.lineno-1
125 while indexLigneGlob < mc.endline :
126 MaLigneTexte = jdc.getLines()[indexLigneGlob]
128 for Valeur in liste :
129 debutMC =MaLigne.find(motcle)
130 if debutMC ==-1 : debutMC=0
131 debut1=MaLigne[0:debutMC]
132 chercheLigne=MaLigne[debutMC:]
133 trouve=chercheLigne.find(Valeur)
136 debut=debut1 + chercheLigne[0:trouve]
138 while (-1 * index) < len(debut) :
139 if (debut[index] == "(") :
146 if (debut[index] == "," ) :
148 if (debut[index] != " " ) :
151 debLigne = debut[0:index]
152 fin=trouve+len(Valeur)
153 if premier == 1 : fin = fin + 1 # on supprime la ,
154 finLigne = chercheLigne[fin:]
155 MaLigne=debLigne+finLigne
157 jdc.getLines()[indexLigneGlob]=MaLigne
158 indexLigneGlob=indexLigneGlob+1
159 if boolChange : jdc.reset(jdc.getSource())
161 #----------------------------------------------
162 def AppelleMacroSelonValeurConcept(jdc,macro,genea):
163 #----------------------------------------------
164 if macro not in jdcSet : return
169 for c in jdc.root.childNodes:
170 if c.name != macro : continue
171 for mcF in c.childNodes:
172 if mcF.name != fact : continue
177 for mc in ll.childNodes:
178 if mc.name != motcle:continue
179 TexteMC=mc.getText(jdc)
180 liste_ligne_MC=TexteMC.splitlines()
181 indexLigneGlob=mc.lineno-2
187 while indexLigneGlob < mc.endline :
188 indexLigneGlob=indexLigneGlob+1
189 MaLigneTexte=jdc.getLines()[indexLigneGlob]
191 # on commence par chercher TABLE par exemple
192 # si on ne trouve pas on passe a la ligne suivante
193 if ( trouveTexteMC == 0 ) :
194 indice=MaLigneTexte.find(motcle)
195 if indice < 0 : continue
201 aChercher=MaLigneTexte[indice:]
202 if (trouveegal == 0 ):
203 indice=aChercher.find("=")
204 if indice < 0 : continue
210 aChercher2=aChercher[indice:]
211 if (trouvechaine == 0 ):
212 indice=aChercher2.find(chaine)
213 if indice < 0 : continue
219 aChercher3=aChercher2[indice:]
220 if (trouveparent == 0 ):
221 indice=aChercher3.find('(')
222 if indice < 0 : continue
228 aChercher4=aChercher3[indice:]
229 if (trouvequote == 0 ):
230 indice=aChercher4.find("'")
231 indice2=aChercher4.find('"')
232 if (indice < 0) and (indice2 < 0): continue
233 if (indice < 0) : indice=indice2
239 aChercher5=aChercher4[indice+1:]
240 indice=aChercher5.find("'")
241 if indice < 0 : indice=aChercher5.find('"')
242 valeur=aChercher5[:indice]
246 logging.error("Pb de traduction pour MACR_LIGNE_COUPE : Pas de nom de Concept identifiable")
250 jdc.reset(jdc.getSource())
251 logging.error("Pb du traduction pour MACR_LIGNE_COUPE : Deux noms de Concept possibles")
255 ligneaTraiter=jdc.getLines()[c.lineno-1]
256 debut=ligneaTraiter[0:c.colno]
258 fin=ligneaTraiter[c.colno:]
259 ligne=debut+suite+fin
260 jdc.getLines()[c.lineno-1]=ligne
261 nbBlanc=len(valeur)+1
262 if c.lineno < c.endline:
263 decaleLignesdeNBlancs(jdc,c.lineno,c.endline-1,nbBlanc)
264 if boolChange : jdc.reset(jdc.getSource())
266 #----------------------------------------------
267 def ChangeTouteValeur(jdc,command,motcle,DictNouvVal,liste=(),defaut=0):
268 #----------------------------------------------
269 if macro not in jdcSet : return