Salome HOME
Documentation and code minor corrections
[modules/adao.git] / src / daEficas / traduitADAOV8_4_0ToV9_2_0.py
1 # -*- coding: utf-8 -*-
2 #
3 # Copyright (C) 2008-2018 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
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_2_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     )
44
45 dict_erreurs = {
46     }
47
48 sys.dict_erreurs=dict_erreurs
49
50 def traduc(infile=None,outfile=None,texte=None,flog=None):
51     hdlr = log.initialise(flog)
52     if infile is not None:
53         jdc  = getJDC(infile,atraiter)
54     elif texte is not None:
55         jdc  = getJDCFromTexte(texte,atraiter)
56     else:
57         raise ValueError("Traduction du JDC impossible")
58     # ==========================================================================
59
60
61     # ==========================================================================
62     fsrc = jdc.getSource()
63     fsrc = re.sub( "#VERSION_CATALOGUE:.*:FIN VERSION_CATALOGUE", "#VERSION_CATALOGUE:%s:FIN VERSION_CATALOGUE"%version_out, fsrc)
64     fsrc = re.sub( "#CHECKSUM.*FIN CHECKSUM", "", fsrc )
65     #
66     log.ferme(hdlr)
67     if outfile is not None:
68         with open(outfile,'w') as f:
69             f.write( fsrc )
70     else:
71         return fsrc
72
73 class MonTraducteur:
74     def __init__(self,texte):
75         self.__texte = str(texte)
76     def traduit(self):
77         return traduc(infile=None,outfile=None,texte=self.__texte,flog=None)
78
79 def main():
80     parser = argparse.ArgumentParser(usage=usage)
81
82     parser.add_argument('-i','--infile', dest="infile",
83         help="Le fichier COMM en entree, a traduire")
84     parser.add_argument('-o','--outfile', dest="outfile", default='out.comm',
85         help="Le fichier COMM en sortie, traduit")
86
87     args = parser.parse_args()
88     if len(args.infile) == 0:
89         print("")
90         parser.print_help()
91         print("")
92         sys.exit(1)
93
94     traduc(args.infile,args.outfile)
95
96 if __name__ == '__main__':
97     main()