2 # Copyright (C) 2010 EDF R&D
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 # Author : André RIBES (EDF R&D)
27 from daYacsSchemaCreator.infos_daComposant import *
31 logging.debug("Arguments are :" + str(args))
33 logging.fatal("Bad number of arguments: you have to provide two arguments (%d given)" % (len(args)))
36 def check_study(study_config):
38 logging.debug("[check_env] study_config : " + str(study_config))
41 if not isinstance(study_config, dict):
42 logging.fatal("Study configuration is not a dictionnary")
46 if "Name" not in study_config:
47 logging.fatal("Cannot found Name in the study configuration")
51 if "Algorithm" not in study_config:
52 logging.fatal("Cannot found Algorithm in the study configuration")
55 if study_config["Algorithm"] not in AssimAlgos:
56 logging.fatal("Algorithm provided is unknow : " + str(study_config["Algorithm"]) +
57 "\n You can choose between : " + str(AssimAlgos))
61 if "Debug" not in study_config:
62 study_config["Debug"] = "0"
65 check_repertory = False
67 if "Repertory" in study_config.keys():
68 repertory = study_config["Repertory"]
69 check_repertory = True
70 if not os.path.isabs(repertory):
71 logging.fatal("Study repertory should be an absolute path")
72 logging.fatal("Repertory provided is %s" % repertory)
75 # Check if all the data is provided
76 for key in AlgoDataRequirements[study_config["Algorithm"]]:
77 if key not in study_config.keys():
78 logging.fatal("Cannot found " + key + " in your study configuration !" +
79 "\n This key is mandatory into a study with " + study_config["Algorithm"] + " algorithm." +
80 "\n " + study_config["Algorithm"] + " requirements are " + str(AlgoDataRequirements[study_config["Algorithm"]]))
84 for key in study_config.keys():
86 check_data(key, study_config[key], check_repertory, repertory)
89 if "UserDataInit" in study_config.keys():
90 check_data("UserDataInit", study_config["UserDataInit"], check_repertory, repertory)
93 check_variables("InputVariables", study_config)
94 check_variables("OutputVariables", study_config)
97 if "UserPostAnalysis" in study_config.keys():
98 analysis_config = study_config["UserPostAnalysis"]
99 if "From" not in analysis_config:
100 logging.fatal("UserPostAnalysis found but From is not defined in the analysis configuration !")
103 if analysis_config["From"] not in AnalysisFromList:
104 logging.fatal("Analysis From defined in the study configuration does not have a correct type : " + str(analysis_config["From"])
105 + "\n You can have : " + str(AnalysisFromList))
107 if "Data" not in analysis_config:
108 logging.fatal("Analysis found but Data is not defined in the analysis configuration !")
111 if analysis_config["From"] == "Script":
114 check_file_name = os.path.join(repertory, os.path.basename(analysis_config["Data"]))
116 check_file_name = analysis_config["Data"]
117 if not os.path.exists(check_file_name):
118 logging.fatal("A script file cannot be found")
119 logging.fatal("File is %s" % check_file_name)
122 def check_variables(name, study_config):
124 if name not in study_config.keys():
125 logging.fatal("%s not found in your study configuration!" % name)
128 variable_config = study_config[name]
129 if "Order" not in variable_config.keys():
130 logging.fatal("Order not found in the %s configuration!" % name)
133 list_of_variables = variable_config["Order"]
134 if not isinstance(list_of_variables, type([])):
135 logging.fatal("Order sould be a list in the %s configuration!" % name)
137 if len(list_of_variables) < 1:
138 logging.fatal("Order should contain one or more names in the %s configuration!" % name)
141 for var in list_of_variables:
142 if var not in variable_config.keys():
143 logging.fatal("Variable %s not found in the %s configuration!" % name)
145 value = variable_config[var]
149 loggind.fatal("Variable %s value cannot be converted in an integer in the %s configuration!" % name)
152 def check_data(data_name, data_config, repertory_check=False, repertory=""):
154 logging.debug("[check_data] " + data_name)
155 data_name_data = "Data"
156 data_name_type = "Type"
157 data_name_from = "From"
159 if data_name_data not in data_config:
160 logging.fatal(data_name +" found but " + data_name_data +" is not defined in the study configuration !")
163 if data_name_type not in data_config:
164 logging.fatal(data_name +" found but " + data_name_type +" is not defined in the study configuration !")
167 if data_config[data_name_type] not in AssimType[data_name]:
168 logging.fatal(data_name_type + " defined in the study configuration does not have a correct type : " + str(data_config[data_name_type])
169 + "\n You can have : " + str(AssimType[data_name]))
171 if data_name_from not in data_config:
172 logging.fatal(data_name + " found but " + data_name_from + " is not defined in the study configuration !")
175 if data_config[data_name_from] not in FromNumpyList[data_config[data_name_type]]:
176 logging.fatal(data_name_from + " defined in the study configuration does not have a correct value : " + str(data_config[data_name_from])
177 + "\n You can have : " + str(FromNumpyList[data_config[data_name_type]]))
181 from_type = data_config["From"]
182 if from_type == "Script":
185 check_file_name = os.path.join(repertory, os.path.basename(data_config["Data"]))
187 check_file_name = data_config["Data"]
188 if not os.path.exists(check_file_name):
189 logging.fatal("A script file cannot be found")
190 logging.fatal("File is %s" % check_file_name)
192 elif from_type == "FunctionDict":
193 FunctionDict = data_config["Data"]
194 for FunctionName in FunctionDict["Function"]:
197 check_file_name = os.path.join(repertory, os.path.basename(FunctionDict["Script"][FunctionName]))
199 check_file_name = FunctionDict["Script"][FunctionName]
200 if not os.path.exists(check_file_name):
201 logging.fatal("A script file cannot be found")
202 logging.fatal("File is %s" % check_file_name)