From: Jean-Philippe ARGAUD Date: Mon, 7 Oct 2013 11:51:03 +0000 (+0200) Subject: Improving UserDataInit behaviour X-Git-Tag: V7_3_0~7 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ead3027c71435be8dda3477a70d211c040ef4eee;p=modules%2Fadao.git Improving UserDataInit behaviour --- diff --git a/resources/ADAOSchemaCatalog.xml b/resources/ADAOSchemaCatalog.xml index 4e9430a..8793f0b 100644 --- a/resources/ADAOSchemaCatalog.xml +++ b/resources/ADAOSchemaCatalog.xml @@ -341,11 +341,6 @@ module_name = os.path.splitext(filename)[0] if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index(filepath)>0): sys.path.insert(0,filepath) -# Import script -__import__(module_name) -user_script_module = sys.modules[module_name] - -# Get Data from script ]]> @@ -370,11 +365,6 @@ module_name = os.path.splitext(filename)[0] if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index(filepath)>0): sys.path.insert(0,filepath) -# Import script -__import__(module_name) -user_script_module = sys.modules[module_name] - -# Get Data from script ]]> @@ -399,11 +389,6 @@ module_name = os.path.splitext(filename)[0] if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index(filepath)>0): sys.path.insert(0,filepath) -# Import script -__import__(module_name) -user_script_module = sys.modules[module_name] - -# Get Data from script ]]> @@ -442,11 +427,6 @@ module_name = os.path.splitext(filename)[0] if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index(filepath)>0): sys.path.insert(0,filepath) -# Import script -__import__(module_name) -user_script_module = sys.modules[module_name] - -# Get Data from script ]]> @@ -486,11 +466,6 @@ module_name = os.path.splitext(filename)[0] if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index(filepath)>0): sys.path.insert(0,filepath) -# Import script -__import__(module_name) -user_script_module = sys.modules[module_name] - -# Get Data from script ]]> @@ -558,11 +533,6 @@ module_name = os.path.splitext(filename)[0] if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index(filepath)>0): sys.path.insert(0,filepath) -# Import script -__import__(module_name) -user_script_module = sys.modules[module_name] - -# Get Data from script ]]> @@ -584,11 +554,6 @@ module_name = os.path.splitext(filename)[0] if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index(filepath)>0): sys.path.insert(0,filepath) -# Import script -__import__(module_name) -user_script_module = sys.modules[module_name] - -# Get Data from script ]]> diff --git a/src/daSalome/daYacsSchemaCreator/methods.py b/src/daSalome/daYacsSchemaCreator/methods.py index 71ab9e4..2328dbb 100644 --- a/src/daSalome/daYacsSchemaCreator/methods.py +++ b/src/daSalome/daYacsSchemaCreator/methods.py @@ -128,6 +128,7 @@ def create_yacs_proc(study_config): else: init_node.getInputPort("script").edInitPy(init_config["Data"]) init_node_script = init_node.getScript() + init_node_script += "# Import script and get data\n__import__(module_name)\nuser_script_module = sys.modules[module_name]\n\n" init_node_script += "init_data = user_script_module.init_data\n" init_node.setScript(init_node_script) ADAO_Case.edAddChild(init_node) @@ -154,20 +155,20 @@ def create_yacs_proc(study_config): else: back_node.getInputPort("script").edInitPy(data_config["Data"]) back_node.edAddOutputPort(key, t_pyobj) + ADAO_Case.edAddChild(back_node) + # Set content of the node back_node_script = back_node.getScript() + if key in init_config["Target"]: + # Connect node with InitUserData + back_node_script += "__builtins__[\"init_data\"] = init_data\n" + back_node.edAddInputPort("init_data", t_pyobj) + ADAO_Case.edAddDFLink(init_node.getOutputPort("init_data"), back_node.getInputPort("init_data")) + back_node_script += "# Import script and get data\n__import__(module_name)\nuser_script_module = sys.modules[module_name]\n\n" back_node_script += key + " = user_script_module." + key + "\n" back_node.setScript(back_node_script) - ADAO_Case.edAddChild(back_node) # Connect node with CreateAssimilationStudy CAS_node.edAddInputPort(key, t_pyobj) ADAO_Case.edAddDFLink(back_node.getOutputPort(key), CAS_node.getInputPort(key)) - # Connect node with InitUserData - if key in init_config["Target"]: - back_node_script = back_node.getScript() - back_node_script = "__builtins__[\"init_data\"] = init_data\n" + back_node_script - back_node.setScript(back_node_script) - back_node.edAddInputPort("init_data", t_pyobj) - ADAO_Case.edAddDFLink(init_node.getOutputPort("init_data"), back_node.getInputPort("init_data")) if data_config["Type"] == "Dict" and data_config["From"] == "String": # Create node @@ -175,21 +176,20 @@ def create_yacs_proc(study_config): back_node = factory_back_node.cloneNode("Get" + key) back_node.getInputPort("dict_in_string").edInitPy(data_config["Data"]) back_node.edAddOutputPort(key, t_pyobj) + ADAO_Case.edAddChild(back_node) + # Set content of the node back_node_script = back_node.getScript() + if key in init_config["Target"]: + # Connect node with InitUserData + back_node_script += "__builtins__[\"init_data\"] = init_data\n" + back_node.edAddInputPort("init_data", t_pyobj) + ADAO_Case.edAddDFLink(init_node.getOutputPort("init_data"), back_node.getInputPort("init_data")) back_node_script += key + " = dict(dico)\n" back_node_script += "logging.debug(\"Dict is %ss\"%s%s)"%("%","%",key) back_node.setScript(back_node_script) - ADAO_Case.edAddChild(back_node) # Connect node with CreateAssimilationStudy CAS_node.edAddInputPort(key, t_pyobj) ADAO_Case.edAddDFLink(back_node.getOutputPort(key), CAS_node.getInputPort(key)) - # Connect node with InitUserData - if key in init_config["Target"]: - back_node_script = back_node.getScript() - back_node_script = "__builtins__[\"init_data\"] = init_data\n" + back_node_script - back_node.setScript(back_node_script) - back_node.edAddInputPort("init_data", t_pyobj) - ADAO_Case.edAddDFLink(init_node.getOutputPort("init_data"), back_node.getInputPort("init_data")) if data_config["Type"] == "Vector" and data_config["From"] == "String": # Create node @@ -197,6 +197,15 @@ def create_yacs_proc(study_config): back_node = factory_back_node.cloneNode("Get" + key) back_node.getInputPort("vector_in_string").edInitPy(data_config["Data"]) ADAO_Case.edAddChild(back_node) + # Set content of the node + back_node_script = back_node.getScript() + back_node_script += "stored = " + str(data_config["Stored"]) + "\n" + if key in init_config["Target"]: + # Connect node with InitUserData + back_node_script += "__builtins__[\"init_data\"] = init_data\n" + back_node.edAddInputPort("init_data", t_pyobj) + ADAO_Case.edAddDFLink(init_node.getOutputPort("init_data"), back_node.getInputPort("init_data")) + back_node.setScript(back_node_script) # Connect node with CreateAssimilationStudy CAS_node.edAddInputPort(key, t_pyobj) CAS_node.edAddInputPort(key_type, t_string) @@ -204,14 +213,6 @@ def create_yacs_proc(study_config): ADAO_Case.edAddDFLink(back_node.getOutputPort("vector"), CAS_node.getInputPort(key)) ADAO_Case.edAddDFLink(back_node.getOutputPort("type"), CAS_node.getInputPort(key_type)) ADAO_Case.edAddDFLink(back_node.getOutputPort("stored"), CAS_node.getInputPort(key_stored)) - back_node_script = back_node.getScript() - back_node_script += "stored = " + str(data_config["Stored"]) + "\n" - # Connect node with InitUserData - if key in init_config["Target"]: - back_node_script += "__builtins__[\"init_data\"] = init_data\n" + back_node_script - back_node.edAddInputPort("init_data", t_pyobj) - ADAO_Case.edAddDFLink(init_node.getOutputPort("init_data"), back_node.getInputPort("init_data")) - back_node.setScript(back_node_script) if data_config["Type"] == "Vector" and data_config["From"] == "Script": # Create node @@ -226,10 +227,18 @@ def create_yacs_proc(study_config): else: back_node.getInputPort("script").edInitPy(data_config["Data"]) back_node.edAddOutputPort(key, t_pyobj) + ADAO_Case.edAddChild(back_node) + # Set content of the node back_node_script = back_node.getScript() + if key in init_config["Target"]: + # Connect node with InitUserData + back_node_script += "__builtins__[\"init_data\"] = init_data\n" + back_node.edAddInputPort("init_data", t_pyobj) + ADAO_Case.edAddDFLink(init_node.getOutputPort("init_data"), back_node.getInputPort("init_data")) + back_node_script += "# Import script and get data\n__import__(module_name)\nuser_script_module = sys.modules[module_name]\n\n" back_node_script += key + " = user_script_module." + key + "\n" + back_node_script += "stored = " + str(data_config["Stored"]) + "\n" back_node.setScript(back_node_script) - ADAO_Case.edAddChild(back_node) # Connect node with CreateAssimilationStudy CAS_node.edAddInputPort(key, t_pyobj) CAS_node.edAddInputPort(key_type, t_string) @@ -237,14 +246,6 @@ def create_yacs_proc(study_config): ADAO_Case.edAddDFLink(back_node.getOutputPort(key), CAS_node.getInputPort(key)) ADAO_Case.edAddDFLink(back_node.getOutputPort("type"), CAS_node.getInputPort(key_type)) ADAO_Case.edAddDFLink(back_node.getOutputPort("stored"), CAS_node.getInputPort(key_stored)) - back_node_script = back_node.getScript() - back_node_script += "stored = " + str(data_config["Stored"]) + "\n" - # Connect node with InitUserData - if key in init_config["Target"]: - back_node_script += "__builtins__[\"init_data\"] = init_data\n" + back_node_script - back_node.edAddInputPort("init_data", t_pyobj) - ADAO_Case.edAddDFLink(init_node.getOutputPort("init_data"), back_node.getInputPort("init_data")) - back_node.setScript(back_node_script) if data_config["Type"] == "VectorSerie" and data_config["From"] == "String": # Create node @@ -252,21 +253,22 @@ def create_yacs_proc(study_config): back_node = factory_back_node.cloneNode("Get" + key) back_node.getInputPort("vector_in_string").edInitPy(data_config["Data"]) ADAO_Case.edAddChild(back_node) - # Connect node with CreateAssimilationStudy - CAS_node.edAddInputPort(key, t_pyobj) - CAS_node.edAddInputPort(key_type, t_string) - CAS_node.edAddInputPort(key_stored, t_bool) - ADAO_Case.edAddDFLink(back_node.getOutputPort("vector"), CAS_node.getInputPort(key)) - ADAO_Case.edAddDFLink(back_node.getOutputPort("type"), CAS_node.getInputPort(key_type)) - ADAO_Case.edAddDFLink(back_node.getOutputPort("stored"), CAS_node.getInputPort(key_stored)) + # Set content of the node back_node_script = back_node.getScript() back_node_script += "stored = " + str(data_config["Stored"]) + "\n" - # Connect node with InitUserData if key in init_config["Target"]: + # Connect node with InitUserData back_node_script += "__builtins__[\"init_data\"] = init_data\n" + back_node_script back_node.edAddInputPort("init_data", t_pyobj) ADAO_Case.edAddDFLink(init_node.getOutputPort("init_data"), back_node.getInputPort("init_data")) back_node.setScript(back_node_script) + # Connect node with CreateAssimilationStudy + CAS_node.edAddInputPort(key, t_pyobj) + CAS_node.edAddInputPort(key_type, t_string) + CAS_node.edAddInputPort(key_stored, t_bool) + ADAO_Case.edAddDFLink(back_node.getOutputPort("vector"), CAS_node.getInputPort(key)) + ADAO_Case.edAddDFLink(back_node.getOutputPort("type"), CAS_node.getInputPort(key_type)) + ADAO_Case.edAddDFLink(back_node.getOutputPort("stored"), CAS_node.getInputPort(key_stored)) if data_config["Type"] == "VectorSerie" and data_config["From"] == "Script": # Create node @@ -281,10 +283,18 @@ def create_yacs_proc(study_config): else: back_node.getInputPort("script").edInitPy(data_config["Data"]) back_node.edAddOutputPort(key, t_pyobj) + ADAO_Case.edAddChild(back_node) + # Set content of the node back_node_script = back_node.getScript() + if key in init_config["Target"]: + # Connect node with InitUserData + back_node_script += "__builtins__[\"init_data\"] = init_data\n" + back_node.edAddInputPort("init_data", t_pyobj) + ADAO_Case.edAddDFLink(init_node.getOutputPort("init_data"), back_node.getInputPort("init_data")) + back_node_script += "# Import script and get data\n__import__(module_name)\nuser_script_module = sys.modules[module_name]\n\n" back_node_script += key + " = user_script_module." + key + "\n" + back_node_script += "stored = " + str(data_config["Stored"]) + "\n" back_node.setScript(back_node_script) - ADAO_Case.edAddChild(back_node) # Connect node with CreateAssimilationStudy CAS_node.edAddInputPort(key, t_pyobj) CAS_node.edAddInputPort(key_type, t_string) @@ -292,14 +302,6 @@ def create_yacs_proc(study_config): ADAO_Case.edAddDFLink(back_node.getOutputPort(key), CAS_node.getInputPort(key)) ADAO_Case.edAddDFLink(back_node.getOutputPort("type"), CAS_node.getInputPort(key_type)) ADAO_Case.edAddDFLink(back_node.getOutputPort("stored"), CAS_node.getInputPort(key_stored)) - back_node_script = back_node.getScript() - back_node_script += "stored = " + str(data_config["Stored"]) + "\n" - # Connect node with InitUserData - if key in init_config["Target"]: - back_node_script += "__builtins__[\"init_data\"] = init_data\n" + back_node_script - back_node.edAddInputPort("init_data", t_pyobj) - ADAO_Case.edAddDFLink(init_node.getOutputPort("init_data"), back_node.getInputPort("init_data")) - back_node.setScript(back_node_script) if data_config["Type"] in ("Matrix", "ScalarSparseMatrix", "DiagonalSparseMatrix") and data_config["From"] == "String": # Create node @@ -307,6 +309,15 @@ def create_yacs_proc(study_config): back_node = factory_back_node.cloneNode("Get" + key) back_node.getInputPort("matrix_in_string").edInitPy(data_config["Data"]) ADAO_Case.edAddChild(back_node) + # Set content of the node + back_node_script = back_node.getScript() + back_node_script += "stored = " + str(data_config["Stored"]) + "\n" + if key in init_config["Target"]: + # Connect node with InitUserData + back_node_script += "__builtins__[\"init_data\"] = init_data\n" + back_node.edAddInputPort("init_data", t_pyobj) + ADAO_Case.edAddDFLink(init_node.getOutputPort("init_data"), back_node.getInputPort("init_data")) + back_node.setScript(back_node_script) # Connect node with CreateAssimilationStudy CAS_node.edAddInputPort(key, t_pyobj) CAS_node.edAddInputPort(key_type, t_string) @@ -314,14 +325,6 @@ def create_yacs_proc(study_config): ADAO_Case.edAddDFLink(back_node.getOutputPort("matrix"), CAS_node.getInputPort(key)) ADAO_Case.edAddDFLink(back_node.getOutputPort("type"), CAS_node.getInputPort(key_type)) ADAO_Case.edAddDFLink(back_node.getOutputPort("stored"), CAS_node.getInputPort(key_stored)) - back_node_script = back_node.getScript() - back_node_script += "stored = " + str(data_config["Stored"]) + "\n" - # Connect node with InitUserData - if key in init_config["Target"]: - back_node_script += "__builtins__[\"init_data\"] = init_data\n" + back_node_script - back_node.edAddInputPort("init_data", t_pyobj) - ADAO_Case.edAddDFLink(init_node.getOutputPort("init_data"), back_node.getInputPort("init_data")) - back_node.setScript(back_node_script) if data_config["Type"] in ("Matrix", "ScalarSparseMatrix", "DiagonalSparseMatrix") and data_config["From"] == "Script": # Create node @@ -336,11 +339,18 @@ def create_yacs_proc(study_config): else: back_node.getInputPort("script").edInitPy(data_config["Data"]) back_node.edAddOutputPort(key, t_pyobj) + ADAO_Case.edAddChild(back_node) + # Set content of the node back_node_script = back_node.getScript() back_node_script += "stored = " + str(data_config["Stored"]) + "\n" + if key in init_config["Target"]: + # Connect node with InitUserData + back_node_script += "__builtins__[\"init_data\"] = init_data\n" + back_node.edAddInputPort("init_data", t_pyobj) + ADAO_Case.edAddDFLink(init_node.getOutputPort("init_data"), back_node.getInputPort("init_data")) + back_node_script += "# Import script and get data\n__import__(module_name)\nuser_script_module = sys.modules[module_name]\n\n" back_node_script += key + " = user_script_module." + key + "\n" back_node.setScript(back_node_script) - ADAO_Case.edAddChild(back_node) # Connect node with CreateAssimilationStudy CAS_node.edAddInputPort(key, t_pyobj) CAS_node.edAddInputPort(key_type, t_string) @@ -348,13 +358,6 @@ def create_yacs_proc(study_config): ADAO_Case.edAddDFLink(back_node.getOutputPort(key), CAS_node.getInputPort(key)) ADAO_Case.edAddDFLink(back_node.getOutputPort("type"), CAS_node.getInputPort(key_type)) ADAO_Case.edAddDFLink(back_node.getOutputPort("stored"), CAS_node.getInputPort(key_stored)) - # Connect node with InitUserData - if key in init_config["Target"]: - back_node_script = back_node.getScript() - back_node_script += "__builtins__[\"init_data\"] = init_data\n" + back_node_script - back_node.setScript(back_node_script) - back_node.edAddInputPort("init_data", t_pyobj) - ADAO_Case.edAddDFLink(init_node.getOutputPort("init_data"), back_node.getInputPort("init_data")) if data_config["Type"] == "Function" and data_config["From"] == "FunctionDict" and key == "ObservationOperator": FunctionDict = data_config["Data"]