From: Jean-Philippe ARGAUD Date: Fri, 20 Sep 2013 08:55:18 +0000 (+0200) Subject: Improving use of study repertory for scripts X-Git-Tag: V7_3_0~17 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=0340613392cb839428766ed9726f8a63a4a6fdb4;p=modules%2Fadao.git Improving use of study repertory for scripts --- diff --git a/resources/ADAOSchemaCatalog.xml b/resources/ADAOSchemaCatalog.xml index 350e34f..4e9430a 100644 --- a/resources/ADAOSchemaCatalog.xml +++ b/resources/ADAOSchemaCatalog.xml @@ -330,6 +330,11 @@ logging.debug("CREATE Entering in CreateNumpyMatrixFromScript") type = "Matrix" # Get file path and filename +try: + if sys.path.count(studydir)==0 or (sys.path.count(studydir)>0 and sys.path.index(studydir)>0): + sys.path.insert(0,studydir) +except: + pass filepath = os.path.dirname(script) filename = os.path.basename(script) module_name = os.path.splitext(filename)[0] @@ -354,6 +359,11 @@ logging.debug("CREATE Entering in CreateNumpyScalarSparseMatrixFromScript") type = "ScalarSparseMatrix" # Get file path and filename +try: + if sys.path.count(studydir)==0 or (sys.path.count(studydir)>0 and sys.path.index(studydir)>0): + sys.path.insert(0,studydir) +except: + pass filepath = os.path.dirname(script) filename = os.path.basename(script) module_name = os.path.splitext(filename)[0] @@ -378,6 +388,11 @@ logging.debug("CREATE Entering in CreateNumpyDiagonalSparseMatrixFromScript") type = "DiagonalSparseMatrix" # Get file path and filename +try: + if sys.path.count(studydir)==0 or (sys.path.count(studydir)>0 and sys.path.index(studydir)>0): + sys.path.insert(0,studydir) +except: + pass filepath = os.path.dirname(script) filename = os.path.basename(script) module_name = os.path.splitext(filename)[0] @@ -416,6 +431,11 @@ logging.debug("CREATE Entering in CreateNumpyVectorFromScript") type = "Vector" # Get file path and filename +try: + if sys.path.count(studydir)==0 or (sys.path.count(studydir)>0 and sys.path.index(studydir)>0): + sys.path.insert(0,studydir) +except: + pass filepath = os.path.dirname(script) filename = os.path.basename(script) module_name = os.path.splitext(filename)[0] @@ -455,6 +475,11 @@ logging.debug("CREATE Entering in CreateNumpyVectorSerieFromScript") type = "VectorSerie" # Get file path and filename +try: + if sys.path.count(studydir)==0 or (sys.path.count(studydir)>0 and sys.path.index(studydir)>0): + sys.path.insert(0,studydir) +except: + pass filepath = os.path.dirname(script) filename = os.path.basename(script) module_name = os.path.splitext(filename)[0] @@ -522,6 +547,11 @@ import logging, sys, os logging.debug("CREATE Entering in CreateDictFromScript") # Get file path and filename +try: + if sys.path.count(studydir)==0 or (sys.path.count(studydir)>0 and sys.path.index(studydir)>0): + sys.path.insert(0,studydir) +except: + pass filepath = os.path.dirname(script) filename = os.path.basename(script) module_name = os.path.splitext(filename)[0] @@ -543,6 +573,11 @@ import logging, sys, os logging.debug("CREATE Entering in UserDataInitFromScript") # Get file path and filename +try: + if sys.path.count(studydir)==0 or (sys.path.count(studydir)>0 and sys.path.index(studydir)>0): + sys.path.insert(0,studydir) +except: + pass filepath = os.path.dirname(script) filename = os.path.basename(script) module_name = os.path.splitext(filename)[0] diff --git a/src/daSalome/daYacsSchemaCreator/help_methods.py b/src/daSalome/daYacsSchemaCreator/help_methods.py index 72f8b06..3651df7 100644 --- a/src/daSalome/daYacsSchemaCreator/help_methods.py +++ b/src/daSalome/daYacsSchemaCreator/help_methods.py @@ -99,11 +99,9 @@ def check_study(study_config): raise ValueError("\n\nAnalysis found but Data is not defined in the analysis configuration!\n") if analysis_config["From"] == "Script": - check_file_name = "" - if check_repertory: + check_file_name = analysis_config["Data"] + if check_repertory and not os.path.exists(check_file_name): check_file_name = os.path.join(repertory, os.path.basename(analysis_config["Data"])) - else: - check_file_name = analysis_config["Data"] if not os.path.exists(check_file_name): raise ValueError("\n\n The script file cannot be found for UserPostAnalysis,\n please check its availability.\n"+ " The given user file is:\n %s\n" % check_file_name) @@ -194,50 +192,40 @@ def check_data(data_name, data_config, repertory_check=False, repertory=""): # Check des fichiers from_type = data_config["From"] if from_type == "Script": - check_file_name = "" - if repertory_check: + check_file_name = data_config["Data"] + if repertory_check and not os.path.exists(check_file_name): check_file_name = os.path.join(repertory, os.path.basename(data_config["Data"])) - else: - check_file_name = data_config["Data"] if not os.path.exists(check_file_name): raise ValueError("\n\n The script file cannot be found for the \"%s\" keyword, please \n check its availability. The given user file is:\n %s\n"%(from_type,check_file_name)) elif from_type == "FunctionDict": FunctionDict = data_config["Data"] for FunctionName in FunctionDict["Function"]: - check_file_name = "" - if repertory_check: + check_file_name = FunctionDict["Script"][FunctionName] + if repertory_check and not os.path.exists(check_file_name): check_file_name = os.path.join(repertory, os.path.basename(FunctionDict["Script"][FunctionName])) - else: - check_file_name = FunctionDict["Script"][FunctionName] if not os.path.exists(check_file_name): raise ValueError("\n\n The script file cannot be found for the \"%s\" keyword, please \n check its availability. The given user file is:\n %s\n"%(from_type,check_file_name)) elif from_type == "ScriptWithSwitch": ScriptWithSwitch = data_config["Data"] for FunctionName in ScriptWithSwitch["Function"]: - check_file_name = "" - if repertory_check: + check_file_name = ScriptWithSwitch["Script"][FunctionName] + if repertory_check and not os.path.exists(check_file_name): check_file_name = os.path.join(repertory, os.path.basename(ScriptWithSwitch["Script"][FunctionName])) - else: - check_file_name = ScriptWithSwitch["Script"][FunctionName] if not os.path.exists(check_file_name): raise ValueError("\n\n The script file cannot be found for the \"%s\" keyword, please \n check its availability. The given user file is:\n %s\n"%(from_type,check_file_name)) elif from_type == "ScriptWithFunctions": ScriptWithFunctions = data_config["Data"] for FunctionName in ScriptWithFunctions["Function"]: - check_file_name = "" - if repertory_check: + check_file_name = ScriptWithFunctions["Script"][FunctionName] + if repertory_check and not os.path.exists(check_file_name): check_file_name = os.path.join(repertory, os.path.basename(ScriptWithFunctions["Script"][FunctionName])) - else: - check_file_name = ScriptWithFunctions["Script"][FunctionName] if not os.path.exists(check_file_name): raise ValueError("\n\n The script file cannot be found for the \"%s\" keyword, please \n check its availability. The given user file is:\n %s\n"%(from_type,check_file_name)) elif from_type == "ScriptWithOneFunction": ScriptWithOneFunction = data_config["Data"] for FunctionName in ScriptWithOneFunction["Function"]: - check_file_name = "" - if repertory_check: + check_file_name = ScriptWithOneFunction["Script"][FunctionName] + if repertory_check and not os.path.exists(check_file_name): check_file_name = os.path.join(repertory, os.path.basename(ScriptWithOneFunction["Script"][FunctionName])) - else: - check_file_name = ScriptWithOneFunction["Script"][FunctionName] if not os.path.exists(check_file_name): raise ValueError("\n\n The script file cannot be found for the \"%s\" keyword, please \n check its availability. The given user file is:\n %s\n"%(from_type,check_file_name)) diff --git a/src/daSalome/daYacsSchemaCreator/methods.py b/src/daSalome/daYacsSchemaCreator/methods.py index 3dee00e..71ab9e4 100644 --- a/src/daSalome/daYacsSchemaCreator/methods.py +++ b/src/daSalome/daYacsSchemaCreator/methods.py @@ -119,8 +119,12 @@ def create_yacs_proc(study_config): init_config = study_config["UserDataInit"] factory_init_node = catalogAd.getNodeFromNodeMap("UserDataInitFromScript") init_node = factory_init_node.cloneNode("UserDataInit") - if repertory: + if repertory and not os.path.exists(init_config["Data"]): init_node.getInputPort("script").edInitPy(os.path.join(base_repertory, os.path.basename(init_config["Data"]))) + elif repertory and os.path.exists(init_config["Data"]): + init_node.getInputPort("script").edInitPy(init_config["Data"]) + init_node.edAddInputPort("studydir", t_string) + init_node.getInputPort("studydir").edInitPy(base_repertory) else: init_node.getInputPort("script").edInitPy(init_config["Data"]) init_node_script = init_node.getScript() @@ -141,8 +145,12 @@ def create_yacs_proc(study_config): # Create node factory_back_node = catalogAd.getNodeFromNodeMap("CreateDictFromScript") back_node = factory_back_node.cloneNode("Get" + key) - if repertory: + if repertory and not os.path.exists(data_config["Data"]): back_node.getInputPort("script").edInitPy(os.path.join(base_repertory, os.path.basename(data_config["Data"]))) + elif repertory and os.path.exists(data_config["Data"]): + back_node.getInputPort("script").edInitPy(data_config["Data"]) + back_node.edAddInputPort("studydir", t_string) + back_node.getInputPort("studydir").edInitPy(base_repertory) else: back_node.getInputPort("script").edInitPy(data_config["Data"]) back_node.edAddOutputPort(key, t_pyobj) @@ -209,8 +217,12 @@ def create_yacs_proc(study_config): # Create node factory_back_node = catalogAd.getNodeFromNodeMap("CreateNumpyVectorFromScript") back_node = factory_back_node.cloneNode("Get" + key) - if repertory: + if repertory and not os.path.exists(data_config["Data"]): back_node.getInputPort("script").edInitPy(os.path.join(base_repertory, os.path.basename(data_config["Data"]))) + elif repertory and os.path.exists(data_config["Data"]): + back_node.getInputPort("script").edInitPy(data_config["Data"]) + back_node.edAddInputPort("studydir", t_string) + back_node.getInputPort("studydir").edInitPy(base_repertory) else: back_node.getInputPort("script").edInitPy(data_config["Data"]) back_node.edAddOutputPort(key, t_pyobj) @@ -260,8 +272,12 @@ def create_yacs_proc(study_config): # Create node factory_back_node = catalogAd.getNodeFromNodeMap("CreateNumpyVectorSerieFromScript") back_node = factory_back_node.cloneNode("Get" + key) - if repertory: + if repertory and not os.path.exists(data_config["Data"]): back_node.getInputPort("script").edInitPy(os.path.join(base_repertory, os.path.basename(data_config["Data"]))) + elif repertory and os.path.exists(data_config["Data"]): + back_node.getInputPort("script").edInitPy(data_config["Data"]) + back_node.edAddInputPort("studydir", t_string) + back_node.getInputPort("studydir").edInitPy(base_repertory) else: back_node.getInputPort("script").edInitPy(data_config["Data"]) back_node.edAddOutputPort(key, t_pyobj) @@ -311,8 +327,12 @@ def create_yacs_proc(study_config): # Create node factory_back_node = catalogAd.getNodeFromNodeMap("CreateNumpy%sFromScript"%(data_config["Type"],)) back_node = factory_back_node.cloneNode("Get" + key) - if repertory: + if repertory and not os.path.exists(data_config["Data"]): back_node.getInputPort("script").edInitPy(os.path.join(base_repertory, os.path.basename(data_config["Data"]))) + elif repertory and os.path.exists(data_config["Data"]): + back_node.getInputPort("script").edInitPy(data_config["Data"]) + back_node.edAddInputPort("studydir", t_string) + back_node.getInputPort("studydir").edInitPy(base_repertory) else: back_node.getInputPort("script").edInitPy(data_config["Data"]) back_node.edAddOutputPort(key, t_pyobj) @@ -341,8 +361,14 @@ def create_yacs_proc(study_config): for FunctionName in FunctionDict["Function"]: port_name = "ObservationOperator" + FunctionName CAS_node.edAddInputPort(port_name, t_string) - if repertory: + if repertory and not os.path.exists(FunctionDict["Script"][FunctionName]): CAS_node.getInputPort(port_name).edInitPy(os.path.join(base_repertory, os.path.basename(FunctionDict["Script"][FunctionName]))) + elif repertory and os.path.exists(FunctionDict["Script"][FunctionName]): + CAS_node.getInputPort(port_name).edInitPy(FunctionDict["Script"][FunctionName]) + try: + CAS_node.edAddInputPort("studydir", t_string) + CAS_node.getInputPort("studydir").edInitPy(base_repertory) + except: pass else: CAS_node.getInputPort(port_name).edInitPy(FunctionDict["Script"][FunctionName]) @@ -351,8 +377,14 @@ def create_yacs_proc(study_config): for FunctionName in FunctionDict["Function"]: port_name = "EvolutionModel" + FunctionName CAS_node.edAddInputPort(port_name, t_string) - if repertory: + if repertory and not os.path.exists(FunctionDict["Script"][FunctionName]): CAS_node.getInputPort(port_name).edInitPy(os.path.join(base_repertory, os.path.basename(FunctionDict["Script"][FunctionName]))) + elif repertory and os.path.exists(FunctionDict["Script"][FunctionName]): + CAS_node.getInputPort(port_name).edInitPy(FunctionDict["Script"][FunctionName]) + try: + CAS_node.edAddInputPort("studydir", t_string) + CAS_node.getInputPort("studydir").edInitPy(base_repertory) + except: pass else: CAS_node.getInputPort(port_name).edInitPy(FunctionDict["Script"][FunctionName]) @@ -361,8 +393,14 @@ def create_yacs_proc(study_config): for FunctionName in ScriptWithSwitch["Function"]: port_name = "ObservationOperator" + FunctionName CAS_node.edAddInputPort(port_name, t_string) - if repertory: + if repertory and not os.path.exists(ScriptWithSwitch["Script"][FunctionName]): CAS_node.getInputPort(port_name).edInitPy(os.path.join(base_repertory, os.path.basename(ScriptWithSwitch["Script"][FunctionName]))) + elif repertory and os.path.exists(ScriptWithSwitch["Script"][FunctionName]): + CAS_node.getInputPort(port_name).edInitPy(ScriptWithSwitch["Script"][FunctionName]) + try: + CAS_node.edAddInputPort("studydir", t_string) + CAS_node.getInputPort("studydir").edInitPy(base_repertory) + except: pass else: CAS_node.getInputPort(port_name).edInitPy(ScriptWithSwitch["Script"][FunctionName]) @@ -371,8 +409,14 @@ def create_yacs_proc(study_config): for FunctionName in ScriptWithSwitch["Function"]: port_name = "EvolutionModel" + FunctionName CAS_node.edAddInputPort(port_name, t_string) - if repertory: + if repertory and not os.path.exists(ScriptWithSwitch["Script"][FunctionName]): CAS_node.getInputPort(port_name).edInitPy(os.path.join(base_repertory, os.path.basename(ScriptWithSwitch["Script"][FunctionName]))) + elif repertory and os.path.exists(ScriptWithSwitch["Script"][FunctionName]): + CAS_node.getInputPort(port_name).edInitPy(ScriptWithSwitch["Script"][FunctionName]) + try: + CAS_node.edAddInputPort("studydir", t_string) + CAS_node.getInputPort("studydir").edInitPy(base_repertory) + except: pass else: CAS_node.getInputPort(port_name).edInitPy(ScriptWithSwitch["Script"][FunctionName]) @@ -381,8 +425,14 @@ def create_yacs_proc(study_config): for FunctionName in ScriptWithFunctions["Function"]: port_name = "ObservationOperator" + FunctionName CAS_node.edAddInputPort(port_name, t_string) - if repertory: + if repertory and not os.path.exists(ScriptWithFunctions["Script"][FunctionName]): CAS_node.getInputPort(port_name).edInitPy(os.path.join(base_repertory, os.path.basename(ScriptWithFunctions["Script"][FunctionName]))) + elif repertory and os.path.exists(ScriptWithFunctions["Script"][FunctionName]): + CAS_node.getInputPort(port_name).edInitPy(ScriptWithFunctions["Script"][FunctionName]) + try: + CAS_node.edAddInputPort("studydir", t_string) + CAS_node.getInputPort("studydir").edInitPy(base_repertory) + except: pass else: CAS_node.getInputPort(port_name).edInitPy(ScriptWithFunctions["Script"][FunctionName]) @@ -391,8 +441,14 @@ def create_yacs_proc(study_config): for FunctionName in ScriptWithFunctions["Function"]: port_name = "EvolutionModel" + FunctionName CAS_node.edAddInputPort(port_name, t_string) - if repertory: + if repertory and not os.path.exists(ScriptWithFunctions["Script"][FunctionName]): CAS_node.getInputPort(port_name).edInitPy(os.path.join(base_repertory, os.path.basename(ScriptWithFunctions["Script"][FunctionName]))) + elif repertory and os.path.exists(ScriptWithFunctions["Script"][FunctionName]): + CAS_node.getInputPort(port_name).edInitPy(ScriptWithFunctions["Script"][FunctionName]) + try: + CAS_node.edAddInputPort("studydir", t_string) + CAS_node.getInputPort("studydir").edInitPy(base_repertory) + except: pass else: CAS_node.getInputPort(port_name).edInitPy(ScriptWithFunctions["Script"][FunctionName]) @@ -401,8 +457,14 @@ def create_yacs_proc(study_config): for FunctionName in ScriptWithOneFunction["Function"]: port_name = "ObservationOperator" + FunctionName CAS_node.edAddInputPort(port_name, t_string) - if repertory: + if repertory and not os.path.exists(ScriptWithOneFunction["Script"][FunctionName]): CAS_node.getInputPort(port_name).edInitPy(os.path.join(base_repertory, os.path.basename(ScriptWithOneFunction["Script"][FunctionName]))) + elif repertory and os.path.exists(ScriptWithOneFunction["Script"][FunctionName]): + CAS_node.getInputPort(port_name).edInitPy(ScriptWithOneFunction["Script"][FunctionName]) + try: + CAS_node.edAddInputPort("studydir", t_string) + CAS_node.getInputPort("studydir").edInitPy(base_repertory) + except: pass else: CAS_node.getInputPort(port_name).edInitPy(ScriptWithOneFunction["Script"][FunctionName]) @@ -411,8 +473,14 @@ def create_yacs_proc(study_config): for FunctionName in ScriptWithOneFunction["Function"]: port_name = "EvolutionModel" + FunctionName CAS_node.edAddInputPort(port_name, t_string) - if repertory: + if repertory and not os.path.exists(ScriptWithOneFunction["Script"][FunctionName]): CAS_node.getInputPort(port_name).edInitPy(os.path.join(base_repertory, os.path.basename(ScriptWithOneFunction["Script"][FunctionName]))) + elif repertory and os.path.exists(ScriptWithOneFunction["Script"][FunctionName]): + CAS_node.getInputPort(port_name).edInitPy(ScriptWithOneFunction["Script"][FunctionName]) + try: + CAS_node.edAddInputPort("studydir", t_string) + CAS_node.getInputPort("studydir").edInitPy(base_repertory) + except: pass else: CAS_node.getInputPort(port_name).edInitPy(ScriptWithOneFunction["Script"][FunctionName]) @@ -442,7 +510,7 @@ def create_yacs_proc(study_config): # We create a new pyscript node opt_script_nodeOO = runtime.createScriptNode("", "FunctionNodeOO") - if repertory: + if repertory and not os.path.exists(script_filename): script_filename = os.path.join(base_repertory, os.path.basename(script_filename)) try: script_str= open(script_filename, 'r') @@ -469,7 +537,7 @@ def create_yacs_proc(study_config): break # We create a new pyscript node opt_script_nodeOO = runtime.createScriptNode("", "FunctionNodeOO") - if repertory: + if repertory and not os.path.exists(script_filename): script_filename = os.path.join(base_repertory, os.path.basename(script_filename)) try: script_str= open(script_filename, 'r') @@ -497,7 +565,7 @@ def create_yacs_proc(study_config): # We create a new pyscript node opt_script_nodeOO = runtime.createScriptNode("", "FunctionNodeOO") - if repertory: + if repertory and not os.path.exists(script_filename): script_filename = os.path.join(base_repertory, os.path.basename(script_filename)) try: script_str= open(script_filename, 'r') @@ -577,7 +645,7 @@ def create_yacs_proc(study_config): # We create a new pyscript node opt_script_nodeOO = runtime.createScriptNode("", "FunctionNodeOO") - if repertory: + if repertory and not os.path.exists(script_filename): script_filename = os.path.join(base_repertory, os.path.basename(script_filename)) try: script_str= open(script_filename, 'r') @@ -663,7 +731,7 @@ def create_yacs_proc(study_config): # We create a new pyscript node opt_script_nodeEM = runtime.createScriptNode("", "FunctionNodeEM") - if repertory: + if repertory and not os.path.exists(script_filename): script_filename = os.path.join(base_repertory, os.path.basename(script_filename)) try: script_str= open(script_filename, 'r') @@ -691,7 +759,7 @@ def create_yacs_proc(study_config): # We create a new pyscript node opt_script_nodeEM = runtime.createScriptNode("", "FunctionNodeEM") - if repertory: + if repertory and not os.path.exists(script_filename): script_filename = os.path.join(base_repertory, os.path.basename(script_filename)) try: script_str= open(script_filename, 'r') @@ -718,7 +786,7 @@ def create_yacs_proc(study_config): break # We create a new pyscript node opt_script_nodeEM = runtime.createScriptNode("", "FunctionNodeEM") - if repertory: + if repertory and not os.path.exists(script_filename): script_filename = os.path.join(base_repertory, os.path.basename(script_filename)) try: script_str= open(script_filename, 'r') @@ -800,7 +868,7 @@ def create_yacs_proc(study_config): break # We create a new pyscript node opt_script_nodeEM = runtime.createScriptNode("", "FunctionNodeEM") - if repertory: + if repertory and not os.path.exists(script_filename): script_filename = os.path.join(base_repertory, os.path.basename(script_filename)) try: script_str= open(script_filename, 'r') @@ -930,8 +998,12 @@ def create_yacs_proc(study_config): else: factory_observation_node = catalogAd.getNodeFromNodeMap("ObservationNodeFile") observation_node = factory_observation_node.cloneNode("Observation") - if repertory: + if repertory and not os.path.exists(observer_cfg["Script"]): observation_node.getInputPort("script").edInitPy(os.path.join(base_repertory, os.path.basename(observer_cfg["Script"]))) + elif repertory and os.path.exists(observer_cfg["Script"]): + observation_node.getInputPort("script").edInitPy(observer_cfg["Script"]) + observation_node.edAddInputPort("studydir", t_string) + observation_node.getInputPort("studydir").edInitPy(base_repertory) else: observation_node.getInputPort("script").edInitPy(observer_cfg["Script"]) observer_bloc.edAddChild(observation_node) @@ -1024,7 +1096,7 @@ def create_yacs_proc(study_config): analysis_node = factory_analysis_node.cloneNode("UserPostAnalysis") default_script = analysis_node.getScript() analysis_file_name = analysis_config["Data"] - if repertory: + if repertory and not os.path.exists(analysis_file_name): analysis_file_name = os.path.join(base_repertory, os.path.basename(analysis_file_name)) try: analysis_file = open(analysis_file_name, 'r')