]> SALOME platform Git repositories - modules/adao.git/commitdiff
Salome HOME
Study repertory - ok
authorAndré Ribes <andre.ribes@edf.fr>
Thu, 24 Mar 2011 22:43:10 +0000 (23:43 +0100)
committerAndré Ribes <andre.ribes@edf.fr>
Thu, 24 Mar 2011 22:43:10 +0000 (23:43 +0100)
bin/AdaoCatalogGenerator.py
src/daSalome/daYacsSchemaCreator/help_methods.py
src/daSalome/daYacsSchemaCreator/infos_daComposant.py
src/daSalome/daYacsSchemaCreator/methods.py

index c36656cb6662fab3a69ba547142702aded35b98a..1986430cf14de95f65292f1e91bf9799e24d4bb1 100644 (file)
@@ -49,7 +49,7 @@ def F_${data_name}(statut) : return FACT(statut = statut,
                                          FROM = SIMP(statut = "o", typ = "TXM", into=(${data_into}), defaut=${data_default}),
                                          SCRIPT_DATA = BLOC ( condition = " FROM in ( 'Script', ) ",
 
-                                                      SCRIPT_FILE = SIMP(statut = "o", typ = "Fichier"),
+                                                      SCRIPT_FILE = SIMP(statut = "o", typ = "FichierNoAbs", validators=(OnlyStr())),
                                                      ),
                                          STRING_DATA = BLOC ( condition = " FROM in ( 'String', ) ",
 
@@ -57,7 +57,7 @@ def F_${data_name}(statut) : return FACT(statut = statut,
                                                      ),
                                          FUNCTIONDICT_DATA = BLOC ( condition = " FROM in ( 'FunctionDict', ) ",
 
-                                                      FUNCTIONDICT_FILE = SIMP(statut = "o", typ = "Fichier"),
+                                                      FUNCTIONDICT_FILE = SIMP(statut = "o", typ = "FichierNoAbs", validators=(OnlyStr())),
                                                      ),
                                     )
 """
@@ -73,7 +73,7 @@ def F_InitChoice() : return  ("Background",
                              )
 
 def F_Init(statut) : return FACT(statut = statut,
-                                 INIT_FILE = SIMP(statut = "o", typ = "Fichier"),
+                                 INIT_FILE = SIMP(statut = "o", typ = "FichierNoAbs", validators=(OnlyStr())),
                                  TARGET_LIST = SIMP(statut = "o", typ = "TXM", min=1, max="**", into=F_InitChoice(),  validators=(VerifExiste(2))),
                                 )
 """
index 0537af0b3d3a9161d120f7aebd0e771caf96485c..20ef78820f6f878e32fb13f794f04816f45bdfeb 100644 (file)
@@ -20,6 +20,7 @@
 # --
 
 import sys
+import os
 import traceback
 import logging
 
@@ -60,6 +61,17 @@ def check_study(study_config):
   if "Debug" not in study_config:
     study_config["Debug"] = "0"
 
+  # Repertory
+  check_repertory = False
+  repertory = ""
+  if "Repertory" in study_config.keys():
+    repertory = study_config["Repertory"]
+    check_repertory = True
+    if not os.path.isabs(repertory):
+      logging.fatal("Study repertory should be an absolute path")
+      logging.fatal("Repertory provided is %s" % repertory)
+      sys.exit(1)
+
   # Check if all the data is provided
   for key in AlgoDataRequirements[study_config["Algorithm"]]:
     if key not in study_config.keys():
@@ -71,7 +83,11 @@ def check_study(study_config):
   # Data
   for key in study_config.keys():
     if key in AssimData:
-      check_data(key, study_config[key])
+      check_data(key, study_config[key], check_repertory, repertory)
+
+  # UserDataInit
+  if "UserDataInit" in study_config.keys():
+    check_data("UserDataInit", study_config["UserDataInit"], check_repertory, repertory)
 
   # Analyse
   if "UserPostAnalysis" in study_config.keys():
@@ -88,8 +104,18 @@ def check_study(study_config):
       logging.fatal("Analysis found but Data is not defined in the analysis configuration !")
       sys.exit(1)
 
+    if analysis_config["From"] == "Script":
+      check_file_name = ""
+      if repertory_check:
+        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):
+        logging.fatal("A script file cannot be found")
+        logging.fatal("File is %s" % check_file_name)
+        sys.exit(1)
 
