1 # -*- coding: utf-8 -*-
2 print "import generator_adao"
4 from generator.generator_python import PythonGenerator
10 Retourne les informations necessaires pour le chargeur de plugins
12 Ces informations sont retournees dans un dictionnaire
17 # La factory pour creer une instance du plugin
18 'factory' : AdaoGenerator,
21 class AdaoGenerator(PythonGenerator):
23 def __init__(self,cr=None):
24 PythonGenerator.__init__(self, cr)
28 self.text_da_status = False
29 self.logger = logging.getLogger('ADAO EFICAS GENERATOR')
30 self.logger.setLevel(logging.DEBUG)
31 ch = logging.StreamHandler()
32 ch.setLevel(logging.DEBUG)
33 formatter = logging.Formatter("%(name)s - %(levelname)s - %(message)s")
34 ch.setFormatter(formatter)
35 self.logger.addHandler(ch)
37 def gener(self,obj,format='brut',config=None):
38 self.logger.debug("method gener called")
39 self.text_comm = PythonGenerator.gener(self, obj, format, config)
40 for key, value in self.dictMCVal.iteritems():
41 self.logger.debug("dictMCVAl %s %s" % (key,value))
44 self.text_da_status = False
46 self.text_da_status = True
48 self.logger.info("Case is not correct, python command file for YACS schema generation cannot be created")
49 self.logger.debug(self.text_da)
54 def writeDefault(self, fn):
55 if self.text_da_status:
56 print "write adao python command file"
57 filename = fn[:fn.rfind(".")] + '.py'
58 f = open( str(filename), 'wb')
59 f.write( self.text_da )
62 def generMCSIMP(self,obj) :
64 Convertit un objet MCSIMP en texte python
67 for i in obj.get_genealogie() :
69 print obj.get_genealogie()
71 self.dictMCVal[clef]=obj.valeur
73 s=PythonGenerator.generMCSIMP(self,obj)
76 def generate_da(self):
78 self.text_da += "#-*-coding:iso-8859-1-*- \n"
79 self.text_da += "study_config = {} \n"
81 # Extraction de Study_name
82 self.text_da += "study_config[\"Name\"] = \"" + self.dictMCVal["__ASSIMILATION_STUDY__Study_name"] + "\"\n"
84 self.text_da += "study_config[\"Debug\"] = \"" + str(self.dictMCVal["__ASSIMILATION_STUDY__Debug"]) + "\"\n"
85 # Extraction de Algorithm
86 self.text_da += "study_config[\"Algorithm\"] = \"" + self.dictMCVal["__ASSIMILATION_STUDY__Algorithm"] + "\"\n"
88 self.add_data("Background")
89 self.add_data("BackgroundError")
90 self.add_data("Observation")
91 self.add_data("ObservationError")
92 self.add_data("ObservationOperator")
95 # Parametres optionnels
97 # Extraction du Study_repertory
98 if "__ASSIMILATION_STUDY__Study_repertory" in self.dictMCVal.keys():
99 self.text_da += "study_config[\"Repertory\"] = \"" + self.dictMCVal["__ASSIMILATION_STUDY__Study_repertory"] + "\"\n"
100 # Extraction de AlgorithmParameters
101 if "__ASSIMILATION_STUDY__AlgorithmParameters__INPUT_TYPE" in self.dictMCVal.keys():
102 self.add_algorithm_parameters()
103 # Extraction de UserPostAnalysis
104 if "__ASSIMILATION_STUDY__UserPostAnalysis__FROM" in self.dictMCVal.keys():
105 self.add_UserPostAnalysis()
106 if "__ASSIMILATION_STUDY__UserDataInit__INIT_FILE" in self.dictMCVal.keys():
109 def add_data(self, data_name):
111 # Extraction des données
112 search_text = "__ASSIMILATION_STUDY__" + data_name + "__"
113 data_type = self.dictMCVal[search_text + "INPUT_TYPE"]
114 search_type = search_text + data_type + "__data__"
115 from_type = self.dictMCVal[search_type + "FROM"]
117 if from_type == "String":
118 data = self.dictMCVal[search_type + "STRING_DATA__STRING"]
119 elif from_type == "Script":
120 data = self.dictMCVal[search_type + "SCRIPT_DATA__SCRIPT_FILE"]
121 elif from_type == "FunctionDict":
122 data = self.dictMCVal[search_type + "FUNCTIONDICT_DATA__FUNCTIONDICT_FILE"]
124 raise Exception('From Type unknown', from_type)
126 if from_type == "String" or from_type == "Script":
127 self.text_da += data_name + "_config = {} \n"
128 self.text_da += data_name + "_config[\"Type\"] = \"" + data_type + "\" \n"
129 self.text_da += data_name + "_config[\"From\"] = \"" + from_type + "\" \n"
130 self.text_da += data_name + "_config[\"Data\"] = \"" + data + "\" \n"
131 self.text_da += "study_config[\"" + data_name + "\"] = " + data_name + "_config \n"
133 if from_type == "FunctionDict":
134 self.text_da += data_name + "_FunctionDict = {} \n"
135 self.text_da += data_name + "_FunctionDict[\"Function\"] = [\"Direct\", \"Tangent\", \"Adjoint\"] \n"
136 self.text_da += data_name + "_FunctionDict[\"Script\"] = {} \n"
137 self.text_da += data_name + "_FunctionDict[\"Script\"][\"Direct\"] = \"" + data + "\" \n"
138 self.text_da += data_name + "_FunctionDict[\"Script\"][\"Tangent\"] = \"" + data + "\" \n"
139 self.text_da += data_name + "_FunctionDict[\"Script\"][\"Adjoint\"] = \"" + data + "\" \n"
140 self.text_da += data_name + "_config = {} \n"
141 self.text_da += data_name + "_config[\"Type\"] = \"Function\" \n"
142 self.text_da += data_name + "_config[\"From\"] = \"FunctionDict\" \n"
143 self.text_da += data_name + "_config[\"Data\"] = " + data_name + "_FunctionDict \n"
144 self.text_da += "study_config[\"" + data_name + "\"] = " + data_name + "_config \n"
146 def add_algorithm_parameters(self):
148 data_name = "AlgorithmParameters"
151 data = self.dictMCVal["__ASSIMILATION_STUDY__AlgorithmParameters__Dict__data__SCRIPT_DATA__SCRIPT_FILE"]
153 self.text_da += data_name + "_config = {} \n"
154 self.text_da += data_name + "_config[\"Type\"] = \"" + data_type + "\" \n"
155 self.text_da += data_name + "_config[\"From\"] = \"" + from_type + "\" \n"
156 self.text_da += data_name + "_config[\"Data\"] = \"" + data + "\" \n"
157 self.text_da += "study_config[\"" + data_name + "\"] = " + data_name + "_config \n"
161 init_file_data = self.dictMCVal["__ASSIMILATION_STUDY__UserDataInit__INIT_FILE"]
162 init_target_list = self.dictMCVal["__ASSIMILATION_STUDY__UserDataInit__TARGET_LIST"]
164 self.text_da += "Init_config = {} \n"
165 self.text_da += "Init_config[\"Type\"] = \"Dict\" \n"
166 self.text_da += "Init_config[\"From\"] = \"Script\" \n"
167 self.text_da += "Init_config[\"Data\"] = \"" + init_file_data + "\"\n"
168 self.text_da += "Init_config[\"Target\"] = ["
169 for target in init_target_list:
170 self.text_da += "\"" + target + "\","
171 self.text_da += "] \n"
172 self.text_da += "study_config[\"UserDataInit\"] = Init_config \n"
174 def add_UserPostAnalysis(self):
176 from_type = self.dictMCVal["__ASSIMILATION_STUDY__UserPostAnalysis__FROM"]
178 if from_type == "String":
179 data = self.dictMCVal["__ASSIMILATION_STUDY__UserPostAnalysis__STRING_DATA__STRING"]
180 self.text_da += "Analysis_config = {} \n"
181 self.text_da += "Analysis_config[\"From\"] = \"String\" \n"
182 self.text_da += "Analysis_config[\"Data\"] = \"\"\"" + data + "\"\"\" \n"
183 self.text_da += "study_config[\"UserPostAnalysis\"] = Analysis_config \n"
184 elif from_type == "Script":
185 data = self.dictMCVal["__ASSIMILATION_STUDY__UserPostAnalysis__SCRIPT_DATA__SCRIPT_FILE"]
186 self.text_da += "Analysis_config = {} \n"
187 self.text_da += "Analysis_config[\"From\"] = \"Script\" \n"
188 self.text_da += "Analysis_config[\"Data\"] = \"" + data + "\" \n"
189 self.text_da += "study_config[\"UserPostAnalysis\"] = Analysis_config \n"
191 raise Exception('From Type unknown', from_type)
193 def add_variables(self):
196 if "__ASSIMILATION_STUDY__InputVariables__NAMES" in self.dictMCVal.keys():
199 if isinstance(self.dictMCVal["__ASSIMILATION_STUDY__InputVariables__NAMES"], type("")):
200 names.append(self.dictMCVal["__ASSIMILATION_STUDY__InputVariables__NAMES"])
202 names = self.dictMCVal["__ASSIMILATION_STUDY__InputVariables__NAMES"]
203 if isinstance(self.dictMCVal["__ASSIMILATION_STUDY__InputVariables__SIZES"], type(1)):
204 sizes.append(self.dictMCVal["__ASSIMILATION_STUDY__InputVariables__SIZES"])
206 sizes = self.dictMCVal["__ASSIMILATION_STUDY__InputVariables__SIZES"]
208 self.text_da += "inputvariables_config = {} \n"
209 for name, size in zip(names, sizes):
210 self.text_da += "inputvariables_config[\"%s\"] = %s \n" % (name,size)
211 self.text_da += "study_config[\"InputVariables\"] = inputvariables_config \n"
213 self.text_da += "inputvariables_config = {} \n"
214 self.text_da += "inputvariables_config[\"adao_default\"] = -1 \n"
215 self.text_da += "study_config[\"InputVariables\"] = inputvariables_config \n"
218 if "__ASSIMILATION_STUDY__OutputVariables__NAMES" in self.dictMCVal.keys():
221 if isinstance(self.dictMCVal["__ASSIMILATION_STUDY__OutputVariables__NAMES"], type("")):
222 names.append(self.dictMCVal["__ASSIMILATION_STUDY__OutputVariables__NAMES"])
224 names = self.dictMCVal["__ASSIMILATION_STUDY__OutputVariables__NAMES"]
225 if isinstance(self.dictMCVal["__ASSIMILATION_STUDY__OutputVariables__SIZES"], type(1)):
226 sizes.append(self.dictMCVal["__ASSIMILATION_STUDY__OutputVariables__SIZES"])
228 sizes = self.dictMCVal["__ASSIMILATION_STUDY__OutputVariables__SIZES"]
230 self.text_da += "outputvariables_config = {} \n"
231 for name, size in zip(names, sizes):
232 self.text_da += "outputvariables_config[\"%s\"] = %s \n" % (name,size)
233 self.text_da += "study_config[\"OutputVariables\"] = outputvariables_config \n"
235 self.text_da += "variables_config = {} \n"
236 self.text_da += "outputvariables_config[\"adao_default\"] = -1 \n"
237 self.text_da += "study_config[\"OutputVariables\"] = ouputvariables_config \n"