2 # Copyright (C) 2008-2015 EDF R&D
4 # This file is part of SALOME ADAO module
6 # This library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation; either
9 # version 2.1 of the License.
11 # This library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # Lesser General Public License for more details.
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with this library; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 # Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D
29 from daYacsSchemaCreator.infos_daComposant import *
33 logging.debug("Arguments are :" + str(args))
35 raise ValueError("\n\n Bad number of arguments: you have to provide two arguments (%d given)\n" % (len(args)))
37 def check_study(study_config):
39 logging.debug("[check_env] study_config : " + str(study_config))
42 if not isinstance(study_config, dict):
43 raise ValueError("\n\n Study configuration is not a dictionnary!\n")
46 if "Name" not in study_config:
47 raise ValueError("\n\n Cannot find Name in the study configuration!\n")
50 if "Algorithm" not in study_config:
51 raise ValueError("\n\n Cannot find Algorithm in the study configuration!\n")
53 if not (study_config["Algorithm"] in AssimAlgos or study_config["Algorithm"] in CheckAlgos):
54 raise ValueError("\n\n Algorithm provided is unknow : " + str(study_config["Algorithm"]) +
55 "\n You can choose between : " + str(AssimAlgos)+" "+str(CheckAlgos) + "\n")
58 if "Debug" not in study_config:
59 study_config["Debug"] = "0"
62 check_repertory = False
64 if "Repertory" in study_config.keys():
65 repertory = study_config["Repertory"]
66 check_repertory = True
67 if not os.path.isabs(repertory):
68 raise ValueError("\n\n Study repertory should be an absolute path\n"+
69 " Repertory provided is %s\n" % repertory)
71 # Check if all the data is provided
72 for key in AlgoDataRequirements[study_config["Algorithm"]]:
73 if key not in study_config.keys():
74 raise ValueError("\n\nCannot find " + key + " in your study configuration !" +
75 "\n This key is mandatory into a study with " + study_config["Algorithm"] + " algorithm." +
76 "\n " + study_config["Algorithm"] + " requirements are " + str(AlgoDataRequirements[study_config["Algorithm"]]) + "\n")
79 for key in study_config.keys():
81 check_data(key, study_config[key], check_repertory, repertory)
84 if "UserDataInit" in study_config.keys():
85 check_data("UserDataInit", study_config["UserDataInit"], check_repertory, repertory)
88 check_variables("InputVariables", study_config)
89 check_variables("OutputVariables", study_config)
92 if "UserPostAnalysis" in study_config.keys():
93 analysis_config = study_config["UserPostAnalysis"]
94 if "From" not in analysis_config:
95 raise ValueError("\n\n UserPostAnalysis found but From is not defined \n in the analysis configuration!\n")
97 if analysis_config["From"] not in AnalysisFromList:
98 raise ValueError("\n\n Analysis From defined in the study configuration does not have a correct type : " + str(analysis_config["From"])
99 + "\n You can have: " + str(AnalysisFromList) + "\n")
100 if "Data" not in analysis_config:
101 raise ValueError("\n\nAnalysis found but Data is not defined in the analysis configuration!\n")
103 if analysis_config["From"] == "Script":
104 check_file_name = analysis_config["Data"]
105 if check_repertory and not os.path.exists(check_file_name):
106 check_file_name = os.path.join(repertory, os.path.basename(analysis_config["Data"]))
107 if not os.path.exists(check_file_name):
108 raise ValueError("\n\n The script file cannot be found for UserPostAnalysis,\n please check its availability.\n"+
109 " The given user file is:\n %s\n" % check_file_name)
112 if "Observers" in study_config.keys():
113 for obs_var in study_config["Observers"]:
115 if not isinstance(study_config["Observers"][obs_var], type({})):
116 raise ValueError("\n\n An observer description has to be a Python dictionary\n"+
117 " Observer is %s\n" % obs_var)
118 if "nodetype" not in study_config["Observers"][obs_var].keys():
119 raise ValueError("\n\n An observer description must provide a nodetype\n"+
120 " Observer is %s\n" % obs_var)
121 nodetype = study_config["Observers"][obs_var]["nodetype"]
122 if not isinstance(study_config["Observers"][obs_var]["nodetype"], type("")):
123 raise ValueError("\n\n An observer nodetype description must be a string\n"+
124 " Observer is %s\n" % obs_var)
125 if nodetype != "String" and nodetype != "Script":
126 raise ValueError("\n\n An observer nodetype must be equal to 'String' or 'Script'\n"+
127 " Observer is %s\n" % obs_var)
128 if nodetype == "String":
129 if "String" not in study_config["Observers"][obs_var].keys():
130 raise ValueError("\n\n An observer with nodetype String must provide a String\n"+
131 " Observer is %s\n" % obs_var)
132 if not isinstance(study_config["Observers"][obs_var]["String"], type("")):
133 raise ValueError("\n\n An observer String description must be a string\n"+
134 " Observer is %s\n" % obs_var)
135 if nodetype == "Script":
136 if "Script" not in study_config["Observers"][obs_var].keys():
137 raise ValueError("\n\n An observer with nodetype Script provide a Script\n"+
138 " Observer is %s\n" % obs_var)
139 if not isinstance(study_config["Observers"][obs_var]["Script"], type("")):
140 raise ValueError("\n\n An observer Script description must be a string\n"+
141 " Observer is %s\n" % obs_var)
142 if "scheduler" in study_config["Observers"][obs_var].keys():
143 if not isinstance(study_config["Observers"][obs_var]["scheduler"], type("")):
144 raise ValueError("\n\n An observer scheduler description must be a string\n"+
145 " Observer is %s\n" % obs_var)
147 def check_variables(name, study_config):
149 if name not in study_config.keys():
150 raise ValueError("\n\n %s not found in your study configuration!\n" % name)
152 variable_config = study_config[name]
153 if "Order" not in variable_config.keys():
154 raise ValueError("\n\n Order not found in the %s configuration!\n" % name)
156 list_of_variables = variable_config["Order"]
157 if not isinstance(list_of_variables, type([])):
158 raise ValueError("\n\n Order sould be a list in the %s configuration!\n" % name)
159 if len(list_of_variables) < 1:
160 raise ValueError("\n\nOrder should contain one or more names in the %s configuration!\n" % name)
162 for var in list_of_variables:
163 if var not in variable_config.keys():
164 raise ValueError("\n\n Variable %s not found in the %s configuration!\n" % name)
165 value = variable_config[var]
169 raise ValueError("\n\n Variable %s value cannot be converted in an integer \n in the %s configuration!\n" % name)
171 def check_data(data_name, data_config, repertory_check=False, repertory=""):
173 logging.debug("[check_data] " + data_name)
174 data_name_data = "Data"
175 data_name_type = "Type"
176 data_name_from = "From"
178 if data_name_data not in data_config:
179 raise ValueError("\n\n" + data_name +" found but " + data_name_data +" is not defined in the study configuration !\n")
181 if data_name_type not in data_config:
182 raise ValueError("\n\n" + data_name +" found but " + data_name_type +" is not defined in the study configuration !\n")
184 if data_config[data_name_type] not in AssimType[data_name]:
185 raise ValueError("\n\n" + data_name_type + " of " + data_name + " defined in the study configuration does not have a correct type : " + str(data_config[data_name_type])
186 + "\n You can have : " + str(AssimType[data_name]) + "\n")
187 if data_name_from not in data_config:
188 raise ValueError("\n\n" + data_name + " found but " + data_name_from + " is not defined in the study configuration !\n")
190 if data_config[data_name_from] not in FromNumpyList[data_config[data_name_type]]:
191 raise ValueError("\n\n" + data_name_from + " of " + data_name + " defined in the study configuration does not have a correct value : " + str(data_config[data_name_from])
192 + "\n You can have : " + str(FromNumpyList[data_config[data_name_type]]) + "\n")
195 from_type = data_config["From"]
196 if from_type == "Script":
197 check_file_name = data_config["Data"]
198 if repertory_check and not os.path.exists(check_file_name):
199 check_file_name = os.path.join(repertory, os.path.basename(data_config["Data"]))
200 if not os.path.exists(check_file_name):
201 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))
202 elif (from_type == "FunctionDict" or from_type == "ScriptWithSwitch" or from_type == "ScriptWithFunctions" or from_type == "ScriptWithOneFunction"):
203 TheData = data_config["Data"]
204 for FunctionName in TheData["Function"]:
205 check_file_name = TheData["Script"][FunctionName]
206 if repertory_check and not os.path.exists(check_file_name):
207 check_file_name = os.path.join(repertory, os.path.basename(TheData["Script"][FunctionName]))
208 if not os.path.exists(check_file_name):
209 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))