-def check_data(data_name, data_config):
+def check_data(data_name, data_config, repertory_check=False, repertory=""):
 
   logging.debug("[check_data] " + data_name)
   data_name_data = "Data"
@@ -117,3 +143,27 @@ def check_data(data_name, data_config):
                     + "\n You can have : " + str(FromNumpyList[data_config[data_name_type]]))
       sys.exit(1)
 
+  # Check des fichiers
+  from_type = data_config["From"]
+  if from_type == "Script":
+    check_file_name = ""
+    if repertory_check:
+      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):
+      logging.fatal("A script file cannot be found")
+      logging.fatal("File is %s" % check_file_name)
+      sys.exit(1)
+  elif from_type == "FunctionDict":
+    FunctionDict = data_config["Data"]
+    for FunctionName in FunctionDict["Function"]:
+      check_file_name = ""
+      if repertory_check:
+        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):
+        logging.fatal("A script file cannot be found")
+        logging.fatal("File is %s" % check_file_name)
+        sys.exit(1)
index 14aba31d4b7ce039d41ba695d740d8983a31811d..04096757c4964c141de84ca712b6e60224ecd3d8 100644 (file)
@@ -42,6 +42,7 @@ AssimType["Observation"] = ["Vector"]
 AssimType["ObservationError"] = ["Matrix"]
 AssimType["ObservationOperator"] = ["Matrix", "Function"]
 AssimType["AlgorithmParameters"] = ["Dict"]
+AssimType["UserDataInit"] = ["Dict"]
 #AssimType["ObservationOperatorAppliedToX"] = ["List"]
 
 FromNumpyList = {}
@@ -95,6 +96,7 @@ AssimDataDict["Observation"] = ["Vector"]
 AssimDataDict["ObservationError"] = ["Matrix"]
 AssimDataDict["ObservationOperator"] = ["Matrix", "Function"]
 AssimDataDict["AlgorithmParameters"] = ["Dict"]
+AssimDataDict["UserDataInit"] = ["Dict"]
 
 AssimDataDefaultDict = {}
 AssimDataDefaultDict["Background"]          = "Vector"
@@ -103,6 +105,7 @@ AssimDataDefaultDict["Observation"]         = "Vector"
 AssimDataDefaultDict["ObservationError"]    = "Matrix"
 AssimDataDefaultDict["ObservationOperator"] = "Function"
 AssimDataDefaultDict["AlgorithmParameters"] = "Dict"
+AssimDataDefaultDict["UserDataInit"]        = "Dict"
 
 # Assimilation optional nodes
 OptDict = {}
index d9922b1889fa2dca253a8aaf1d80007541987a98..0aa752c16bd36df751ae6d3fa44690f898952029 100644 (file)
@@ -51,6 +51,12 @@ def create_yacs_proc(study_config):
   t_pyobj  = proc.getTypeCode("pyobj")
   t_string = proc.getTypeCode("string")
 
+  repertory = False
+  base_repertory = ""
+  if "Repertory" in study_config.keys():
+    base_repertory = study_config["Repertory"]
+    repertory = True
+
   # Step 0: create AssimilationStudyObject
   factory_CAS_node = catalogAd._nodeMap["CreateAssimilationStudy"]
   CAS_node = factory_CAS_node.cloneNode("CreateAssimilationStudy")
@@ -69,7 +75,10 @@ def create_yacs_proc(study_config):
     init_config = study_config["UserDataInit"]
     factory_init_node = catalogAd._nodeMap["UserDataInitFromScript"]
     init_node = factory_init_node.cloneNode("UserDataInit")
-    init_node.getInputPort("script").edInitPy(init_config["Data"])
+    if repertory:
+      init_node.getInputPort("script").edInitPy(os.path.join(base_repertory, os.path.basename(init_config["Data"])))
+    else:
+      init_node.getInputPort("script").edInitPy(init_config["Data"])
     proc.edAddChild(init_node)
 
   # Step 1: get input data from user configuration
