Salome HOME
Documentation corrections and code performance update
[modules/adao.git] / src / daEficas / traduitADAOV7_5_0ToV9_13_0.py
1 # -*- coding: utf-8 -*-
2 #
3 # Copyright (C) 2008-2024 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 argparse # optparse deprecated since Python version 3.2
24 import sys
25 import re
26
27 import Traducteur.log as log
28 from Traducteur.load         import getJDC, getJDCFromTexte
29 from Traducteur.mocles       import parseKeywords
30 from Traducteur.dictErreurs  import genereErreurPourCommande
31 from Traducteur.inseremocle  import *
32 from Traducteur.movemocle    import *
33 from Traducteur.renamemocle  import *
34
35 version_out = "V9_13_0"
36
37 usage="""Usage: python %(prog)s [args]
38
39 Typical use is:
40   python %(prog)s --infile=xxxx.comm --outfile=yyyy.comm"""
41
42 atraiter = (
43     "ASSIMILATION_STUDY",
44     "CHECKING_STUDY",
45     )
46
47 dict_erreurs = {
48     "ASSIMILATION_STUDY":"Changements dans l'arbre et dans les noms",
49     "CHECKING_STUDY":"Changements dans l'arbre et dans les noms",
50     }
51
52 sys.dict_erreurs=dict_erreurs
53
54 def traduc(infile=None,outfile=None,texte=None,flog=None):
55     hdlr = log.initialise(flog)
56     if infile is not None:
57         jdc  = getJDC(infile,atraiter)
58     elif texte is not None:
59         jdc  = getJDCFromTexte(texte,atraiter)
60     else:
61         raise ValueError("Traduction du JDC impossible")
62
63     #Parse les mocles des commandes
64     parseKeywords(jdc.root)
65     genereErreurPourCommande(jdc,('Algorithm','AlgorithmParameters','FunctionDict'))
66     # ==========================================================================
67
68     for command in atraiter:
69         # Insere le MC s'il n'existe pas
70         chercheOperInsereFacteurSiRegle(jdc, command, "AlgorithmParameters",((("AlgorithmParameters",),"nexistepasMCFParmi"),))
71         # Deplace le MC
72         moveMotClefInOperToFact(jdc, command, "Algorithm", "AlgorithmParameters", plusieursFois=False)
73         # Renomme le MC
74         renameMotCleInFact(jdc, command, "AlgorithmParameters", "INPUT_TYPE", "Parameters")
75         # Renomme le MC
76         renameMotCle(jdc, command, "Study_name", "StudyName")
77         renameMotCle(jdc, command, "Study_repertory", "StudyRepertory")
78
79     # ==========================================================================
80     fsrc = jdc.getSource()
81     fsrc = re.sub( "MaximumNumberOfSteps", "MaximumNumberOfIterations", fsrc )
82     fsrc = re.sub( "EnableMultiProcessing", "EnableWiseParallelism", fsrc )
83     fsrc = re.sub( "FunctionDict", "ScriptWithSwitch", fsrc )
84     fsrc = re.sub( "FUNCTIONDICT_FILE", "SCRIPTWITHSWITCH_FILE", fsrc )
85     fsrc = re.sub( "#VERSION_CATALOGUE:.*:FIN VERSION_CATALOGUE", "#VERSION_CATALOGUE:%s:FIN VERSION_CATALOGUE"%version_out, fsrc)
86     fsrc = re.sub( "#CHECKSUM.*FIN CHECKSUM", "", fsrc )
87     #
88     log.ferme(hdlr)
89     if outfile is not None:
90         with open(outfile,'w') as f:
91             f.write( fsrc )
92     else:
93         return fsrc
94
95 class MonTraducteur:
96     def __init__(self,texte):
97         self.__texte = str(texte)
98     def traduit(self):
99         return traduc(infile=None,outfile=None,texte=self.__texte,flog=None)
100
101 def main():
102     parser = argparse.ArgumentParser(usage=usage)
103
104     parser.add_argument('-i','--infile', dest="infile",
105         help="Le fichier COMM en entree, a traduire")
106     parser.add_argument('-o','--outfile', dest="outfile", default='out.comm',
107         help="Le fichier COMM en sortie, traduit")
108
109     args = parser.parse_args()
110     if len(args.infile) == 0:
111         print("")
112         parser.print_help()
113         print("")
114         sys.exit(1)
115
116     traduc(args.infile,args.outfile)
117
118 if __name__ == '__main__':
119     main()