]> SALOME platform Git repositories - modules/adao.git/blob - src/daEficas/traduitADAOsansToV7_6_0.py
Salome HOME
Documentation and source minor corrections and improvements
[modules/adao.git] / src / daEficas / traduitADAOsansToV7_6_0.py
1 #-*-coding:iso-8859-1-*-
2 #
3 # Copyright (C) 2008-2015 EDF R&D
4 #
5 # This file is part of SALOME ADAO module
6 #
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License.
11 #
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 # Lesser General Public License for more details.
16 #
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
20 #
21 # Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D
22
23 import log
24 import optparse
25 import sys
26 import re
27
28 from load   import getJDC, getJDCFromTexte
29 from mocles import parseKeywords
30 from removemocle  import *
31 from renamemocle  import *
32 from renamemocle  import *
33 from inseremocle  import *
34 from changeValeur import *
35 from movemocle    import *
36 from dictErreurs  import *
37 from regles import pasDeRegle
38
39 version_out = "V7_6_0"
40
41 usage="""Usage: python %prog [options]
42
43 Typical use is:
44   python %prog --infile=xxxx.comm --outfile=yyyy.comm"""
45
46 atraiter = (
47     "ASSIMILATION_STUDY",
48     "CHECKING_STUDY",
49     )
50
51 dict_erreurs = {
52     "ASSIMILATION_STUDY":"Changements dans l'arbre et dans les noms",
53     "CHECKING_STUDY":"Changements dans l'arbre et dans les noms",
54     }
55
56 sys.dict_erreurs=dict_erreurs
57
58 def traduc(infile=None,outfile=None,texte=None,flog=None):
59     hdlr = log.initialise(flog)
60     if infile is not None:
61         jdc  = getJDC(infile,atraiter)
62     elif texte is not None:
63         jdc  = getJDCFromTexte(texte,atraiter)
64     else:
65         raise ValueError("Traduction du JDC impossible")
66
67     #Parse les mocles des commandes
68     parseKeywords(jdc.root)
69     GenereErreurPourCommande(jdc,('Algorithm','AlgorithmParameters','FunctionDict'))
70     # ==========================================================================
71
72     for command in atraiter:
73         # Insere le MC s'il n'existe pas
74         chercheOperInsereFacteurSiRegle(jdc, command, "AlgorithmParameters",((("AlgorithmParameters",),"nexistepasMCFParmi"),))
75         # Deplace le MC
76         moveMotClefInOperToFact(jdc, command, "Algorithm", "AlgorithmParameters")
77         # Renomme le MC
78         renameMotCleInFact(jdc, command, "AlgorithmParameters", "INPUT_TYPE", "Parameters")
79         # Renomme le MC
80         renameMotCle(jdc, command, "Study_name", "StudyName")
81         renameMotCle(jdc, command, "Study_repertory", "StudyRepertory")
82
83     # ==========================================================================
84     fsrc = jdc.getSource()
85     fsrc = re.sub( "FunctionDict", "ScriptWithSwitch", fsrc )
86     fsrc = re.sub( "FUNCTIONDICT_FILE", "SCRIPTWITHSWITCH_FILE", fsrc )
87     fsrc = re.sub( "#VERSION_CATALOGUE:.*:FIN VERSION_CATALOGUE", "#VERSION_CATALOGUE:%s:FIN VERSION_CATALOGUE"%version_out, fsrc)
88     fsrc = re.sub( "#CHECKSUM.*FIN CHECKSUM", "", fsrc )
89     #
90     log.ferme(hdlr)
91     if outfile is not None:
92         f=open(outfile,'w')
93         f.write( fsrc )
94         f.close()
95     else:
96         return fsrc
97
98 class MonTraducteur:
99     def __init__(self,texte):
100         self.__texte = str(texte)
101     def traduit(self):
102         return traduc(infile=None,outfile=None,texte=self.__texte,flog=None)
103
104 def main():
105     parser = optparse.OptionParser(usage=usage)
106
107     parser.add_option('-i','--infile', dest="infile",
108         help="Le fichier COMM en entree, a traduire")
109     parser.add_option('-o','--outfile', dest="outfile", default='out.comm',
110         help="Le fichier COMM en sortie, traduit")
111
112     options, args = parser.parse_args()
113     if len(options.infile) == 0:
114         print
115         parser.print_help()
116         print
117         sys.exit(1)
118
119     traduc(options.infile,options.outfile)
120
121 if __name__ == '__main__':
122     main()