X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2FdaEficas%2Fgenerator_adao.py;h=79c786f4318c66008154190148a2cad5de7d5aab;hb=9e1ba0c91a43032476ab9cc1321f907a8b836bd0;hp=0bd1bfff841ed4f467139f5807401715d49de02d;hpb=49d63f393a1502a2f549c5b5e3592b1d1a6b5079;p=modules%2Fadao.git diff --git a/src/daEficas/generator_adao.py b/src/daEficas/generator_adao.py index 0bd1bff..79c786f 100644 --- a/src/daEficas/generator_adao.py +++ b/src/daEficas/generator_adao.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # -# Copyright (C) 2008-2017 EDF R&D +# Copyright (C) 2008-2018 EDF R&D # # This file is part of SALOME ADAO module # @@ -58,7 +58,7 @@ class AdaoGenerator(PythonGenerator): def gener(self,obj,format='brut',config=None,appli=None): self.logger.debug("method gener called") self.text_comm = PythonGenerator.gener(self, obj, format, config) - for key, value in self.dictMCVal.iteritems(): + for key, value in self.dictMCVal.items(): self.logger.debug("dictMCVAl %s %s" % (key,value)) try : @@ -69,14 +69,15 @@ class AdaoGenerator(PythonGenerator): self.logger.debug("EFICAS case is not valid, python command file for YACS schema generation cannot be created") self.logger.debug(self.text_da) self.dictMCVal = {} - # traceback.print_exc() + # traceback.print_exc() return self.text_comm def writeDefault(self, fn): 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() @@ -85,7 +86,7 @@ class AdaoGenerator(PythonGenerator): Convertit un objet MCSIMP en texte python """ clef="" - for i in obj.get_genealogie() : + for i in obj.getGenealogie() : clef=clef+"__"+i self.dictMCVal[clef]=obj.valeur @@ -93,14 +94,14 @@ class AdaoGenerator(PythonGenerator): return s def generate_da(self): - + if "__CHECKING_STUDY__StudyName" in self.dictMCVal.keys(): self.type_of_study = "CHECKING_STUDY" else: self.type_of_study = "ASSIMILATION_STUDY" - - self.text_da += "#-*-coding:iso-8859-1-*- \n" - self.text_da += "study_config = {} \n" + + self.text_da += "#-*- coding: utf-8 -*-\n" + self.text_da += "study_config = {}\n" # Extraction de Study_type self.text_da += "study_config['StudyType'] = '" + self.type_of_study + "'\n" @@ -154,7 +155,7 @@ class AdaoGenerator(PythonGenerator): def add_data(self, data_name): - # Extraction des données + # Extraction des donnees search_text = "__"+self.type_of_study+"__" + data_name + "__" data_type = self.dictMCVal[search_text + "INPUT_TYPE"] search_type = search_text + data_type + "__data__" @@ -252,7 +253,7 @@ class AdaoGenerator(PythonGenerator): self.text_da += "Init_config['From'] = 'Script'\n" self.text_da += "Init_config['Data'] = '" + init_file_data + "'\n" self.text_da += "Init_config['Target'] = [" - if type(init_target_list) is type("str"): + if isinstance(init_target_list, "str"): self.text_da += "'" + init_target_list + "'," else: for target in init_target_list: @@ -288,26 +289,31 @@ class AdaoGenerator(PythonGenerator): def add_AlgorithmParameters(self): - if not self.dictMCVal.has_key("__"+self.type_of_study+"__AlgorithmParameters__Parameters"): return - data_name = "AlgorithmParameters" data_type = "Dict" - para_type = self.dictMCVal["__"+self.type_of_study+"__AlgorithmParameters__Parameters"] + # + if "__"+self.type_of_study+"__AlgorithmParameters__Parameters" in self.dictMCVal: + para_type = self.dictMCVal["__"+self.type_of_study+"__AlgorithmParameters__Parameters"] + else: + para_type = "Defaults" + # if para_type == "Defaults": from_type = para_type elif para_type == "Dict": from_type = self.dictMCVal["__"+self.type_of_study+"__AlgorithmParameters__Dict__data__FROM"] + else: + return if from_type == "Script": data = self.dictMCVal["__"+self.type_of_study+"__AlgorithmParameters__Dict__data__SCRIPT_DATA__SCRIPT_FILE"] - self.text_da += data_name + "_config = {} \n" + self.text_da += data_name + "_config = {}\n" self.text_da += data_name + "_config['Type'] = '" + data_type + "'\n" self.text_da += data_name + "_config['From'] = '" + from_type + "'\n" self.text_da += data_name + "_config['Data'] = '" + data + "'\n" self.text_da += "study_config['" + data_name + "'] = " + data_name + "_config\n" elif from_type == "String": data = self.dictMCVal["__"+self.type_of_study+"__AlgorithmParameters__Dict__data__STRING_DATA__STRING"] - self.text_da += data_name + "_config = {} \n" + self.text_da += data_name + "_config = {}\n" self.text_da += data_name + "_config['Type'] = '" + data_type + "'\n" self.text_da += data_name + "_config['From'] = '" + from_type + "'\n" self.text_da += data_name + "_config['Data'] = '" + data + "'\n" @@ -315,7 +321,7 @@ class AdaoGenerator(PythonGenerator): elif from_type == "Defaults": base = "__"+self.type_of_study+"__AlgorithmParameters__Parameters" keys = [k for k in self.dictMCVal.keys() if base in k] - keys.remove(base) + if base in keys: keys.remove(base) keys = [k.replace(base,'') for k in keys] data = '{' for k in keys: @@ -330,11 +336,12 @@ class AdaoGenerator(PythonGenerator): data += '"%s":%s,'%(key,val) data = data.replace("'",'"') data += '}' - self.text_da += data_name + "_config = {} \n" - self.text_da += data_name + "_config['Type'] = '" + data_type + "'\n" - self.text_da += data_name + "_config['From'] = 'String'\n" - self.text_da += data_name + "_config['Data'] = '" + data + "'\n" - self.text_da += "study_config['" + data_name + "'] = " + data_name + "_config\n" + if data != '{}': + self.text_da += data_name + "_config = {}\n" + self.text_da += data_name + "_config['Type'] = '" + data_type + "'\n" + self.text_da += data_name + "_config['From'] = 'String'\n" + self.text_da += data_name + "_config['Data'] = '" + data + "'\n" + self.text_da += "study_config['" + data_name + "'] = " + data_name + "_config\n" def add_variables(self):