From: Renaud Barate Date: Thu, 10 Nov 2011 15:54:41 +0000 (+0000) Subject: Fix opening of OT study with inconsistent or inexistent definition of variables ... X-Git-Tag: LOGILAB~278 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=360b38b56a7d7b687fb4ed4cf980146871d44422;p=tools%2Feficas.git Fix opening of OT study with inconsistent or inexistent definition of variables (fix bug METIERS #40) --- diff --git a/convert/convert_openturns_study.py b/convert/convert_openturns_study.py index ba62b9f9..d1727ad3 100644 --- a/convert/convert_openturns_study.py +++ b/convert/convert_openturns_study.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # CONFIGURATION MANAGEMENT OF EDF VERSION # ====================================================================== # COPYRIGHT (C) 1991 - 2002 EDF R&D WWW.CODE-ASTER.ORG @@ -18,22 +17,33 @@ # # # ====================================================================== -""" -""" -import parseur_python -from convert_python import * +import re +from convert_python import PythonParser def entryPoint(): """ - Retourne les informations nécessaires pour le chargeur de plugins - Ces informations sont retournées dans un dictionnaire + Return a dictionary containing the description needed to load the plugin """ return { - # Le nom du plugin 'name' : 'openturns_study', - # La factory pour créer une instance du plugin - 'factory' : PythonParser, + 'factory' : OTStudyParser } +class OTStudyParser(PythonParser): + """ + This converter works like PythonParser, except that it also initializes all + model variables to None in order to avoid Python syntax errors when loading + a file with a different or inexistent definition of variables. + """ + # We look for pattern "ModelVariable=NOMVAR," + pattern_model_variable = re.compile(r'ModelVariable\s*=\s*(\w+)\s*,') + def convert(self, outformat, appli=None): + text = PythonParser.convert(self, outformat, appli) + varnames = self.pattern_model_variable.findall(text) + newtext = "" + for var in varnames: + newtext += "%s = None\n" % var + newtext += text + return newtext