]> SALOME platform Git repositories - modules/adao.git/blob - src/daSalome/daYacsSchemaCreator/help_methods.py
Salome HOME
Le cas ASTER est de nouveau ok
[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   # Debug
60   if "Debug" not in study_config:
61     study_config["Debug"] = "0"
62
63   # Check if all the data is provided
64   for key in AlgoDataRequirements[study_config["Algorithm"]]:
65     if key not in study_config.keys():
66       logging.fatal("Cannot found " +  key + " in your study configuration !" +
67                     "\n This key is mandatory into a study with " + study_config["Algorithm"] + " algorithm." +
68                     "\n " + study_config["Algorithm"] + " requirements are " + str(AlgoDataRequirements[study_config["Algorithm"]]))
69       sys.exit(1)
70
71   # Data
72   for key in study_config.keys():
73     if key in AssimData:
74       check_data(key, study_config[key])
75
76   # Analyse
77   if "UserPostAnalysis" in study_config.keys():
78     analysis_config = study_config["UserPostAnalysis"]
79     if "From" not in analysis_config:
80       logging.fatal("UserPostAnalysis found but From is not defined in the analysis configuration !")
81       sys.exit(1)
82     else:
83       if analysis_config["From"] not in AnalysisFromList:
84         logging.fatal("Analysis From defined in the study configuration does not have a correct type : " + str(analysis_config["From"])
85                       + "\n You can have : " + str(AnalysisFromList))
86         sys.exit(1)
87     if "Data" not in analysis_config:
88       logging.fatal("Analysis found but Data is not defined in the analysis configuration !")
89       sys.exit(1)
90
91
92 def check_data(data_name, data_config):
93
94   logging.debug("[check_data] " + data_name)
95   data_name_data = "Data"
96   data_name_type = "Type"
97   data_name_from = "From"
98
99   if data_name_data not in data_config:
100     logging.fatal(data_name +" found but " + data_name_data +" is not defined in the study configuration !")
101     sys.exit(1)
102
103   if data_name_type not in data_config:
104     logging.fatal(data_name +" found but " + data_name_type  +" is not defined in the study configuration !")
105     sys.exit(1)
106   else:
107     if data_config[data_name_type] not in AssimType[data_name]:
108       logging.fatal(data_name_type + " defined in the study configuration does not have a correct type : " + str(data_config[data_name_type]) 
109                     + "\n You can have : " + str(AssimType[data_name]))
110       sys.exit(1)
111   if data_name_from not in data_config:
112     logging.fatal(data_name + " found but " + data_name_from + " is not defined in the study configuration !")
113     sys.exit(1)
114   else:
115     if data_config[data_name_from] not in FromNumpyList[data_config[data_name_type]]:
116       logging.fatal(data_name_from + " defined in the study configuration does not have a correct value : " + str(data_config[data_name_from]) 
117                     + "\n You can have : " + str(FromNumpyList[data_config[data_name_type]]))
118       sys.exit(1)
119