Salome HOME
String et Script pour les observers
[modules/adao.git] / src / daSalome / daYacsSchemaCreator / help_methods.py
index 20ef78820f6f878e32fb13f794f04816f45bdfeb..018a20d69b3289bb12d9a6dc1d4c80f8948c3a45 100644 (file)
@@ -1,23 +1,23 @@
 #-*- coding: utf-8 -*-
-#  Copyright (C) 2010 EDF R&D
+# Copyright (C) 2010-2011 EDF R&D
 #
-#  This library is free software; you can redistribute it and/or
-#  modify it under the terms of the GNU General Public
-#  License as published by the Free Software Foundation; either
-#  version 2.1 of the License.
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License.
 #
-#  This library is distributed in the hope that it will be useful,
-#  but WITHOUT ANY WARRANTY; without even the implied warranty of
-#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-#  Lesser General Public License for more details.
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
 #
-#  You should have received a copy of the GNU Lesser General Public
-#  License along with this library; if not, write to the Free Software
-#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 #
-# --
-# Author : AndrĂ© RIBES (EDF R&D)
-# --
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+# Author: AndrĂ© Ribes, andre.ribes@edf.fr, EDF R&D
 
 import sys
 import os
@@ -89,6 +89,10 @@ def check_study(study_config):
   if "UserDataInit" in study_config.keys():
     check_data("UserDataInit", study_config["UserDataInit"], check_repertory, repertory)
 
+  # Variables
+  check_variables("InputVariables", study_config)
+  check_variables("OutputVariables", study_config)
+
   # Analyse
   if "UserPostAnalysis" in study_config.keys():
     analysis_config = study_config["UserPostAnalysis"]
@@ -106,7 +110,7 @@ def check_study(study_config):
 
     if analysis_config["From"] == "Script":
       check_file_name = ""
-      if repertory_check:
+      if check_repertory:
         check_file_name = os.path.join(repertory, os.path.basename(analysis_config["Data"]))
       else:
         check_file_name = analysis_config["Data"]
@@ -115,6 +119,81 @@ def check_study(study_config):
         logging.fatal("File is %s" % check_file_name)
         sys.exit(1)
 
+  # Check observers
+  if "Observers" in study_config.keys():
+    for obs_var in study_config["Observers"]:
+      # Check du type
+      if not isinstance(study_config["Observers"][obs_var], type({})):
+        logging.fatal("An observer description has to be a Python dictionary")
+        logging.fatal("Observer is %s" % obs_var)
+        sys.exit(1)
+      if "nodetype" not in study_config["Observers"][obs_var].keys():
+        logging.fatal("An observer description must provide a nodetype")
+        logging.fatal("Observer is %s" % obs_var)
+        sys.exit(1)
+      nodetype = study_config["Observers"][obs_var]["nodetype"]
+      if not isinstance(study_config["Observers"][obs_var]["nodetype"], type("")):
+        logging.fatal("An observer nodetype description must be a string")
+        logging.fatal("Observer is %s" % obs_var)
+        sys.exit(1)
+      if nodetype != "String" and nodetype != "Script":
+        logging.fatal("An observer nodetype must be equal to 'String' or 'Script'")
+        logging.fatal("Observer is %s" % obs_var)
+        sys.exit(1)
+      if nodetype == "String":
+        if "String" not in study_config["Observers"][obs_var].keys():
+          logging.fatal("An observer with nodetype String must provide a String")
+          logging.fatal("Observer is %s" % obs_var)
+          sys.exit(1)
+        if not isinstance(study_config["Observers"][obs_var]["String"], type("")):
+          logging.fatal("An observer String description must be a string")
+          logging.fatal("Observer is %s" % obs_var)
+          sys.exit(1)
+      if nodetype == "Script":
+        if "Script" not in study_config["Observers"][obs_var].keys():
+          logging.fatal("An observer with nodetype Script provide a Script")
+          logging.fatal("Observer is %s" % obs_var)
+          sys.exit(1)
+        if not isinstance(study_config["Observers"][obs_var]["Script"], type("")):
+          logging.fatal("An observer Script description must be a string")
+          logging.fatal("Observer is %s" % obs_var)
+          sys.exit(1)
+      if "scheduler" in study_config["Observers"][obs_var].keys():
+        if not isinstance(study_config["Observers"][obs_var]["scheduler"], type("")):
+          logging.fatal("An observer scheduler description must be a string")
+          logging.fatal("Observer is %s" % obs_var)
+          sys.exit(1)
+
+def check_variables(name, study_config):
+
+  if name not in study_config.keys():
+    logging.fatal("%s not found in your study configuration!" % name)
+    sys.exit(1)
+
+  variable_config = study_config[name]
+  if "Order" not in variable_config.keys():
+    logging.fatal("Order not found in the %s configuration!" % name)
+    sys.exit(1)
+
+  list_of_variables = variable_config["Order"]
+  if not isinstance(list_of_variables, type([])):
+    logging.fatal("Order sould be a list in the %s configuration!" % name)
+    sys.exit(1)
+  if len(list_of_variables) < 1:
+    logging.fatal("Order should contain one or more names in the %s configuration!" % name)
+    sys.exit(1)
+
+  for var in list_of_variables:
+    if var not in variable_config.keys():
+      logging.fatal("Variable %s not found in the %s configuration!" % name)
+      sys.exit(1)
+    value = variable_config[var]
+    try:
+      value = int(value)
+    except:
+      loggind.fatal("Variable %s value cannot be converted in an integer in the %s configuration!" % name)
+      sys.exit(1)
+
 def check_data(data_name, data_config, repertory_check=False, repertory=""):
 
   logging.debug("[check_data] " + data_name)