]> SALOME platform Git repositories - modules/adao.git/blob - src/daSalome/daYacsSchemaCreator/help_methods.py
Salome HOME
Study repertory - 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 os
24 import traceback
25 import logging
26
27 from daYacsSchemaCreator.infos_daComposant import *
28
29 def check_args(args):
30
31   logging.debug("Arguments are :" + str(args))
32   if len(args) != 2:
33     logging.fatal("Bad number of arguments: you have to provide two arguments (%d given)" % (len(args)))
34     sys.exit(1)
35
36 def check_study(study_config):
37
38   logging.debug("[check_env] study_config : " + str(study_config))
39
40   # Check study_config
41   if not isinstance(study_config, dict):
42     logging.fatal("Study configuration is not a dictionnary")
43     sys.exit(1)
44
45   # Name
46   if "Name" not in study_config:
47     logging.fatal("Cannot found Name in the study configuration")
48     sys.exit(1)
49
50   # Algorithm
51   if "Algorithm" not in study_config:
52     logging.fatal("Cannot found Algorithm in the study configuration")
53     sys.exit(1)
54   else:
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))
58       sys.exit(1)
59
60   # Debug
61   if "Debug" not in study_config:
62     study_config["Debug"] = "0"
63
64   # Repertory
65   check_repertory = False
66   repertory = ""
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)
73       sys.exit(1)
74
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"]]))
81       sys.exit(1)
82
83   # Data
84   for key in study_config.keys():
85     if key in AssimData:
86       check_data(key, study_config[key], check_repertory, repertory)
87
88   # UserDataInit
89   if "UserDataInit" in study_config.keys():
90     check_data("UserDataInit", study_config["UserDataInit"], check_repertory, repertory)
91
92   # Analyse
93   if "UserPostAnalysis" in study_config.keys():
94     analysis_config = study_config["UserPostAnalysis"]
95     if "From" not in analysis_config:
96       logging.fatal("UserPostAnalysis found but From is not defined in the analysis configuration !")
97       sys.exit(1)
98     else:
99       if analysis_config["From"] not in AnalysisFromList:
100         logging.fatal("Analysis From defined in the study configuration does not have a correct type : " + str(analysis_config["From"])
101                       + "\n You can have : " + str(AnalysisFromList))
102         sys.exit(1)
103     if "Data" not in analysis_config:
104       logging.fatal("Analysis found but Data is not defined in the analysis configuration !")
105       sys.exit(1)
106
107     if analysis_config["From"] == "Script":
108       check_file_name = ""
109       if repertory_check:
110         check_file_name = os.path.join(repertory, os.path.basename(analysis_config["Data"]))
111       else:
112         check_file_name = analysis_config["Data"]
113       if not os.path.exists(check_file_name):
114         logging.fatal("A script file cannot be found")
115         logging.fatal("File is %s" % check_file_name)
116         sys.exit(1)
117
118 def check_data(data_name, data_config, repertory_check=False, repertory=""):
119
120   logging.debug("[check_data] " + data_name)
121   data_name_data = "Data"
122   data_name_type = "Type"
123   data_name_from = "From"
124
125   if data_name_data not in data_config:
126     logging.fatal(data_name +" found but " + data_name_data +" is not defined in the study configuration !")
127     sys.exit(1)
128
129   if data_name_type not in data_config:
130     logging.fatal(data_name +" found but " + data_name_type  +" is not defined in the study configuration !")
131     sys.exit(1)
132   else:
133     if data_config[data_name_type] not in AssimType[data_name]:
134       logging.fatal(data_name_type + " defined in the study configuration does not have a correct type : " + str(data_config[data_name_type]) 
135                     + "\n You can have : " + str(AssimType[data_name]))
136       sys.exit(1)
137   if data_name_from not in data_config:
138     logging.fatal(data_name + " found but " + data_name_from + " is not defined in the study configuration !")
139     sys.exit(1)
140   else:
141     if data_config[data_name_from] not in FromNumpyList[data_config[data_name_type]]:
142       logging.fatal(data_name_from + " defined in the study configuration does not have a correct value : " + str(data_config[data_name_from]) 
143                     + "\n You can have : " + str(FromNumpyList[data_config[data_name_type]]))
144       sys.exit(1)
145
146   # Check des fichiers
147   from_type = data_config["From"]
148   if from_type == "Script":
149     check_file_name = ""
150     if repertory_check:
151       check_file_name = os.path.join(repertory, os.path.basename(data_config["Data"]))
152     else:
153       check_file_name = data_config["Data"]
154     if not os.path.exists(check_file_name):
155       logging.fatal("A script file cannot be found")
156       logging.fatal("File is %s" % check_file_name)
157       sys.exit(1)
158   elif from_type == "FunctionDict":
159     FunctionDict = data_config["Data"]
160     for FunctionName in FunctionDict["Function"]:
161       check_file_name = ""
162       if repertory_check:
163         check_file_name = os.path.join(repertory, os.path.basename(FunctionDict["Script"][FunctionName]))
164       else:
165         check_file_name = FunctionDict["Script"][FunctionName]
166       if not os.path.exists(check_file_name):
167         logging.fatal("A script file cannot be found")
168         logging.fatal("File is %s" % check_file_name)
169         sys.exit(1)