@@ -84,7 +93,10 @@ def create_yacs_proc(study_config):
         # Create node
         factory_back_node = catalogAd._nodeMap["CreateDictFromScript"]
         back_node = factory_back_node.cloneNode("Get" + key)
-        back_node.getInputPort("script").edInitPy(data_config["Data"])
+        if repertory:
+          back_node.getInputPort("script").edInitPy(os.path.join(base_repertory, os.path.basename(data_config["Data"])))
+        else:
+          back_node.getInputPort("script").edInitPy(data_config["Data"])
         back_node.edAddOutputPort(key, t_pyobj)
         proc.edAddChild(back_node)
         # Connect node with CreateAssimilationStudy
@@ -115,7 +127,10 @@ def create_yacs_proc(study_config):
         # Create node
         factory_back_node = catalogAd._nodeMap["CreateNumpyVectorFromScript"]
         back_node = factory_back_node.cloneNode("Get" + key)
-        back_node.getInputPort("script").edInitPy(data_config["Data"])
+        if repertory:
+          back_node.getInputPort("script").edInitPy(os.path.join(base_repertory, os.path.basename(data_config["Data"])))
+        else:
+          back_node.getInputPort("script").edInitPy(data_config["Data"])
         back_node.edAddOutputPort(key, t_pyobj)
         proc.edAddChild(back_node)
         # Connect node with CreateAssimilationStudy
@@ -148,7 +163,10 @@ def create_yacs_proc(study_config):
         # Create node
         factory_back_node = catalogAd._nodeMap["CreateNumpyMatrixFromScript"]
         back_node = factory_back_node.cloneNode("Get" + key)
-        back_node.getInputPort("script").edInitPy(data_config["Data"])
+        if repertory:
+          back_node.getInputPort("script").edInitPy(os.path.join(base_repertory, os.path.basename(data_config["Data"])))
+        else:
+          back_node.getInputPort("script").edInitPy(data_config["Data"])
         back_node.edAddOutputPort(key, t_pyobj)
         proc.edAddChild(back_node)
         # Connect node with CreateAssimilationStudy
@@ -166,7 +184,10 @@ def create_yacs_proc(study_config):
          for FunctionName in FunctionDict["Function"]:
            port_name = "ObservationOperator" + FunctionName
            CAS_node.edAddInputPort(port_name, t_string)
-           CAS_node.getInputPort(port_name).edInitPy(FunctionDict["Script"][FunctionName])
+           if repertory:
+             CAS_node.getInputPort(port_name).edInitPy(os.path.join(base_repertory, os.path.basename(FunctionDict["Script"][FunctionName])))
+           else:
+             CAS_node.getInputPort(port_name).edInitPy(FunctionDict["Script"][FunctionName])
 
   # Step 3: create compute bloc
   compute_bloc = runtime.createBloc("compute_bloc")
@@ -195,9 +216,8 @@ def create_yacs_proc(study_config):
 
       # We create a new pyscript node
       opt_script_node = runtime.createScriptNode("", "FunctionNode")
-      if not os.path.exists(script_filename):
-        logging.fatal("Function script source file does not exists ! :" + script_filename)
-        sys.exit(1)
+      if repertory:
+        script_filename = os.path.join(base_repertory, os.path.basename(script_filename))
       try:
         script_str= open(script_filename, 'r')
       except:
@@ -260,11 +280,11 @@ def create_yacs_proc(study_config):
       factory_analysis_node = catalogAd._nodeMap["SimpleUserAnalysis"]
       analysis_node = factory_analysis_node.cloneNode("UserPostAnalysis")
       default_script = analysis_node.getScript()
-      if not os.path.exists(analysis_config["Data"]):
-        logging.fatal("Analysis source file does not exists ! :" + str(analysis_config["Data"]))
-        sys.exit(1)
+      analysis_file_name = analysis_config["Data"]
+      if repertory:
+        analysis_file_name = os.path.join(base_repertory, os.path.basename(analysis_file_name))
       try:
-        analysis_file = open(analysis_config["Data"], 'r')
+        analysis_file = open(analysis_file_name, 'r')
       except:
         logging.fatal("Exception in opening analysis file : " + str(analysis_config["Data"]))
         traceback.print_exc()