Salome HOME
- Patch pour les changements sur EficasV1
[modules/adao.git] / src / daSalome / daYacsSchemaCreator / help_methods.py
1 #-*- coding: utf-8 -*-
2 #  Copyright (C) 2010 EDF R&D
3 #
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.
8 #
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.
13 #
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
17 #
18 # --
19 # Author : AndrĂ© RIBES (EDF R&D)
20 # --
21
22 import sys
23 import traceback
24 import logging
25
26 from daYacsSchemaCreator.infos_daComposant import *
27
28 def check_args(args):
29
30   logging.debug("Arguments are :" + str(args))
31   if len(args) != 2:
32     logging.fatal("Bad number of arguments: you have to provide two arguments (%d given)" % (len(args)))
33     sys.exit(1)
34
35 def check_study(study_config):
36
37   logging.debug("[check_env] study_config : " + str(study_config))
38
39   # Check study_config
40   if not isinstance(study_config, dict):
41     logging.fatal("Study configuration is not a dictionnary")
42     sys.exit(1)
43   
44   # Name
45   if "Name" not in study_config:
46     logging.fatal("Cannot found Name in the study configuration")
47     sys.exit(1)
48
49   # Algorithm
50   if "Algorithm" not in study_config:
51     logging.fatal("Cannot found Algorithm in the study configuration")
52     sys.exit(1)
53   else:
54     if study_config["Algorithm"] not in AssimAlgos:
55       logging.fatal("Algorithm provided is unknow : " + str(study_config["Algorithm"]) +
56                     "\n You can choose between : " + str(AssimAlgos))
57       sys.exit(1)
58
59   # Check if all the data is provided
60   for key in AlgoDataRequirements[study_config["Algorithm"]]:
61     if key not in study_config.keys():
62       logging.fatal("Cannot found " +  key + " in your study configuration !" +
63                     "\n This key is mandatory into a study with " + study_config["Algorithm"] + " algorithm." +
64                     "\n " + study_config["Algorithm"] + " requirements are " + str(AlgoDataRequirements[study_config["Algorithm"]]))
65       sys.exit(1)
66
67   # Data
68   for key in study_config.keys():
69     if key in AssimData:
70       check_data(key, study_config[key])
71
72   # Analyse
73   if "Analysis" in study_config.keys():
74     analysis_config = study_config["Analysis"]
75     if "From" not in analysis_config:
76       logging.fatal("Analysis found but From is not defined in the analysis configuration !")
77       sys.exit(1)
78     else:
79       if analysis_config["From"] not in AnalysisFromList:
80         logging.fatal("Analysis From defined in the study configuration does not have a correct type : " + str(analysis_config["From"])
81                       + "\n You can have : " + str(AnalysisFromList))
82         sys.exit(1)
83     if "Data" not in analysis_config:
84       logging.fatal("Analysis found but Data is not defined in the analysis configuration !")
85       sys.exit(1)
86
87
88 def check_data(data_name, data_config):
89
90   logging.debug("[check_data] " + data_name)
91   data_name_data = "Data"
92   data_name_type = "Type"
93   data_name_from = "From"
94
95   if data_name_data not in data_config:
96     logging.fatal(data_name +" found but " + data_name_data +" is not defined in the study configuration !")
97     sys.exit(1)
98
99   if data_name_type not in data_config:
100     logging.fatal(data_name +" found but " + data_name_type  +" is not defined in the study configuration !")
101     sys.exit(1)
102   else:
103     if data_config[data_name_type] not in AssimType[data_name]:
104       logging.fatal(data_name_type + " defined in the study configuration does not have a correct type : " + str(data_config[data_name_type]) 
105                     + "\n You can have : " + str(AssimType[data_name]))
106       sys.exit(1)
107   if data_name_from not in data_config:
108     logging.fatal(data_name + " found but " + data_name_from + " is not defined in the study configuration !")
109     sys.exit(1)
110   else:
111     if data_config[data_name_from] not in FromNumpyList[data_config[data_name_type]]:
112       logging.fatal(data_name_from + " defined in the study configuration does not have a correct value : " + str(data_config[data_name_from]) 
113                     + "\n You can have : " + str(FromNumpyList[data_config[data_name_type]]))
114       sys.exit(1)
115