From: Jean-Philippe ARGAUD Date: Thu, 25 Jan 2018 20:30:26 +0000 (+0100) Subject: Improving file conversion and internal test X-Git-Tag: V8_5_0rc1~23 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=a0cd62f22f5097e73529ca38767528141bb851be;p=modules%2Fadao.git Improving file conversion and internal test --- diff --git a/bin/AdaoYacsSchemaCreator.py b/bin/AdaoYacsSchemaCreator.py index eb5af25..587896b 100644 --- a/bin/AdaoYacsSchemaCreator.py +++ b/bin/AdaoYacsSchemaCreator.py @@ -52,4 +52,4 @@ my_parser.add_argument('config_file') my_parser.add_argument('yacs_schema_filename') args = my_parser.parse_args() -create_schema(args.config_file, args.yacs_schema_filename) +create_schema_from_file(args.config_file, args.yacs_schema_filename) diff --git a/src/daComposant/daCore/Aidsm.py b/src/daComposant/daCore/Aidsm.py index 54e9ca3..5e59061 100644 --- a/src/daComposant/daCore/Aidsm.py +++ b/src/daComposant/daCore/Aidsm.py @@ -706,8 +706,7 @@ class Aidsm(object): def __executeYACSScheme(self, FileName=None): "Lancement du calcul" self.__case.register("executeYACSScheme", dir(), locals()) - if FileName is not None: - self.dump( FileName, "DIC") + self.dump( FileName, "YACS") self.__adaoObject["AlgorithmParameters"].executeYACSScheme( FileName ) return 0 diff --git a/src/daComposant/daCore/AssimilationStudy.py b/src/daComposant/daCore/AssimilationStudy.py index e4dc2e1..c4fab69 100644 --- a/src/daComposant/daCore/AssimilationStudy.py +++ b/src/daComposant/daCore/AssimilationStudy.py @@ -21,7 +21,7 @@ # Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D """ - Normalized interface for ADAO + Normalized interface for ADAO scripting (full version API) """ __author__ = "Jean-Philippe ARGAUD" __all__ = ["AssimilationStudy"] diff --git a/src/daComposant/daCore/BasicObjects.py b/src/daComposant/daCore/BasicObjects.py index 27ce16f..573b39b 100644 --- a/src/daComposant/daCore/BasicObjects.py +++ b/src/daComposant/daCore/BasicObjects.py @@ -951,26 +951,10 @@ class AlgorithmAndParameters(object): def executeYACSScheme(self, FileName=None): "Permet de lancer le calcul d'assimilation" if FileName is None or not os.path.exists(FileName): - raise ValueError("an existing DIC Python file name has to be given for YACS execution.\n") + raise ValueError("a YACS file name has to be given for YACS execution.\n") if not PlatformInfo.has_salome or not PlatformInfo.has_yacs or not PlatformInfo.has_adao: raise ImportError("Unable to get SALOME, YACS or ADAO environnement variables. Please launch SALOME before executing.\n") # - __converterExe = os.path.join(os.environ["ADAO_ROOT_DIR"], "bin/salome", "AdaoYacsSchemaCreator.py") - __inputFile = os.path.abspath(FileName) - __outputFile = __inputFile[:__inputFile.rfind(".")] + '.xml' - # - __args = ["python", __converterExe, __inputFile, __outputFile] - import subprocess - __p = subprocess.Popen(__args) - (__stdoutdata, __stderrdata) = __p.communicate() - if not os.path.exists(__outputFile): - __msg = "An error occured during the execution of the ADAO YACS Schema\n" - __msg += "Creator applied on the input file:\n" - __msg += " %s\n"%__inputFile - __msg += "If SALOME GUI is launched by command line, see errors\n" - __msg += "details in your terminal.\n" - raise ValueError(__msg) - # try: import pilot import SALOMERuntime @@ -981,13 +965,13 @@ class AlgorithmAndParameters(object): xmlLoader = loader.YACSLoader() xmlLoader.registerProcCataLoader() try: - catalogAd = r.loadCatalog("proc", __outputFile) + catalogAd = r.loadCatalog("proc", os.path.abspath(FileName)) except: pass r.addCatalog(catalogAd) try: - p = xmlLoader.load(__outputFile) + p = xmlLoader.load(os.path.abspath(FileName)) except IOError as ex: print("IO exception: %s"%(ex,)) @@ -1735,7 +1719,11 @@ class CaseLogger(object): self.__objname = str(__objname) self.__logSerie = [] self.__switchoff = False - self.__viewers = self.__loaders = {"TUI":_TUIViewer, "DIC":_DICViewer} + self.__viewers = self.__loaders = { + "TUI":_TUIViewer, + "DIC":_DICViewer, + "YACS":_YACSViewer, + } if __addViewers is not None: self.__viewers.update(dict(__addViewers)) if __addLoaders is not None: @@ -1803,9 +1791,9 @@ class GenericCaseViewer(object): __text +="\n" if __filename is not None: __file = os.path.abspath(__filename) - fid = open(__file,"w") - fid.write(__text) - fid.close() + __fid = open(__file,"w") + __fid.write(__text) + __fid.close() return __text def load(self, __filename=None): "Chargement normalisé des commandes" @@ -2058,6 +2046,53 @@ class _XMLViewer(GenericCaseViewer): GenericCaseViewer.__init__(self, __name, __objname, __content) raise NotImplementedError() +class _YACSViewer(GenericCaseViewer): + """ + Etablissement des commandes de creation d'un cas YACS + """ + def __init__(self, __name="", __objname="case", __content=None): + "Initialisation et enregistrement de l'entete" + GenericCaseViewer.__init__(self, __name, __objname, __content) + self.__internalDIC = _DICViewer(__name, __objname, __content) + self._append = self.__internalDIC._append + def dump(self, __filename=None): + "Restitution normalisée des commandes" + self.__internalDIC._finalize() + # ----- + if __filename is not None: + __file = os.path.abspath(__filename) + __DICfile = __file[:__file.rfind(".")] + '_DIC.py' + __DICdump = self.__internalDIC.dump(__DICfile) + else: + raise ValueError("A file name has to be given for YACS XML output.") + # ----- + if not PlatformInfo.has_salome or \ + not PlatformInfo.has_adao: + raise ImportError("\n\n"+\ + "Unable to get SALOME or ADAO environnement variables.\n"+\ + "Please load the right environnement before trying to use it.\n") + else: + if os.path.isfile(__file) or os.path.islink(__file): + os.remove(__file) + __converterExe = os.path.join(os.environ["ADAO_ROOT_DIR"], "bin/salome", "AdaoYacsSchemaCreator.py") + __args = ["python", __converterExe, __DICfile, __file] + import subprocess + __p = subprocess.Popen(__args) + (__stdoutdata, __stderrdata) = __p.communicate() + if not os.path.exists(__file): + __msg = "An error occured during the ADAO YACS Schema build.\n" + __msg += "Creator applied on the input file:\n" + __msg += " %s\n"%__DICfile + __msg += "If SALOME GUI is launched by command line, see errors\n" + __msg += "details in your terminal.\n" + raise ValueError(__msg) + os.remove(__DICfile) + # ----- + __fid = open(__file,"r") + __text = __fid.read() + __fid.close() + return __text + # ============================================================================== class ImportFromScript(object): """ diff --git a/src/daSalome/daYacsSchemaCreator/run.py b/src/daSalome/daYacsSchemaCreator/run.py index b937bae..7a5740b 100644 --- a/src/daSalome/daYacsSchemaCreator/run.py +++ b/src/daSalome/daYacsSchemaCreator/run.py @@ -29,21 +29,38 @@ import logging from daYacsSchemaCreator.methods import * from daYacsSchemaCreator.help_methods import * -def create_schema(config_file, yacs_schema_filename): +def create_schema(config_file, config_content, yacs_schema_filename): - # Import config_file - try: - exec(compile(open(config_file).read(), config_file, 'exec')) - except Exception as e: - if isinstance(e, SyntaxError): msg = "at %s: %s"%(e.offset, e.text) - else: msg = "" - raise ValueError("\n\nexception in loading %s\n\nThe following error occurs:\n\n%s %s\n\nSee also the potential messages, which can show the origin of the above error, in the launching terminal.\n"%(config_file,str(e),msg)) + if config_file is not None and config_content is None: + # Import config_file + try: + exec(compile(open(config_file).read(), config_file, 'exec')) + except Exception as e: + if isinstance(e, SyntaxError): msg = "at %s: %s"%(e.offset, e.text) + else: msg = "" + raise ValueError("\n\nexception in loading %s\n\nThe following error occurs:\n\n%s %s\n\nSee also the potential messages, which can show the origin of the above error, in the launching terminal.\n"%(config_file,str(e),msg)) + elif config_file is None and config_content is not None: + # Import config_content + try: + exec(compile(config_content, None, 'exec')) + except Exception as e: + if isinstance(e, SyntaxError): msg = "at %s: %s"%(e.offset, e.text) + else: msg = "" + raise ValueError("\n\nexception in loading the DIC config content\n\nThe following error occurs:\n\n%s %s\n\nSee also the potential messages, which can show the origin of the above error, in the launching terminal.\n"%(str(e),msg)) + else: + raise ValueError("Error in schema creation, file or content has to be given") - if "study_config" not in locals(): - raise ValueError("\n\n Cannot found study_config in %s\n"%str(config_file)) - else: - globals()['study_config'] = locals()['study_config'] + if "study_config" not in locals(): + raise ValueError("\n\n Cannot find study_config in %s\n"%str(config_file)) + else: + globals()['study_config'] = locals()['study_config'] - check_study(study_config) - proc = create_yacs_proc(study_config) - write_yacs_proc(proc, yacs_schema_filename) + check_study(study_config) + proc = create_yacs_proc(study_config) + write_yacs_proc(proc, yacs_schema_filename) + +def create_schema_from_file(config_file, yacs_schema_filename): + create_schema(config_file, None, yacs_schema_filename) + +def create_schema_from_content(config_content, yacs_schema_filename): + create_schema(None, config_content, yacs_schema_filename)