1 # -*- coding: utf-8 -*-
2 print "import generator_adao"
4 from generator.generator_python import PythonGenerator
8 Retourne les informations necessaires pour le chargeur de plugins
10 Ces informations sont retournees dans un dictionnaire
15 # La factory pour creer une instance du plugin
16 'factory' : AdaoGenerator,
19 class AdaoGenerator(PythonGenerator):
21 def __init__(self,cr=None):
22 PythonGenerator.__init__(self, cr)
26 self.text_da_status = False
28 def gener(self,obj,format='brut',config=None):
29 print "AdaoGenerator gener"
30 self.text_comm = PythonGenerator.gener(self, obj, format, config)
36 self.text_da_status = False
38 self.text_da_status = True
40 print "Case seems not be correct"
44 def writeDefault(self, fn):
45 if self.text_da_status:
46 print "write adao python command file"
47 filename = fn[:fn.rfind(".")] + '.py'
48 f = open( str(filename), 'wb')
49 f.write( self.text_da )
52 def generMCSIMP(self,obj) :
54 Convertit un objet MCSIMP en texte python
57 for i in obj.get_genealogie() :
59 self.dictMCVal[clef]=obj.valeur
61 s=PythonGenerator.generMCSIMP(self,obj)
64 def generMCFACT(self,obj):
66 if obj.parent.nom == "ALGORITHM":
67 self.dictMCVal["ALGORITHM_NAME"] = obj.nom
69 s=PythonGenerator.generMCFACT(self,obj)
72 def generate_da(self):
74 self.text_da += "#-*-coding:iso-8859-1-*- \n"
75 self.text_da += "study_config = {} \n"
76 self.text_da += "study_config[\"Name\"] = \"" + self.dictMCVal["__ASSIM_STUDY__STUDY_NAME"] + "\"\n"
77 self.text_da += "study_config[\"Algorithm\"] = \"" + self.dictMCVal["ALGORITHM_NAME"] + "\"\n"
80 self.add_data("Background")
81 self.add_data("BackgroundError")
82 self.add_data("Observation")
83 self.add_data("ObservationError")
84 self.add_data("ObservationOperator")
89 def add_data(self, data_name):
90 search_text = "__ASSIM_STUDY__ALGORITHM__" + self.dictMCVal["ALGORITHM_NAME"] + "__"
91 back_search_text = search_text + data_name + "__"
94 search_vector = back_search_text + "Vector"
95 if search_vector + "__FROM" in self.dictMCVal:
96 back_from = self.dictMCVal[search_vector + "__FROM"]
98 search_string = search_vector + "__STRING_DATA__STRING"
99 search_script = search_vector + "__SCRIPT_DATA__SCRIPT_FILE"
101 # Vector is from a string
102 if search_string in self.dictMCVal:
103 back_data = self.dictMCVal[search_string]
104 # Vector is from a script
105 elif search_script in self.dictMCVal:
106 back_data = self.dictMCVal[search_script]
108 print "[generator adao] Error cannot found Vector data"
110 self.text_da += data_name + "_config = {} \n"
111 self.text_da += data_name + "_config[\"Type\"] = \"Vector\" \n"
112 self.text_da += data_name + "_config[\"From\"] = \"" + back_from + "\" \n"
113 self.text_da += data_name + "_config[\"Data\"] = \"" + back_data + "\" \n"
114 self.text_da += "study_config[\"" + data_name + "\"] = " + data_name + "_config \n"
118 search_matrix = back_search_text + "Matrix"
119 if search_matrix + "__FROM" in self.dictMCVal:
120 back_from = self.dictMCVal[search_matrix + "__FROM"]
122 search_string = search_matrix + "__STRING_DATA__STRING"
123 search_script = search_matrix + "__SCRIPT_DATA__SCRIPT_FILE"
125 # Matrix is from a string
126 if search_string in self.dictMCVal:
127 back_data = self.dictMCVal[search_string]
128 # Matrix is from a script
129 elif search_script in self.dictMCVal:
130 back_data = self.dictMCVal[search_script]
132 print "[generator adao] Error cannot found Matrix data"
134 self.text_da += data_name + "_config = {} \n"
135 self.text_da += data_name + "_config[\"Type\"] = \"Matrix\" \n"
136 self.text_da += data_name + "_config[\"From\"] = \"" + back_from + "\" \n"
137 self.text_da += data_name + "_config[\"Data\"] = \"" + back_data + "\" \n"
138 self.text_da += "study_config[\"" + data_name + "\"] = " + data_name + "_config \n"
141 def add_analysis(self):
142 search_text = "__ASSIM_STUDY__ALGORITHM__" + self.dictMCVal["ALGORITHM_NAME"] + "__Analysis__"
144 ana_from = self.dictMCVal[search_text + "FROM"]
146 if ana_from == "String":
147 ana_data = self.dictMCVal[search_text + "STRING_DATA__STRING"]
148 self.text_da += "Analysis_config = {} \n"
149 self.text_da += "Analysis_config[\"From\"] = \"String\" \n"
150 self.text_da += "Analysis_config[\"Data\"] = \"\"\"" + ana_data + "\"\"\" \n"
151 self.text_da += "study_config[\"Analysis\"] = Analysis_config \n"
153 if ana_from == "Script":
154 ana_data = self.dictMCVal[search_text + "SCRIPT_DATA__SCRIPT_FILE"]
155 self.text_da += "Analysis_config = {} \n"
156 self.text_da += "Analysis_config[\"From\"] = \"Script\" \n"
157 self.text_da += "Analysis_config[\"Data\"] = \"" + ana_data + "\" \n"
158 self.text_da += "study_config[\"Analysis\"] = Analysis_config \n"