From a77d55e9dd314ae9baeed59d219661ebd8d2ecf5 Mon Sep 17 00:00:00 2001 From: Gilles DAVID Date: Wed, 24 May 2017 14:24:28 +0200 Subject: [PATCH] Porting python3: optparse and string are obsolete modules --- bin/AdaoCatalogGenerator.py | 140 ++++++++++------------ bin/AdaoYacsSchemaCreator.py | 17 ++- src/daEficas/traduitADAOV7_4_0ToV8_3_0.py | 23 ++-- src/daEficas/traduitADAOV7_5_0ToV8_3_0.py | 23 ++-- src/daEficas/traduitADAOV7_5_1ToV8_3_0.py | 23 ++-- src/daEficas/traduitADAOV7_6_0ToV8_3_0.py | 23 ++-- src/daEficas/traduitADAOV7_7_0ToV8_3_0.py | 23 ++-- src/daEficas/traduitADAOV7_8_0ToV8_3_0.py | 23 ++-- src/daEficas/traduitADAOV8_1_0ToV8_3_0.py | 23 ++-- src/daEficas/traduitADAOV8_2_0ToV8_3_0.py | 23 ++-- src/daEficas/traduitADAOsansToV8_3_0.py | 23 ++-- src/daSalome/daYacsSchemaCreator/run.py | 1 - 12 files changed, 168 insertions(+), 197 deletions(-) diff --git a/bin/AdaoCatalogGenerator.py b/bin/AdaoCatalogGenerator.py index 68f498a..2f5993d 100644 --- a/bin/AdaoCatalogGenerator.py +++ b/bin/AdaoCatalogGenerator.py @@ -25,8 +25,8 @@ import logging import traceback import sys -import string import io +import os import module_version @@ -58,7 +58,7 @@ begin_catalog_file = """#-*-coding:iso-8859-1-*- # Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D # -------------------------------------------------------- -# Generated by AdaoCatalogGenerator on ${date} +# Generated by AdaoCatalogGenerator on {date} # -------------------------------------------------------- import os, re @@ -85,7 +85,7 @@ def DirectOperatorInNS(filename): for ln in fc: if cr.match(ln): return 1 return 0 -DirectOperatorInNS.info = u"The Python file has to contain explicitly a \\"DirectOperator\\" function definition with only one vector as argument." +DirectOperatorInNS.info = "The Python file has to contain explicitly a \\"DirectOperator\\" function definition with only one vector as argument." def TangentOperatorInNS(filename): if os.path.exists(filename): fc = open(filename, 'r').readlines() @@ -96,7 +96,7 @@ def TangentOperatorInNS(filename): for ln in fc: if cr.match(ln): return 1 return 0 -TangentOperatorInNS.info = u"The Python file has to contain explicitly a \\"TangentOperator\\" function definition with only one pair of vectors as argument." +TangentOperatorInNS.info = "The Python file has to contain explicitly a \\"TangentOperator\\" function definition with only one pair of vectors as argument." def AdjointOperatorInNS(filename): if os.path.exists(filename): fc = open(filename, 'r').readlines() @@ -107,20 +107,20 @@ def AdjointOperatorInNS(filename): for ln in fc: if cr.match(ln): return 1 return 0 -AdjointOperatorInNS.info = u"The Python file has to contain explicitly an \\"AdjointOperator\\" function definition with only one pair of vectors as argument." +AdjointOperatorInNS.info = "The Python file has to contain explicitly an \\"AdjointOperator\\" function definition with only one pair of vectors as argument." """%(module_version.name,module_version.version) # Important : validators=[...] pour que les conditions soient traitées simultanément, en "ET", et pas en "OU" (choisi dans le cas du tuple à la place de la liste) # validators=[OnlyStr(), FileExtVal('py'), FunctionVal(fv)] data_method = """ -def F_${data_name}(statut, fv=NoCheckInNS) : return FACT( +def F_{data_name}(statut, fv=NoCheckInNS) : return FACT( statut = statut, - FROM = SIMP(statut = "o", typ = "TXM", into=(${data_into}), defaut=${data_default}), + FROM = SIMP(statut = "o", typ = "TXM", into=({data_into}), defaut={data_default}), SCRIPT_DATA = BLOC ( condition = " FROM in ( 'Script', ) ", SCRIPT_FILE = SIMP(statut = "o", typ = "FichierNoAbs", validators=[OnlyStr(), FileExtVal('py'), FunctionVal(fv)], fr="En attente d'un nom de fichier script, avec ou sans le chemin complet pour le trouver, contenant si nécessaire la définition d'une variable interne de même nom que le concept parent", ang="Waiting for a script file name, with or without the full path to find it, containing if necessary the definition of an internal variable of the same name as the parent concept"), ), STRING_DATA = BLOC ( condition = " FROM in ( 'String', ) ", - STRING = SIMP(statut = "o", typ = "TXM",${ms_default} fr="En attente d'une chaine de caractères entre guillements. Pour construire un vecteur ou une matrice, ce doit être une suite de nombres, utilisant un espace ou une virgule pour séparer deux éléments et un point-virgule pour séparer deux lignes", ang="Waiting for a string in quotes. To build a vector or a matrix, it has to be a float serie, using a space or comma to separate two elements in a line, a semi-colon to separate rows"), + STRING = SIMP(statut = "o", typ = "TXM",{ms_default} fr="En attente d'une chaine de caractères entre guillements. Pour construire un vecteur ou une matrice, ce doit être une suite de nombres, utilisant un espace ou une virgule pour séparer deux éléments et un point-virgule pour séparer deux lignes", ang="Waiting for a string in quotes. To build a vector or a matrix, it has to be a float serie, using a space or comma to separate two elements in a line, a semi-colon to separate rows"), ), SCRIPTWITHFUNCTIONS_DATA = BLOC ( condition = " FROM in ( 'ScriptWithFunctions', ) ", SCRIPTWITHFUNCTIONS_FILE = SIMP(statut = "o", typ = "FichierNoAbs", validators=[OnlyStr(), FileExtVal('py'), FunctionVal(DirectOperatorInNS), FunctionVal(TangentOperatorInNS), FunctionVal(AdjointOperatorInNS)], fr="En attente d'un nom de fichier script, avec ou sans le chemin complet pour le trouver, contenant en variables internes trois fonctions de calcul nommées DirectOperator, TangentOperator et AdjointOperator", ang="Waiting for a script file name, with or without the full path to find it, containing as internal variables three computation functions named DirectOperator, TangentOperator and AdjointOperator"), @@ -169,31 +169,31 @@ def F_Init(statut) : return FACT(statut = statut, """ assim_data_method = """ -def ${assim_name}InNS(filename): +def {assim_name}InNS(filename): if os.path.exists(filename): fc = open(filename, 'r').readlines() - cr = re.compile("^${assim_name}[\s]*=") + cr = re.compile("^{assim_name}[\s]*=") for ln in fc: if cr.match(ln): return 1 return 0 -${assim_name}InNS.info = u"The Python file has to contain explicitly a \\"${assim_name}\\" variable." -def F_${assim_name}(statut, fv=NoCheckInNS) : return FACT( +{assim_name}InNS.info = "The Python file has to contain explicitly a \\"{assim_name}\\" variable." +def F_{assim_name}(statut, fv=NoCheckInNS) : return FACT( statut=statut, -${storage} - INPUT_TYPE = SIMP(statut="o", typ = "TXM", into=(${choices}), defaut=${default_choice}),${decl_choices} +{storage} + INPUT_TYPE = SIMP(statut="o", typ = "TXM", into=({choices}), defaut={default_choice}),{decl_choices} ) """ assim_data_choice = """ - ${choice_name} = BLOC ( condition = " INPUT_TYPE in ( '${choice_name}', ) ", - data = F_${choice_name}("o", fv), + {choice_name} = BLOC ( condition = " INPUT_TYPE in ( '{choice_name}', ) ", + data = F_{choice_name}("o", fv), ),""" observers_choice = """ - ${var_name} = BLOC (condition=" '${var_name}' in set(SELECTION) ", - ${var_name}_data = FACT(statut = "o", + {var_name} = BLOC (condition=" '{var_name}' in set(SELECTION) ", + {var_name}_data = FACT(statut = "o", Scheduler = SIMP(statut = "f", typ = "TXM"), - Info = SIMP(statut = "o", typ = "TXM", defaut = "${var_name}"), + Info = SIMP(statut = "o", typ = "TXM", defaut = "{var_name}"), NodeType = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "Template", into=("String", "Script", "Template")), PythonScript = BLOC (condition = " NodeType == 'String' ", Value = SIMP(statut = "o", typ = "TXM") @@ -224,7 +224,7 @@ def F_ObserverTemplate() : return BLOC(condition = " NodeType == 'Template' ", def F_Observers(statut) : return FACT( statut=statut, - SELECTION = SIMP(statut="o", defaut=[], typ="TXM", min=0, max="**", homo="SansOrdreNiDoublon", validators=NoRepeat(), into=(${choices})),${decl_choices} + SELECTION = SIMP(statut="o", defaut=[], typ="TXM", min=0, max="**", homo="SansOrdreNiDoublon", validators=NoRepeat(), into=({choices})),{decl_choices} ) """%(observers_list,observers_cont) @@ -236,7 +236,7 @@ def AlgorithmParametersInNS(filename): for ln in fc: if cr.match(ln): return 1 return 0 -AlgorithmParametersInNS.info = u"The Python file has to contain explicitly an \\"AlgorithmParameters\\" variable." +AlgorithmParametersInNS.info = "The Python file has to contain explicitly an \\"AlgorithmParameters\\" variable." def F_AlgorithmParameters(statut, algos_names, fv=NoCheckInNS) : return FACT( statut = statut, Algorithm = SIMP(statut="o", typ = "TXM", into = algos_names ), @@ -244,13 +244,13 @@ def F_AlgorithmParameters(statut, algos_names, fv=NoCheckInNS) : return FACT( Dict = BLOC ( condition = " Parameters == 'Dict' ", statut="f", data = F_Dict("o", fv), - ),${all_algo_defaults} + ),{all_algo_defaults} ) """ one_algo_choices = """ - Parameters${algo_name} = BLOC (condition = " (Parameters == 'Defaults') and (Algorithm == '${algo_name}') ", + Parameters{algo_name} = BLOC (condition = " (Parameters == 'Defaults') and (Algorithm == '{algo_name}') ", statut="f", -${algo_parameters} ),""" +{algo_parameters} ),""" assim_study = """ def F_variables(statut) : return FACT( @@ -270,7 +270,7 @@ ASSIMILATION_STUDY = PROC(nom="ASSIMILATION_STUDY", StudyName = SIMP(statut="o", typ = "TXM", defaut="ADAO Calculation Case"), StudyRepertory = SIMP(statut="f", typ = "Repertoire", validators=FunctionVal(ChDir), min=1, max=1), Debug = SIMP(statut="f", typ = "I", into=(0, 1), defaut=0), - AlgorithmParameters = F_AlgorithmParameters("o",(${algos_names}), AlgorithmParametersInNS), + AlgorithmParameters = F_AlgorithmParameters("o",({algos_names}), AlgorithmParametersInNS), Background = F_Background("o", BackgroundInNS), BackgroundError = F_BackgroundError("o", BackgroundErrorInNS), Observation = F_Observation("o", ObservationInNS), @@ -292,7 +292,7 @@ CHECKING_STUDY = PROC(nom="CHECKING_STUDY", StudyName = SIMP(statut="o", typ = "TXM", defaut="ADAO Checking Case"), StudyRepertory = SIMP(statut="f", typ = "Repertoire", validators=FunctionVal(ChDir), min=1, max=1), Debug = SIMP(statut="f", typ = "I", into=(0, 1), defaut=0), - AlgorithmParameters = F_AlgorithmParameters("o", (${check_names}), AlgorithmParametersInNS), + AlgorithmParameters = F_AlgorithmParameters("o", ({check_names}), AlgorithmParametersInNS), CheckingPoint = F_CheckingPoint("o", CheckingPointInNS), BackgroundError = F_BackgroundError("f", BackgroundErrorInNS), Observation = F_Observation("f", ObservationInNS), @@ -303,16 +303,6 @@ CHECKING_STUDY = PROC(nom="CHECKING_STUDY", ) """ -begin_catalog_file = string.Template(begin_catalog_file) -data_method = string.Template(data_method) -assim_data_method = string.Template(assim_data_method) -assim_data_choice = string.Template(assim_data_choice) -assim_study = string.Template(assim_study) -observers_method = string.Template(observers_method) -observers_choice = string.Template(observers_choice) -algo_choices = string.Template(algo_choices) -one_algo_choices = string.Template(one_algo_choices) - #----------- End of Templates Part ---------------# @@ -331,29 +321,21 @@ except: traceback.print_exc() sys.exit(1) -def check_args(args): - logging.debug("Arguments are :" + str(args)) - if len(args) != 2: - logging.fatal("Bad number of arguments: you have to provide two arguments (%d given)" % (len(args))) - sys.exit(1) - # Parse arguments -from optparse import OptionParser -usage = "usage: %prog [options] catalog_path catalog_name" -version="%prog 0.1" -my_parser = OptionParser(usage=usage, version=version) -(options, args) = my_parser.parse_args() -check_args(args) - -catalog_path = args[0] -catalog_name = args[1] +from argparse import ArgumentParser +usage = "usage: %(prog)s [options] catalog_path catalog_name" +version="%(prog)s 0.1" +my_parser = ArgumentParser(usage=usage, version=version) +my_parser.add_argument('catalog_path') +my_parser.add_argument('catalog_name') +args = my_parser.parse_args() # Generates into a string mem_file = io.StringIO() # Start file from time import strftime -mem_file.write(begin_catalog_file.substitute(date=strftime("%Y-%m-%d %H:%M:%S"))) +mem_file.write(begin_catalog_file.format(**{'date':strftime("%Y-%m-%d %H:%M:%S")})) # Step initial: on obtient la liste des algos algos_names = "" @@ -390,11 +372,11 @@ for data_input_name in infos.DataTypeDict: if data_input_name in infos.DataSValueDefaultDict: ms_default = " defaut=\"" + infos.DataSValueDefaultDict[data_input_name] + "\"," - mem_file.write(data_method.substitute(data_name = data_name, - data_into = data_into, - data_default = data_default, - ms_default = ms_default, - algos_names = algos_names+check_names)) + mem_file.write(data_method.format(**{'data_name' : data_name, + 'data_into' : data_into, + 'data_default' : data_default, + 'ms_default' : ms_default, + 'algos_names' : algos_names+check_names})) # Step 2: On cree les fonctions qui permettent de rentrer les donnees des algorithmes for assim_data_input_name in infos.AssimDataDict: @@ -409,16 +391,16 @@ for assim_data_input_name in infos.AssimDataDict: storage = " Stored = SIMP(statut=\"f\", typ = \"I\", into=(0, 1), defaut=0, fr=\"Choix de stockage interne ou non du concept parent\", ang=\"Choice of the storage or not of the parent concept\")," for choice in infos.AssimDataDict[assim_data_input_name]: choices += "\"" + choice + "\", " - decl_choices += assim_data_choice.substitute(choice_name = choice) + decl_choices += assim_data_choice.format(**{'choice_name' : choice}) if choice in infos.StoredAssimData: storage = " Stored = SIMP(statut=\"f\", typ = \"I\", into=(0, 1), defaut=0, fr=\"Choix de stockage interne ou non du concept parent\", ang=\"Choice of the storage or not of the parent concept\")," default_choice = "\"" + infos.AssimDataDefaultDict[assim_data_input_name] + "\"" - mem_file.write(assim_data_method.substitute(assim_name = assim_data_input_name, - storage = storage, - choices = choices, - decl_choices = decl_choices, - default_choice = default_choice)) + mem_file.write(assim_data_method.format(**{'assim_name' : assim_data_input_name, + 'storage' : storage, + 'choices' : choices, + 'decl_choices' : decl_choices, + 'default_choice' : default_choice})) # Step 3: On ajoute les fonctions representant les options possibles for opt_name in infos.OptDict: @@ -436,11 +418,11 @@ for opt_name in infos.OptDict: if opt_name in infos.DataSValueDefaultDict: ms_default = " defaut=\"" + infos.DataSValueDefaultDict[opt_name] + "\"," - mem_file.write(data_method.substitute(data_name = data_name, - data_into = data_into, - data_default = data_default, - ms_default = ms_default, - algos_names = algos_names+check_names)) + mem_file.write(data_method.format(**{'data_name' : data_name, + 'data_into' : data_into, + 'data_default' : data_default, + 'ms_default' : ms_default, + 'algos_names' : algos_names+check_names})) # Step 4: On ajoute la methode optionnelle init # TODO uniformiser avec le step 3 @@ -449,9 +431,9 @@ mem_file.write(init_method) # Step 5: Add observers decl_choices = "" for obs_var in infos.ObserversList: - decl_choices += observers_choice.substitute(var_name=obs_var) -mem_file.write(observers_method.substitute(choices = infos.ObserversList, - decl_choices = decl_choices)) + decl_choices += observers_choice.format(**{'var_name':obs_var}) +mem_file.write(observers_method.format(**{'choices' : infos.ObserversList, + 'decl_choices' : decl_choices})) # Step 5: Add algorithmic choices @@ -490,19 +472,19 @@ for algo in all_names: algo_parameters += """ %s = SIMP(statut="f", typ="TXM", fr="%s"),\n"""%(pn,pm) del assim_study_object if algo_parameters != "": - all_algo_defaults += one_algo_choices.substitute( - algo_name=algo, - algo_parameters=algo_parameters, + all_algo_defaults += one_algo_choices.format( + **{'algo_name':algo, + 'algo_parameters':algo_parameters,} ) -mem_file.write(algo_choices.substitute(all_algo_defaults=all_algo_defaults)) +mem_file.write(algo_choices.format(**{'all_algo_defaults':all_algo_defaults})) # Final step: Add algorithm and assim_study -mem_file.write(assim_study.substitute(algos_names=algos_names, - check_names=check_names, - decl_algos=decl_algos)) +mem_file.write(assim_study.format(**{'algos_names':algos_names, + 'check_names':check_names, + 'decl_algos':decl_algos})) # Write file -with open(catalog_path + "/" + catalog_name, "w") as final_file: +with open(os.path.join(args.catalog_path, args.catalog_name), "w", encoding='utf8') as final_file: final_file.write(mem_file.getvalue()) mem_file.close() diff --git a/bin/AdaoYacsSchemaCreator.py b/bin/AdaoYacsSchemaCreator.py index d41b05e..cb811d3 100644 --- a/bin/AdaoYacsSchemaCreator.py +++ b/bin/AdaoYacsSchemaCreator.py @@ -45,13 +45,12 @@ except: sys.exit(1) # Parse arguments -from optparse import OptionParser -usage = "usage: %prog [options] config_file yacs_schema_filename" -version="%prog 0.1" -my_parser = OptionParser(usage=usage, version=version) -(options, args) = my_parser.parse_args() -check_args(args) +from argparse import ArgumentParser +usage = "usage: %(prog)s [options] config_file yacs_schema_filename" +version="%(prog)s 0.1" +my_parser = ArgumentParser(usage=usage, version=version) +my_parser.add_argument('config_file') +my_parser.add_argument('yacs_schema_filename') +args = my_parser.parse_args() -config_file = args[0] -yacs_schema_filename = args[1] -create_schema(config_file, yacs_schema_filename) +create_schema(args.config_file, args.yacs_schema_filename) diff --git a/src/daEficas/traduitADAOV7_4_0ToV8_3_0.py b/src/daEficas/traduitADAOV7_4_0ToV8_3_0.py index 9d4afe5..c066984 100644 --- a/src/daEficas/traduitADAOV7_4_0ToV8_3_0.py +++ b/src/daEficas/traduitADAOV7_4_0ToV8_3_0.py @@ -20,7 +20,7 @@ # # Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D -import optparse +import argparse import sys import re @@ -34,10 +34,10 @@ from Traducteur.renamemocle import * version_out = "V8_3_0" -usage="""Usage: python %prog [options] +usage="""Usage: python %(prog)s [options] Typical use is: - python %prog --infile=xxxx.comm --outfile=yyyy.comm""" + python %(prog)s --infile=xxxx.comm --outfile=yyyy.comm""" atraiter = ( "ASSIMILATION_STUDY", @@ -85,9 +85,8 @@ def traduc(infile=None,outfile=None,texte=None,flog=None): # log.ferme(hdlr) if outfile is not None: - f=open(outfile,'w') - f.write( fsrc ) - f.close() + with open(outfile,'w',encoding='utf8') as f: + f.write( fsrc ) else: return fsrc @@ -98,21 +97,21 @@ class MonTraducteur: return traduc(infile=None,outfile=None,texte=self.__texte,flog=None) def main(): - parser = optparse.OptionParser(usage=usage) + parser = argparse.ArgumentParser(usage=usage) - parser.add_option('-i','--infile', dest="infile", + parser.add_argument('-i','--infile', dest="infile", help="Le fichier COMM en entree, a traduire") - parser.add_option('-o','--outfile', dest="outfile", default='out.comm', + parser.add_argument('-o','--outfile', dest="outfile", default='out.comm', help="Le fichier COMM en sortie, traduit") - options, args = parser.parse_args() - if len(options.infile) == 0: + args = parser.parse_args() + if len(args.infile) == 0: print() parser.print_help() print() sys.exit(1) - traduc(options.infile,options.outfile) + traduc(args.infile,args.outfile) if __name__ == '__main__': main() diff --git a/src/daEficas/traduitADAOV7_5_0ToV8_3_0.py b/src/daEficas/traduitADAOV7_5_0ToV8_3_0.py index 9d4afe5..c066984 100644 --- a/src/daEficas/traduitADAOV7_5_0ToV8_3_0.py +++ b/src/daEficas/traduitADAOV7_5_0ToV8_3_0.py @@ -20,7 +20,7 @@ # # Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D -import optparse +import argparse import sys import re @@ -34,10 +34,10 @@ from Traducteur.renamemocle import * version_out = "V8_3_0" -usage="""Usage: python %prog [options] +usage="""Usage: python %(prog)s [options] Typical use is: - python %prog --infile=xxxx.comm --outfile=yyyy.comm""" + python %(prog)s --infile=xxxx.comm --outfile=yyyy.comm""" atraiter = ( "ASSIMILATION_STUDY", @@ -85,9 +85,8 @@ def traduc(infile=None,outfile=None,texte=None,flog=None): # log.ferme(hdlr) if outfile is not None: - f=open(outfile,'w') - f.write( fsrc ) - f.close() + with open(outfile,'w',encoding='utf8') as f: + f.write( fsrc ) else: return fsrc @@ -98,21 +97,21 @@ class MonTraducteur: return traduc(infile=None,outfile=None,texte=self.__texte,flog=None) def main(): - parser = optparse.OptionParser(usage=usage) + parser = argparse.ArgumentParser(usage=usage) - parser.add_option('-i','--infile', dest="infile", + parser.add_argument('-i','--infile', dest="infile", help="Le fichier COMM en entree, a traduire") - parser.add_option('-o','--outfile', dest="outfile", default='out.comm', + parser.add_argument('-o','--outfile', dest="outfile", default='out.comm', help="Le fichier COMM en sortie, traduit") - options, args = parser.parse_args() - if len(options.infile) == 0: + args = parser.parse_args() + if len(args.infile) == 0: print() parser.print_help() print() sys.exit(1) - traduc(options.infile,options.outfile) + traduc(args.infile,args.outfile) if __name__ == '__main__': main() diff --git a/src/daEficas/traduitADAOV7_5_1ToV8_3_0.py b/src/daEficas/traduitADAOV7_5_1ToV8_3_0.py index 9d4afe5..c066984 100644 --- a/src/daEficas/traduitADAOV7_5_1ToV8_3_0.py +++ b/src/daEficas/traduitADAOV7_5_1ToV8_3_0.py @@ -20,7 +20,7 @@ # # Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D -import optparse +import argparse import sys import re @@ -34,10 +34,10 @@ from Traducteur.renamemocle import * version_out = "V8_3_0" -usage="""Usage: python %prog [options] +usage="""Usage: python %(prog)s [options] Typical use is: - python %prog --infile=xxxx.comm --outfile=yyyy.comm""" + python %(prog)s --infile=xxxx.comm --outfile=yyyy.comm""" atraiter = ( "ASSIMILATION_STUDY", @@ -85,9 +85,8 @@ def traduc(infile=None,outfile=None,texte=None,flog=None): # log.ferme(hdlr) if outfile is not None: - f=open(outfile,'w') - f.write( fsrc ) - f.close() + with open(outfile,'w',encoding='utf8') as f: + f.write( fsrc ) else: return fsrc @@ -98,21 +97,21 @@ class MonTraducteur: return traduc(infile=None,outfile=None,texte=self.__texte,flog=None) def main(): - parser = optparse.OptionParser(usage=usage) + parser = argparse.ArgumentParser(usage=usage) - parser.add_option('-i','--infile', dest="infile", + parser.add_argument('-i','--infile', dest="infile", help="Le fichier COMM en entree, a traduire") - parser.add_option('-o','--outfile', dest="outfile", default='out.comm', + parser.add_argument('-o','--outfile', dest="outfile", default='out.comm', help="Le fichier COMM en sortie, traduit") - options, args = parser.parse_args() - if len(options.infile) == 0: + args = parser.parse_args() + if len(args.infile) == 0: print() parser.print_help() print() sys.exit(1) - traduc(options.infile,options.outfile) + traduc(args.infile,args.outfile) if __name__ == '__main__': main() diff --git a/src/daEficas/traduitADAOV7_6_0ToV8_3_0.py b/src/daEficas/traduitADAOV7_6_0ToV8_3_0.py index 5096efb..86730b3 100644 --- a/src/daEficas/traduitADAOV7_6_0ToV8_3_0.py +++ b/src/daEficas/traduitADAOV7_6_0ToV8_3_0.py @@ -20,7 +20,7 @@ # # Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D -import optparse +import argparse import sys import re @@ -34,10 +34,10 @@ from Traducteur.renamemocle import * version_out = "V8_3_0" -usage="""Usage: python %prog [options] +usage="""Usage: python %(prog)s [options] Typical use is: - python %prog --infile=xxxx.comm --outfile=yyyy.comm""" + python %(prog)s --infile=xxxx.comm --outfile=yyyy.comm""" atraiter = ( ) @@ -65,9 +65,8 @@ def traduc(infile=None,outfile=None,texte=None,flog=None): # log.ferme(hdlr) if outfile is not None: - f=open(outfile,'w') - f.write( fsrc ) - f.close() + with open(outfile,'w',encoding='utf8') as f: + f.write( fsrc ) else: return fsrc @@ -78,21 +77,21 @@ class MonTraducteur: return traduc(infile=None,outfile=None,texte=self.__texte,flog=None) def main(): - parser = optparse.OptionParser(usage=usage) + parser = argparse.ArgumentParser(usage=usage) - parser.add_option('-i','--infile', dest="infile", + parser.add_argument('-i','--infile', dest="infile", help="Le fichier COMM en entree, a traduire") - parser.add_option('-o','--outfile', dest="outfile", default='out.comm', + parser.add_argument('-o','--outfile', dest="outfile", default='out.comm', help="Le fichier COMM en sortie, traduit") - options, args = parser.parse_args() - if len(options.infile) == 0: + args = parser.parse_args() + if len(args.infile) == 0: print() parser.print_help() print() sys.exit(1) - traduc(options.infile,options.outfile) + traduc(args.infile,args.outfile) if __name__ == '__main__': main() diff --git a/src/daEficas/traduitADAOV7_7_0ToV8_3_0.py b/src/daEficas/traduitADAOV7_7_0ToV8_3_0.py index 5096efb..86730b3 100644 --- a/src/daEficas/traduitADAOV7_7_0ToV8_3_0.py +++ b/src/daEficas/traduitADAOV7_7_0ToV8_3_0.py @@ -20,7 +20,7 @@ # # Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D -import optparse +import argparse import sys import re @@ -34,10 +34,10 @@ from Traducteur.renamemocle import * version_out = "V8_3_0" -usage="""Usage: python %prog [options] +usage="""Usage: python %(prog)s [options] Typical use is: - python %prog --infile=xxxx.comm --outfile=yyyy.comm""" + python %(prog)s --infile=xxxx.comm --outfile=yyyy.comm""" atraiter = ( ) @@ -65,9 +65,8 @@ def traduc(infile=None,outfile=None,texte=None,flog=None): # log.ferme(hdlr) if outfile is not None: - f=open(outfile,'w') - f.write( fsrc ) - f.close() + with open(outfile,'w',encoding='utf8') as f: + f.write( fsrc ) else: return fsrc @@ -78,21 +77,21 @@ class MonTraducteur: return traduc(infile=None,outfile=None,texte=self.__texte,flog=None) def main(): - parser = optparse.OptionParser(usage=usage) + parser = argparse.ArgumentParser(usage=usage) - parser.add_option('-i','--infile', dest="infile", + parser.add_argument('-i','--infile', dest="infile", help="Le fichier COMM en entree, a traduire") - parser.add_option('-o','--outfile', dest="outfile", default='out.comm', + parser.add_argument('-o','--outfile', dest="outfile", default='out.comm', help="Le fichier COMM en sortie, traduit") - options, args = parser.parse_args() - if len(options.infile) == 0: + args = parser.parse_args() + if len(args.infile) == 0: print() parser.print_help() print() sys.exit(1) - traduc(options.infile,options.outfile) + traduc(args.infile,args.outfile) if __name__ == '__main__': main() diff --git a/src/daEficas/traduitADAOV7_8_0ToV8_3_0.py b/src/daEficas/traduitADAOV7_8_0ToV8_3_0.py index 5096efb..86730b3 100644 --- a/src/daEficas/traduitADAOV7_8_0ToV8_3_0.py +++ b/src/daEficas/traduitADAOV7_8_0ToV8_3_0.py @@ -20,7 +20,7 @@ # # Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D -import optparse +import argparse import sys import re @@ -34,10 +34,10 @@ from Traducteur.renamemocle import * version_out = "V8_3_0" -usage="""Usage: python %prog [options] +usage="""Usage: python %(prog)s [options] Typical use is: - python %prog --infile=xxxx.comm --outfile=yyyy.comm""" + python %(prog)s --infile=xxxx.comm --outfile=yyyy.comm""" atraiter = ( ) @@ -65,9 +65,8 @@ def traduc(infile=None,outfile=None,texte=None,flog=None): # log.ferme(hdlr) if outfile is not None: - f=open(outfile,'w') - f.write( fsrc ) - f.close() + with open(outfile,'w',encoding='utf8') as f: + f.write( fsrc ) else: return fsrc @@ -78,21 +77,21 @@ class MonTraducteur: return traduc(infile=None,outfile=None,texte=self.__texte,flog=None) def main(): - parser = optparse.OptionParser(usage=usage) + parser = argparse.ArgumentParser(usage=usage) - parser.add_option('-i','--infile', dest="infile", + parser.add_argument('-i','--infile', dest="infile", help="Le fichier COMM en entree, a traduire") - parser.add_option('-o','--outfile', dest="outfile", default='out.comm', + parser.add_argument('-o','--outfile', dest="outfile", default='out.comm', help="Le fichier COMM en sortie, traduit") - options, args = parser.parse_args() - if len(options.infile) == 0: + args = parser.parse_args() + if len(args.infile) == 0: print() parser.print_help() print() sys.exit(1) - traduc(options.infile,options.outfile) + traduc(args.infile,args.outfile) if __name__ == '__main__': main() diff --git a/src/daEficas/traduitADAOV8_1_0ToV8_3_0.py b/src/daEficas/traduitADAOV8_1_0ToV8_3_0.py index 5096efb..86730b3 100644 --- a/src/daEficas/traduitADAOV8_1_0ToV8_3_0.py +++ b/src/daEficas/traduitADAOV8_1_0ToV8_3_0.py @@ -20,7 +20,7 @@ # # Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D -import optparse +import argparse import sys import re @@ -34,10 +34,10 @@ from Traducteur.renamemocle import * version_out = "V8_3_0" -usage="""Usage: python %prog [options] +usage="""Usage: python %(prog)s [options] Typical use is: - python %prog --infile=xxxx.comm --outfile=yyyy.comm""" + python %(prog)s --infile=xxxx.comm --outfile=yyyy.comm""" atraiter = ( ) @@ -65,9 +65,8 @@ def traduc(infile=None,outfile=None,texte=None,flog=None): # log.ferme(hdlr) if outfile is not None: - f=open(outfile,'w') - f.write( fsrc ) - f.close() + with open(outfile,'w',encoding='utf8') as f: + f.write( fsrc ) else: return fsrc @@ -78,21 +77,21 @@ class MonTraducteur: return traduc(infile=None,outfile=None,texte=self.__texte,flog=None) def main(): - parser = optparse.OptionParser(usage=usage) + parser = argparse.ArgumentParser(usage=usage) - parser.add_option('-i','--infile', dest="infile", + parser.add_argument('-i','--infile', dest="infile", help="Le fichier COMM en entree, a traduire") - parser.add_option('-o','--outfile', dest="outfile", default='out.comm', + parser.add_argument('-o','--outfile', dest="outfile", default='out.comm', help="Le fichier COMM en sortie, traduit") - options, args = parser.parse_args() - if len(options.infile) == 0: + args = parser.parse_args() + if len(args.infile) == 0: print() parser.print_help() print() sys.exit(1) - traduc(options.infile,options.outfile) + traduc(args.infile,args.outfile) if __name__ == '__main__': main() diff --git a/src/daEficas/traduitADAOV8_2_0ToV8_3_0.py b/src/daEficas/traduitADAOV8_2_0ToV8_3_0.py index 5096efb..b60968d 100644 --- a/src/daEficas/traduitADAOV8_2_0ToV8_3_0.py +++ b/src/daEficas/traduitADAOV8_2_0ToV8_3_0.py @@ -20,7 +20,7 @@ # # Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D -import optparse +import argparse import sys import re @@ -34,10 +34,10 @@ from Traducteur.renamemocle import * version_out = "V8_3_0" -usage="""Usage: python %prog [options] +usage="""Usage: python %(prog)s [args] Typical use is: - python %prog --infile=xxxx.comm --outfile=yyyy.comm""" + python %(prog)s --infile=xxxx.comm --outfile=yyyy.comm""" atraiter = ( ) @@ -65,9 +65,8 @@ def traduc(infile=None,outfile=None,texte=None,flog=None): # log.ferme(hdlr) if outfile is not None: - f=open(outfile,'w') - f.write( fsrc ) - f.close() + with open(outfile,'w',encoding='utf8') as f: + f.write( fsrc ) else: return fsrc @@ -78,21 +77,21 @@ class MonTraducteur: return traduc(infile=None,outfile=None,texte=self.__texte,flog=None) def main(): - parser = optparse.OptionParser(usage=usage) + parser = argparse.ArgumentParser(usage=usage) - parser.add_option('-i','--infile', dest="infile", + parser.add_argument('-i','--infile', dest="infile", help="Le fichier COMM en entree, a traduire") - parser.add_option('-o','--outfile', dest="outfile", default='out.comm', + parser.add_argument('-o','--outfile', dest="outfile", default='out.comm', help="Le fichier COMM en sortie, traduit") - options, args = parser.parse_args() - if len(options.infile) == 0: + args = parser.parse_args() + if len(args.infile) == 0: print() parser.print_help() print() sys.exit(1) - traduc(options.infile,options.outfile) + traduc(args.infile,args.outfile) if __name__ == '__main__': main() diff --git a/src/daEficas/traduitADAOsansToV8_3_0.py b/src/daEficas/traduitADAOsansToV8_3_0.py index 9d4afe5..38be259 100644 --- a/src/daEficas/traduitADAOsansToV8_3_0.py +++ b/src/daEficas/traduitADAOsansToV8_3_0.py @@ -20,7 +20,7 @@ # # Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D -import optparse +import argparse import sys import re @@ -34,10 +34,10 @@ from Traducteur.renamemocle import * version_out = "V8_3_0" -usage="""Usage: python %prog [options] +usage="""Usage: python %(prog)s [args] Typical use is: - python %prog --infile=xxxx.comm --outfile=yyyy.comm""" + python %(prog)s --infile=xxxx.comm --outfile=yyyy.comm""" atraiter = ( "ASSIMILATION_STUDY", @@ -85,9 +85,8 @@ def traduc(infile=None,outfile=None,texte=None,flog=None): # log.ferme(hdlr) if outfile is not None: - f=open(outfile,'w') - f.write( fsrc ) - f.close() + with open(outfile,'w',encoding='utf8') as f: + f.write( fsrc ) else: return fsrc @@ -98,21 +97,21 @@ class MonTraducteur: return traduc(infile=None,outfile=None,texte=self.__texte,flog=None) def main(): - parser = optparse.OptionParser(usage=usage) + parser = argparse.ArgumentParser(usage=usage) - parser.add_option('-i','--infile', dest="infile", + parser.add_argument('-i','--infile', dest="infile", help="Le fichier COMM en entree, a traduire") - parser.add_option('-o','--outfile', dest="outfile", default='out.comm', + parser.add_argument('-o','--outfile', dest="outfile", default='out.comm', help="Le fichier COMM en sortie, traduit") - options, args = parser.parse_args() - if len(options.infile) == 0: + args = parser.parse_args() + if len(args.infile) == 0: print() parser.print_help() print() sys.exit(1) - traduc(options.infile,options.outfile) + traduc(args.infile,args.outfile) if __name__ == '__main__': main() diff --git a/src/daSalome/daYacsSchemaCreator/run.py b/src/daSalome/daYacsSchemaCreator/run.py index 6eda6e9..1413e9f 100644 --- a/src/daSalome/daYacsSchemaCreator/run.py +++ b/src/daSalome/daYacsSchemaCreator/run.py @@ -25,7 +25,6 @@ import sys import os import traceback import logging -from optparse import OptionParser from daYacsSchemaCreator.methods import * from daYacsSchemaCreator.help_methods import * -- 2.39.2