From: Jean-Philippe ARGAUD Date: Sat, 29 Sep 2018 19:05:21 +0000 (+0200) Subject: Correction of Python 3 compatibility X-Git-Tag: V9_2_0b_ok_ADAO~7 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=f8a5bbadc9cfc0150e35b71e4e5157cb3058c4b8;p=modules%2Fadao.git Correction of Python 3 compatibility --- diff --git a/bin/AdaoCatalogGenerator.py b/bin/AdaoCatalogGenerator.py index 488d35a..0c62be0 100644 --- a/bin/AdaoCatalogGenerator.py +++ b/bin/AdaoCatalogGenerator.py @@ -35,6 +35,20 @@ logging.basicConfig(level=logging.WARNING) if sys.version_info.major > 2: def unicode(text, encoding='utf-8'): return text +print("-- Starting AdaoCalatogGenerator.py --") + +try: + import adao + import daEficas + import daYacsSchemaCreator + import daCore.AssimilationStudy + import daYacsSchemaCreator.infos_daComposant as infos +except: + logging.fatal("Import of ADAO python modules failed !" + + "\n add ADAO python installation directory in your PYTHONPATH") + traceback.print_exc() + sys.exit(1) + #----------- Templates Part ---------------# begin_catalog_file = """# -*- coding: utf-8 -*- # @@ -141,13 +155,13 @@ def F_{data_name}(statut, fv=NoCheckInNS) : return FACT( TEMPLATE_DATA = BLOC (condition = " FROM in ( 'Template', ) ", Template = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "AnalysisPrinter", into=("AnalysisPrinter", "AnalysisSaver", "AnalysisPrinterAndSaver")), AnalysisPrinter = BLOC (condition = " Template == 'AnalysisPrinter' ", - ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "import numpy\\nxa=numpy.ravel(ADD.get('Analysis')[-1])\\nprint 'Analysis:',xa" ), + ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "import numpy\\nxa=numpy.ravel(ADD.get('Analysis')[-1])\\nprint('Analysis:',xa)" ), ), AnalysisSaver = BLOC (condition = " Template == 'AnalysisSaver' ", - ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "import numpy\\nxa=numpy.ravel(ADD.get('Analysis')[-1])\\nf='/tmp/analysis.txt'\\nprint 'Analysis saved in \\"%s\\"'%f\\nnumpy.savetxt(f,xa)" ), + ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "import numpy\\nxa=numpy.ravel(ADD.get('Analysis')[-1])\\nf='/tmp/analysis.txt'\\nprint('Analysis saved in \\"%s\\"'%f)\\nnumpy.savetxt(f,xa)" ), ), AnalysisPrinterAndSaver = BLOC (condition = " Template == 'AnalysisPrinterAndSaver' ", - ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "import numpy\\nxa=numpy.ravel(ADD.get('Analysis')[-1])\\nprint 'Analysis:',xa\\nf='/tmp/analysis.txt'\\nprint 'Analysis saved in \\"%s\\"'%f\\nnumpy.savetxt(f,xa)" ), + ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "import numpy\\nxa=numpy.ravel(ADD.get('Analysis')[-1])\\nprint 'Analysis:',xa\\nf='/tmp/analysis.txt'\\nprint('Analysis saved in \\"%s\\"'%f)\\nnumpy.savetxt(f,xa)" ), ), ), ) @@ -311,18 +325,6 @@ CHECKING_STUDY = PROC(nom="CHECKING_STUDY", #----------- Begin generation script -----------# -print("-- Starting AdaoCalatogGenerator.py --") - -try: - import daEficas - import daYacsSchemaCreator - import daCore.AssimilationStudy - import daYacsSchemaCreator.infos_daComposant as infos -except: - logging.fatal("Import of ADAO python modules failed !" + - "\n add ADAO python installation directory in your PYTHONPATH") - traceback.print_exc() - sys.exit(1) # Parse arguments from argparse import ArgumentParser diff --git a/resources/ADAOSchemaCatalog.xml b/resources/ADAOSchemaCatalog.xml index f531643..b1a32ab 100644 --- a/resources/ADAOSchemaCatalog.xml +++ b/resources/ADAOSchemaCatalog.xml @@ -547,13 +547,16 @@ logging.debug(" switching to value : "+str(switch_value)) diff --git a/src/daEficas/generator_adao.py b/src/daEficas/generator_adao.py index 47f4a1f..79c786f 100644 --- a/src/daEficas/generator_adao.py +++ b/src/daEficas/generator_adao.py @@ -76,7 +76,8 @@ class AdaoGenerator(PythonGenerator): if self.text_da_status: self.logger.debug("write adao python command file") filename = fn[:fn.rfind(".")] + '.py' - f = open( str(filename), 'wb') + #~ f = open( str(filename), 'wb') + f = open( str(filename), 'w') f.write( self.text_da ) f.close() diff --git a/src/daSalome/daYacsIntegration/daOptimizerLoop.py b/src/daSalome/daYacsIntegration/daOptimizerLoop.py index ac80320..ea8ad0b 100644 --- a/src/daSalome/daYacsIntegration/daOptimizerLoop.py +++ b/src/daSalome/daYacsIntegration/daOptimizerLoop.py @@ -24,7 +24,10 @@ import SALOMERuntime import pilot -import cPickle +try: + import cPickle as pickle +except: + import pickle import numpy import threading @@ -289,7 +292,7 @@ class AssimilationAlgorithm_asynch(SALOMERuntime.OptimizerAlgASync): #print "[Debug] Input is ", input str_da_study = input.getStringValue() try: - self.da_study = cPickle.loads(str_da_study) + self.da_study = pickle.loads(str_da_study) except ValueError as e: raise ValueError("\n\n Handling internal error in study exchange (message: \"%s\").\n The case is probably too big (bigger than the physical plus the virtual memory available).\n Try if possible to store the covariance matrices in sparse format.\n"%(str(e),)) #print "[Debug] da_study is ", self.da_study @@ -394,7 +397,7 @@ class AssimilationAlgorithm_asynch(SALOMERuntime.OptimizerAlgASync): # Remove Data Observer, so you can ... var.removeDataObserver(self.obs) # Pickle then ... - var_str = cPickle.dumps(var) + var_str = pickle.dumps(var) # Add Again Data Observer if self.da_study.observers_dict[info]["scheduler"] != "": self.ADD.setObserver(Variable = info, ObjectFunction = self.obs, Scheduler = self.da_study.observers_dict[info]["scheduler"], Info = info) @@ -443,7 +446,7 @@ class AssimilationAlgorithm_asynch(SALOMERuntime.OptimizerAlgASync): # for observer_name in list(self.da_study.observers_dict.keys()): # self.ADD.removeDataObserver(observer_name, self.obs) self.da_study.YI_prepare_to_pickle() - result = cPickle.dumps(self.da_study) + result = pickle.dumps(self.da_study) return result # Obligatoire ???