@@ -1,1252 +1,1263 | |||||
1 | ''' |
|
1 | ''' | |
2 | Created on September , 2012 |
|
2 | Created on September , 2012 | |
3 | @author: |
|
3 | @author: | |
4 | ''' |
|
4 | ''' | |
5 |
|
5 | |||
6 | import sys |
|
6 | import sys | |
7 | import ast |
|
7 | import ast | |
8 | import datetime |
|
8 | import datetime | |
9 | import traceback |
|
9 | import traceback | |
10 | import schainpy |
|
10 | import schainpy | |
11 | import schainpy.admin |
|
11 | import schainpy.admin | |
12 |
|
12 | |||
13 | from xml.etree.ElementTree import ElementTree, Element, SubElement, tostring |
|
13 | from xml.etree.ElementTree import ElementTree, Element, SubElement, tostring | |
14 | from xml.dom import minidom |
|
14 | from xml.dom import minidom | |
15 |
|
15 | |||
16 | from schainpy.model import * |
|
16 | from schainpy.model import * | |
17 | from time import sleep |
|
17 | from time import sleep | |
18 |
|
18 | |||
19 | def prettify(elem): |
|
19 | def prettify(elem): | |
20 | """Return a pretty-printed XML string for the Element. |
|
20 | """Return a pretty-printed XML string for the Element. | |
21 | """ |
|
21 | """ | |
22 | rough_string = tostring(elem, 'utf-8') |
|
22 | rough_string = tostring(elem, 'utf-8') | |
23 | reparsed = minidom.parseString(rough_string) |
|
23 | reparsed = minidom.parseString(rough_string) | |
24 | return reparsed.toprettyxml(indent=" ") |
|
24 | return reparsed.toprettyxml(indent=" ") | |
25 |
|
25 | |||
26 | class ParameterConf(): |
|
26 | class ParameterConf(): | |
27 |
|
27 | |||
28 | id = None |
|
28 | id = None | |
29 | name = None |
|
29 | name = None | |
30 | value = None |
|
30 | value = None | |
31 | format = None |
|
31 | format = None | |
32 |
|
32 | |||
33 | __formated_value = None |
|
33 | __formated_value = None | |
34 |
|
34 | |||
35 | ELEMENTNAME = 'Parameter' |
|
35 | ELEMENTNAME = 'Parameter' | |
36 |
|
36 | |||
37 | def __init__(self): |
|
37 | def __init__(self): | |
38 |
|
38 | |||
39 | self.format = 'str' |
|
39 | self.format = 'str' | |
40 |
|
40 | |||
41 | def getElementName(self): |
|
41 | def getElementName(self): | |
42 |
|
42 | |||
43 | return self.ELEMENTNAME |
|
43 | return self.ELEMENTNAME | |
44 |
|
44 | |||
45 | def getValue(self): |
|
45 | def getValue(self): | |
46 |
|
46 | |||
47 | value = self.value |
|
47 | value = self.value | |
48 | format = self.format |
|
48 | format = self.format | |
49 |
|
49 | |||
50 | if self.__formated_value != None: |
|
50 | if self.__formated_value != None: | |
51 |
|
51 | |||
52 | return self.__formated_value |
|
52 | return self.__formated_value | |
53 |
|
53 | |||
54 | if format == 'str': |
|
54 | if format == 'str': | |
55 | self.__formated_value = str(value) |
|
55 | self.__formated_value = str(value) | |
56 | return self.__formated_value |
|
56 | return self.__formated_value | |
57 |
|
57 | |||
58 | if value == '': |
|
58 | if value == '': | |
59 | raise ValueError, "%s: This parameter value is empty" %self.name |
|
59 | raise ValueError, "%s: This parameter value is empty" %self.name | |
60 |
|
60 | |||
61 | if format == 'list': |
|
61 | if format == 'list': | |
62 | strList = value.split(',') |
|
62 | strList = value.split(',') | |
63 |
|
63 | |||
64 | self.__formated_value = strList |
|
64 | self.__formated_value = strList | |
65 |
|
65 | |||
66 | return self.__formated_value |
|
66 | return self.__formated_value | |
67 |
|
67 | |||
68 | if format == 'intlist': |
|
68 | if format == 'intlist': | |
69 | """ |
|
69 | """ | |
70 | Example: |
|
70 | Example: | |
71 | value = (0,1,2) |
|
71 | value = (0,1,2) | |
72 | """ |
|
72 | """ | |
73 | value = value.replace('(', '') |
|
73 | value = value.replace('(', '') | |
74 | value = value.replace(')', '') |
|
74 | value = value.replace(')', '') | |
75 |
|
75 | |||
76 | value = value.replace('[', '') |
|
76 | value = value.replace('[', '') | |
77 | value = value.replace(']', '') |
|
77 | value = value.replace(']', '') | |
78 |
|
78 | |||
79 | strList = value.split(',') |
|
79 | strList = value.split(',') | |
80 | intList = [int(float(x)) for x in strList] |
|
80 | intList = [int(float(x)) for x in strList] | |
81 |
|
81 | |||
82 | self.__formated_value = intList |
|
82 | self.__formated_value = intList | |
83 |
|
83 | |||
84 | return self.__formated_value |
|
84 | return self.__formated_value | |
85 |
|
85 | |||
86 | if format == 'floatlist': |
|
86 | if format == 'floatlist': | |
87 | """ |
|
87 | """ | |
88 | Example: |
|
88 | Example: | |
89 | value = (0.5, 1.4, 2.7) |
|
89 | value = (0.5, 1.4, 2.7) | |
90 | """ |
|
90 | """ | |
91 |
|
91 | |||
92 | value = value.replace('(', '') |
|
92 | value = value.replace('(', '') | |
93 | value = value.replace(')', '') |
|
93 | value = value.replace(')', '') | |
94 |
|
94 | |||
95 | value = value.replace('[', '') |
|
95 | value = value.replace('[', '') | |
96 | value = value.replace(']', '') |
|
96 | value = value.replace(']', '') | |
97 |
|
97 | |||
98 | strList = value.split(',') |
|
98 | strList = value.split(',') | |
99 | floatList = [float(x) for x in strList] |
|
99 | floatList = [float(x) for x in strList] | |
100 |
|
100 | |||
101 | self.__formated_value = floatList |
|
101 | self.__formated_value = floatList | |
102 |
|
102 | |||
103 | return self.__formated_value |
|
103 | return self.__formated_value | |
104 |
|
104 | |||
105 | if format == 'date': |
|
105 | if format == 'date': | |
106 | strList = value.split('/') |
|
106 | strList = value.split('/') | |
107 | intList = [int(x) for x in strList] |
|
107 | intList = [int(x) for x in strList] | |
108 | date = datetime.date(intList[0], intList[1], intList[2]) |
|
108 | date = datetime.date(intList[0], intList[1], intList[2]) | |
109 |
|
109 | |||
110 | self.__formated_value = date |
|
110 | self.__formated_value = date | |
111 |
|
111 | |||
112 | return self.__formated_value |
|
112 | return self.__formated_value | |
113 |
|
113 | |||
114 | if format == 'time': |
|
114 | if format == 'time': | |
115 | strList = value.split(':') |
|
115 | strList = value.split(':') | |
116 | intList = [int(x) for x in strList] |
|
116 | intList = [int(x) for x in strList] | |
117 | time = datetime.time(intList[0], intList[1], intList[2]) |
|
117 | time = datetime.time(intList[0], intList[1], intList[2]) | |
118 |
|
118 | |||
119 | self.__formated_value = time |
|
119 | self.__formated_value = time | |
120 |
|
120 | |||
121 | return self.__formated_value |
|
121 | return self.__formated_value | |
122 |
|
122 | |||
123 | if format == 'pairslist': |
|
123 | if format == 'pairslist': | |
124 | """ |
|
124 | """ | |
125 | Example: |
|
125 | Example: | |
126 | value = (0,1),(1,2) |
|
126 | value = (0,1),(1,2) | |
127 | """ |
|
127 | """ | |
128 |
|
128 | |||
129 | value = value.replace('(', '') |
|
129 | value = value.replace('(', '') | |
130 | value = value.replace(')', '') |
|
130 | value = value.replace(')', '') | |
131 |
|
131 | |||
132 | value = value.replace('[', '') |
|
132 | value = value.replace('[', '') | |
133 | value = value.replace(']', '') |
|
133 | value = value.replace(']', '') | |
134 |
|
134 | |||
135 | strList = value.split(',') |
|
135 | strList = value.split(',') | |
136 | intList = [int(item) for item in strList] |
|
136 | intList = [int(item) for item in strList] | |
137 | pairList = [] |
|
137 | pairList = [] | |
138 | for i in range(len(intList)/2): |
|
138 | for i in range(len(intList)/2): | |
139 | pairList.append((intList[i*2], intList[i*2 + 1])) |
|
139 | pairList.append((intList[i*2], intList[i*2 + 1])) | |
140 |
|
140 | |||
141 | self.__formated_value = pairList |
|
141 | self.__formated_value = pairList | |
142 |
|
142 | |||
143 | return self.__formated_value |
|
143 | return self.__formated_value | |
144 |
|
144 | |||
145 | if format == 'multilist': |
|
145 | if format == 'multilist': | |
146 | """ |
|
146 | """ | |
147 | Example: |
|
147 | Example: | |
148 | value = (0,1,2),(3,4,5) |
|
148 | value = (0,1,2),(3,4,5) | |
149 | """ |
|
149 | """ | |
150 | multiList = ast.literal_eval(value) |
|
150 | multiList = ast.literal_eval(value) | |
151 |
|
151 | |||
152 | if type(multiList[0]) == int: |
|
152 | if type(multiList[0]) == int: | |
153 | multiList = ast.literal_eval("(" + value + ")") |
|
153 | multiList = ast.literal_eval("(" + value + ")") | |
154 |
|
154 | |||
155 | self.__formated_value = multiList |
|
155 | self.__formated_value = multiList | |
156 |
|
156 | |||
157 | return self.__formated_value |
|
157 | return self.__formated_value | |
158 |
|
158 | |||
159 | if format == 'bool': |
|
159 | if format == 'bool': | |
160 | value = int(value) |
|
160 | value = int(value) | |
161 |
|
161 | |||
162 | if format == 'int': |
|
162 | if format == 'int': | |
163 | value = float(value) |
|
163 | value = float(value) | |
164 |
|
164 | |||
165 | format_func = eval(format) |
|
165 | format_func = eval(format) | |
166 |
|
166 | |||
167 | self.__formated_value = format_func(value) |
|
167 | self.__formated_value = format_func(value) | |
168 |
|
168 | |||
169 | return self.__formated_value |
|
169 | return self.__formated_value | |
170 |
|
170 | |||
171 | def updateId(self, new_id): |
|
171 | def updateId(self, new_id): | |
172 |
|
172 | |||
173 | self.id = str(new_id) |
|
173 | self.id = str(new_id) | |
174 |
|
174 | |||
175 | def setup(self, id, name, value, format='str'): |
|
175 | def setup(self, id, name, value, format='str'): | |
176 |
|
176 | |||
177 | self.id = str(id) |
|
177 | self.id = str(id) | |
178 | self.name = name |
|
178 | self.name = name | |
179 | self.value = str(value) |
|
179 | self.value = str(value) | |
180 | self.format = str.lower(format) |
|
180 | self.format = str.lower(format) | |
181 |
|
181 | |||
182 | try: |
|
182 | try: | |
183 | self.getValue() |
|
183 | self.getValue() | |
184 | except: |
|
184 | except: | |
185 | return 0 |
|
185 | return 0 | |
186 |
|
186 | |||
187 | return 1 |
|
187 | return 1 | |
188 |
|
188 | |||
189 | def update(self, name, value, format='str'): |
|
189 | def update(self, name, value, format='str'): | |
190 |
|
190 | |||
191 | self.name = name |
|
191 | self.name = name | |
192 | self.value = str(value) |
|
192 | self.value = str(value) | |
193 | self.format = format |
|
193 | self.format = format | |
194 |
|
194 | |||
195 | def makeXml(self, opElement): |
|
195 | def makeXml(self, opElement): | |
196 |
|
196 | |||
197 | parmElement = SubElement(opElement, self.ELEMENTNAME) |
|
197 | parmElement = SubElement(opElement, self.ELEMENTNAME) | |
198 | parmElement.set('id', str(self.id)) |
|
198 | parmElement.set('id', str(self.id)) | |
199 | parmElement.set('name', self.name) |
|
199 | parmElement.set('name', self.name) | |
200 | parmElement.set('value', self.value) |
|
200 | parmElement.set('value', self.value) | |
201 | parmElement.set('format', self.format) |
|
201 | parmElement.set('format', self.format) | |
202 |
|
202 | |||
203 | def readXml(self, parmElement): |
|
203 | def readXml(self, parmElement): | |
204 |
|
204 | |||
205 | self.id = parmElement.get('id') |
|
205 | self.id = parmElement.get('id') | |
206 | self.name = parmElement.get('name') |
|
206 | self.name = parmElement.get('name') | |
207 | self.value = parmElement.get('value') |
|
207 | self.value = parmElement.get('value') | |
208 | self.format = str.lower(parmElement.get('format')) |
|
208 | self.format = str.lower(parmElement.get('format')) | |
209 |
|
209 | |||
210 | #Compatible with old signal chain version |
|
210 | #Compatible with old signal chain version | |
211 | if self.format == 'int' and self.name == 'idfigure': |
|
211 | if self.format == 'int' and self.name == 'idfigure': | |
212 | self.name = 'id' |
|
212 | self.name = 'id' | |
213 |
|
213 | |||
214 | def printattr(self): |
|
214 | def printattr(self): | |
215 |
|
215 | |||
216 | print "Parameter[%s]: name = %s, value = %s, format = %s" %(self.id, self.name, self.value, self.format) |
|
216 | print "Parameter[%s]: name = %s, value = %s, format = %s" %(self.id, self.name, self.value, self.format) | |
217 |
|
217 | |||
218 | class OperationConf(): |
|
218 | class OperationConf(): | |
219 |
|
219 | |||
220 | id = None |
|
220 | id = None | |
221 | name = None |
|
221 | name = None | |
222 | priority = None |
|
222 | priority = None | |
223 | type = None |
|
223 | type = None | |
224 |
|
224 | |||
225 | parmConfObjList = [] |
|
225 | parmConfObjList = [] | |
226 |
|
226 | |||
227 | ELEMENTNAME = 'Operation' |
|
227 | ELEMENTNAME = 'Operation' | |
228 |
|
228 | |||
229 | def __init__(self): |
|
229 | def __init__(self): | |
230 |
|
230 | |||
231 | self.id = '0' |
|
231 | self.id = '0' | |
232 | self.name = None |
|
232 | self.name = None | |
233 | self.priority = None |
|
233 | self.priority = None | |
234 | self.type = 'self' |
|
234 | self.type = 'self' | |
235 |
|
235 | |||
236 |
|
236 | |||
237 | def __getNewId(self): |
|
237 | def __getNewId(self): | |
238 |
|
238 | |||
239 | return int(self.id)*10 + len(self.parmConfObjList) + 1 |
|
239 | return int(self.id)*10 + len(self.parmConfObjList) + 1 | |
240 |
|
240 | |||
241 | def updateId(self, new_id): |
|
241 | def updateId(self, new_id): | |
242 |
|
242 | |||
243 | self.id = str(new_id) |
|
243 | self.id = str(new_id) | |
244 |
|
244 | |||
245 | n = 1 |
|
245 | n = 1 | |
246 | for parmObj in self.parmConfObjList: |
|
246 | for parmObj in self.parmConfObjList: | |
247 |
|
247 | |||
248 | idParm = str(int(new_id)*10 + n) |
|
248 | idParm = str(int(new_id)*10 + n) | |
249 | parmObj.updateId(idParm) |
|
249 | parmObj.updateId(idParm) | |
250 |
|
250 | |||
251 | n += 1 |
|
251 | n += 1 | |
252 |
|
252 | |||
253 | def getElementName(self): |
|
253 | def getElementName(self): | |
254 |
|
254 | |||
255 | return self.ELEMENTNAME |
|
255 | return self.ELEMENTNAME | |
256 |
|
256 | |||
257 | def getParameterObjList(self): |
|
257 | def getParameterObjList(self): | |
258 |
|
258 | |||
259 | return self.parmConfObjList |
|
259 | return self.parmConfObjList | |
260 |
|
260 | |||
261 | def getParameterObj(self, parameterName): |
|
261 | def getParameterObj(self, parameterName): | |
262 |
|
262 | |||
263 | for parmConfObj in self.parmConfObjList: |
|
263 | for parmConfObj in self.parmConfObjList: | |
264 |
|
264 | |||
265 | if parmConfObj.name != parameterName: |
|
265 | if parmConfObj.name != parameterName: | |
266 | continue |
|
266 | continue | |
267 |
|
267 | |||
268 | return parmConfObj |
|
268 | return parmConfObj | |
269 |
|
269 | |||
270 | return None |
|
270 | return None | |
271 |
|
271 | |||
272 | def getParameterObjfromValue(self, parameterValue): |
|
272 | def getParameterObjfromValue(self, parameterValue): | |
273 |
|
273 | |||
274 | for parmConfObj in self.parmConfObjList: |
|
274 | for parmConfObj in self.parmConfObjList: | |
275 |
|
275 | |||
276 | if parmConfObj.getValue() != parameterValue: |
|
276 | if parmConfObj.getValue() != parameterValue: | |
277 | continue |
|
277 | continue | |
278 |
|
278 | |||
279 | return parmConfObj.getValue() |
|
279 | return parmConfObj.getValue() | |
280 |
|
280 | |||
281 | return None |
|
281 | return None | |
282 |
|
282 | |||
283 | def getParameterValue(self, parameterName): |
|
283 | def getParameterValue(self, parameterName): | |
284 |
|
284 | |||
285 | parameterObj = self.getParameterObj(parameterName) |
|
285 | parameterObj = self.getParameterObj(parameterName) | |
286 |
|
286 | |||
287 | # if not parameterObj: |
|
287 | # if not parameterObj: | |
288 | # return None |
|
288 | # return None | |
289 |
|
289 | |||
290 | value = parameterObj.getValue() |
|
290 | value = parameterObj.getValue() | |
291 |
|
291 | |||
292 | return value |
|
292 | return value | |
293 |
|
293 | |||
294 | def setup(self, id, name, priority, type): |
|
294 | def setup(self, id, name, priority, type): | |
295 |
|
295 | |||
296 | self.id = str(id) |
|
296 | self.id = str(id) | |
297 | self.name = name |
|
297 | self.name = name | |
298 | self.type = type |
|
298 | self.type = type | |
299 | self.priority = priority |
|
299 | self.priority = priority | |
300 |
|
300 | |||
301 | self.parmConfObjList = [] |
|
301 | self.parmConfObjList = [] | |
302 |
|
302 | |||
303 | def removeParameters(self): |
|
303 | def removeParameters(self): | |
304 |
|
304 | |||
305 | for obj in self.parmConfObjList: |
|
305 | for obj in self.parmConfObjList: | |
306 | del obj |
|
306 | del obj | |
307 |
|
307 | |||
308 | self.parmConfObjList = [] |
|
308 | self.parmConfObjList = [] | |
309 |
|
309 | |||
310 | def addParameter(self, name, value, format='str'): |
|
310 | def addParameter(self, name, value, format='str'): | |
311 |
|
311 | |||
312 | id = self.__getNewId() |
|
312 | id = self.__getNewId() | |
313 |
|
313 | |||
314 | parmConfObj = ParameterConf() |
|
314 | parmConfObj = ParameterConf() | |
315 | if not parmConfObj.setup(id, name, value, format): |
|
315 | if not parmConfObj.setup(id, name, value, format): | |
316 | return None |
|
316 | return None | |
317 |
|
317 | |||
318 | self.parmConfObjList.append(parmConfObj) |
|
318 | self.parmConfObjList.append(parmConfObj) | |
319 |
|
319 | |||
320 | return parmConfObj |
|
320 | return parmConfObj | |
321 |
|
321 | |||
322 | def changeParameter(self, name, value, format='str'): |
|
322 | def changeParameter(self, name, value, format='str'): | |
323 |
|
323 | |||
324 | parmConfObj = self.getParameterObj(name) |
|
324 | parmConfObj = self.getParameterObj(name) | |
325 | parmConfObj.update(name, value, format) |
|
325 | parmConfObj.update(name, value, format) | |
326 |
|
326 | |||
327 | return parmConfObj |
|
327 | return parmConfObj | |
328 |
|
328 | |||
329 | def makeXml(self, procUnitElement): |
|
329 | def makeXml(self, procUnitElement): | |
330 |
|
330 | |||
331 | opElement = SubElement(procUnitElement, self.ELEMENTNAME) |
|
331 | opElement = SubElement(procUnitElement, self.ELEMENTNAME) | |
332 | opElement.set('id', str(self.id)) |
|
332 | opElement.set('id', str(self.id)) | |
333 | opElement.set('name', self.name) |
|
333 | opElement.set('name', self.name) | |
334 | opElement.set('type', self.type) |
|
334 | opElement.set('type', self.type) | |
335 | opElement.set('priority', str(self.priority)) |
|
335 | opElement.set('priority', str(self.priority)) | |
336 |
|
336 | |||
337 | for parmConfObj in self.parmConfObjList: |
|
337 | for parmConfObj in self.parmConfObjList: | |
338 | parmConfObj.makeXml(opElement) |
|
338 | parmConfObj.makeXml(opElement) | |
339 |
|
339 | |||
340 | def readXml(self, opElement): |
|
340 | def readXml(self, opElement): | |
341 |
|
341 | |||
342 | self.id = opElement.get('id') |
|
342 | self.id = opElement.get('id') | |
343 | self.name = opElement.get('name') |
|
343 | self.name = opElement.get('name') | |
344 | self.type = opElement.get('type') |
|
344 | self.type = opElement.get('type') | |
345 | self.priority = opElement.get('priority') |
|
345 | self.priority = opElement.get('priority') | |
346 |
|
346 | |||
347 | #Compatible with old signal chain version |
|
347 | #Compatible with old signal chain version | |
348 | #Use of 'run' method instead 'init' |
|
348 | #Use of 'run' method instead 'init' | |
349 | if self.type == 'self' and self.name == 'init': |
|
349 | if self.type == 'self' and self.name == 'init': | |
350 | self.name = 'run' |
|
350 | self.name = 'run' | |
351 |
|
351 | |||
352 | self.parmConfObjList = [] |
|
352 | self.parmConfObjList = [] | |
353 |
|
353 | |||
354 | parmElementList = opElement.getiterator(ParameterConf().getElementName()) |
|
354 | parmElementList = opElement.getiterator(ParameterConf().getElementName()) | |
355 |
|
355 | |||
356 | for parmElement in parmElementList: |
|
356 | for parmElement in parmElementList: | |
357 | parmConfObj = ParameterConf() |
|
357 | parmConfObj = ParameterConf() | |
358 | parmConfObj.readXml(parmElement) |
|
358 | parmConfObj.readXml(parmElement) | |
359 |
|
359 | |||
360 | #Compatible with old signal chain version |
|
360 | #Compatible with old signal chain version | |
361 | #If an 'plot' OPERATION is found, changes name operation by the value of its type PARAMETER |
|
361 | #If an 'plot' OPERATION is found, changes name operation by the value of its type PARAMETER | |
362 | if self.type != 'self' and self.name == 'Plot': |
|
362 | if self.type != 'self' and self.name == 'Plot': | |
363 | if parmConfObj.format == 'str' and parmConfObj.name == 'type': |
|
363 | if parmConfObj.format == 'str' and parmConfObj.name == 'type': | |
364 | self.name = parmConfObj.value |
|
364 | self.name = parmConfObj.value | |
365 | continue |
|
365 | continue | |
366 |
|
366 | |||
367 | self.parmConfObjList.append(parmConfObj) |
|
367 | self.parmConfObjList.append(parmConfObj) | |
368 |
|
368 | |||
369 | def printattr(self): |
|
369 | def printattr(self): | |
370 |
|
370 | |||
371 | print "%s[%s]: name = %s, type = %s, priority = %s" %(self.ELEMENTNAME, |
|
371 | print "%s[%s]: name = %s, type = %s, priority = %s" %(self.ELEMENTNAME, | |
372 | self.id, |
|
372 | self.id, | |
373 | self.name, |
|
373 | self.name, | |
374 | self.type, |
|
374 | self.type, | |
375 | self.priority) |
|
375 | self.priority) | |
376 |
|
376 | |||
377 | for parmConfObj in self.parmConfObjList: |
|
377 | for parmConfObj in self.parmConfObjList: | |
378 | parmConfObj.printattr() |
|
378 | parmConfObj.printattr() | |
379 |
|
379 | |||
380 | def createObject(self, plotter_queue=None): |
|
380 | def createObject(self, plotter_queue=None): | |
381 |
|
381 | |||
382 | if self.type == 'self': |
|
382 | if self.type == 'self': | |
383 | raise ValueError, "This operation type cannot be created" |
|
383 | raise ValueError, "This operation type cannot be created" | |
384 |
|
384 | |||
385 | if self.type == 'plotter': |
|
385 | if self.type == 'plotter': | |
386 | #Plotter(plotter_name) |
|
386 | #Plotter(plotter_name) | |
387 | opObj = Plotter(self.name, plotter_queue) |
|
387 | opObj = Plotter(self.name, plotter_queue) | |
388 |
|
388 | |||
389 | if self.type == 'external' or self.type == 'other': |
|
389 | if self.type == 'external' or self.type == 'other': | |
390 | className = eval(self.name) |
|
390 | className = eval(self.name) | |
391 | opObj = className() |
|
391 | opObj = className() | |
392 |
|
392 | |||
393 | return opObj |
|
393 | return opObj | |
394 |
|
394 | |||
395 | class ProcUnitConf(): |
|
395 | class ProcUnitConf(): | |
396 |
|
396 | |||
397 | id = None |
|
397 | id = None | |
398 | name = None |
|
398 | name = None | |
399 | datatype = None |
|
399 | datatype = None | |
400 | inputId = None |
|
400 | inputId = None | |
401 | parentId = None |
|
401 | parentId = None | |
402 |
|
402 | |||
403 | opConfObjList = [] |
|
403 | opConfObjList = [] | |
404 |
|
404 | |||
405 | procUnitObj = None |
|
405 | procUnitObj = None | |
406 | opObjList = [] |
|
406 | opObjList = [] | |
407 |
|
407 | |||
408 | ELEMENTNAME = 'ProcUnit' |
|
408 | ELEMENTNAME = 'ProcUnit' | |
409 |
|
409 | |||
410 | def __init__(self): |
|
410 | def __init__(self): | |
411 |
|
411 | |||
412 | self.id = None |
|
412 | self.id = None | |
413 | self.datatype = None |
|
413 | self.datatype = None | |
414 | self.name = None |
|
414 | self.name = None | |
415 | self.inputId = None |
|
415 | self.inputId = None | |
416 |
|
416 | |||
417 | self.opConfObjList = [] |
|
417 | self.opConfObjList = [] | |
418 |
|
418 | |||
419 | self.procUnitObj = None |
|
419 | self.procUnitObj = None | |
420 | self.opObjDict = {} |
|
420 | self.opObjDict = {} | |
421 |
|
421 | |||
422 | def __getPriority(self): |
|
422 | def __getPriority(self): | |
423 |
|
423 | |||
424 | return len(self.opConfObjList)+1 |
|
424 | return len(self.opConfObjList)+1 | |
425 |
|
425 | |||
426 | def __getNewId(self): |
|
426 | def __getNewId(self): | |
427 |
|
427 | |||
428 | return int(self.id)*10 + len(self.opConfObjList) + 1 |
|
428 | return int(self.id)*10 + len(self.opConfObjList) + 1 | |
429 |
|
429 | |||
430 | def getElementName(self): |
|
430 | def getElementName(self): | |
431 |
|
431 | |||
432 | return self.ELEMENTNAME |
|
432 | return self.ELEMENTNAME | |
433 |
|
433 | |||
434 | def getId(self): |
|
434 | def getId(self): | |
435 |
|
435 | |||
436 | return self.id |
|
436 | return self.id | |
437 |
|
437 | |||
438 | def updateId(self, new_id, parentId=parentId): |
|
438 | def updateId(self, new_id, parentId=parentId): | |
439 |
|
439 | |||
440 |
|
440 | |||
441 | new_id = int(parentId)*10 + (int(self.id) % 10) |
|
441 | new_id = int(parentId)*10 + (int(self.id) % 10) | |
442 | new_inputId = int(parentId)*10 + (int(self.inputId) % 10) |
|
442 | new_inputId = int(parentId)*10 + (int(self.inputId) % 10) | |
443 |
|
443 | |||
444 | #If this proc unit has not inputs |
|
444 | #If this proc unit has not inputs | |
445 | if self.inputId == '0': |
|
445 | if self.inputId == '0': | |
446 | new_inputId = 0 |
|
446 | new_inputId = 0 | |
447 |
|
447 | |||
448 | n = 1 |
|
448 | n = 1 | |
449 | for opConfObj in self.opConfObjList: |
|
449 | for opConfObj in self.opConfObjList: | |
450 |
|
450 | |||
451 | idOp = str(int(new_id)*10 + n) |
|
451 | idOp = str(int(new_id)*10 + n) | |
452 | opConfObj.updateId(idOp) |
|
452 | opConfObj.updateId(idOp) | |
453 |
|
453 | |||
454 | n += 1 |
|
454 | n += 1 | |
455 |
|
455 | |||
456 | self.parentId = str(parentId) |
|
456 | self.parentId = str(parentId) | |
457 | self.id = str(new_id) |
|
457 | self.id = str(new_id) | |
458 | self.inputId = str(new_inputId) |
|
458 | self.inputId = str(new_inputId) | |
459 |
|
459 | |||
460 |
|
460 | |||
461 | def getInputId(self): |
|
461 | def getInputId(self): | |
462 |
|
462 | |||
463 | return self.inputId |
|
463 | return self.inputId | |
464 |
|
464 | |||
465 | def getOperationObjList(self): |
|
465 | def getOperationObjList(self): | |
466 |
|
466 | |||
467 | return self.opConfObjList |
|
467 | return self.opConfObjList | |
468 |
|
468 | |||
469 | def getOperationObj(self, name=None): |
|
469 | def getOperationObj(self, name=None): | |
470 |
|
470 | |||
471 | for opConfObj in self.opConfObjList: |
|
471 | for opConfObj in self.opConfObjList: | |
472 |
|
472 | |||
473 | if opConfObj.name != name: |
|
473 | if opConfObj.name != name: | |
474 | continue |
|
474 | continue | |
475 |
|
475 | |||
476 | return opConfObj |
|
476 | return opConfObj | |
477 |
|
477 | |||
478 | return None |
|
478 | return None | |
479 |
|
479 | |||
480 | def getOpObjfromParamValue(self, value=None): |
|
480 | def getOpObjfromParamValue(self, value=None): | |
481 |
|
481 | |||
482 | for opConfObj in self.opConfObjList: |
|
482 | for opConfObj in self.opConfObjList: | |
483 | if opConfObj.getParameterObjfromValue(parameterValue=value) != value: |
|
483 | if opConfObj.getParameterObjfromValue(parameterValue=value) != value: | |
484 | continue |
|
484 | continue | |
485 | return opConfObj |
|
485 | return opConfObj | |
486 | return None |
|
486 | return None | |
487 |
|
487 | |||
488 | def getProcUnitObj(self): |
|
488 | def getProcUnitObj(self): | |
489 |
|
489 | |||
490 | return self.procUnitObj |
|
490 | return self.procUnitObj | |
491 |
|
491 | |||
492 | def setup(self, id, name, datatype, inputId, parentId=None): |
|
492 | def setup(self, id, name, datatype, inputId, parentId=None): | |
493 |
|
493 | |||
494 | #Compatible with old signal chain version |
|
494 | #Compatible with old signal chain version | |
495 | if datatype==None and name==None: |
|
495 | if datatype==None and name==None: | |
496 | raise ValueError, "datatype or name should be defined" |
|
496 | raise ValueError, "datatype or name should be defined" | |
497 |
|
497 | |||
498 | if name==None: |
|
498 | if name==None: | |
499 | if 'Proc' in datatype: |
|
499 | if 'Proc' in datatype: | |
500 | name = datatype |
|
500 | name = datatype | |
501 | else: |
|
501 | else: | |
502 | name = '%sProc' %(datatype) |
|
502 | name = '%sProc' %(datatype) | |
503 |
|
503 | |||
504 | if datatype==None: |
|
504 | if datatype==None: | |
505 | datatype = name.replace('Proc','') |
|
505 | datatype = name.replace('Proc','') | |
506 |
|
506 | |||
507 | self.id = str(id) |
|
507 | self.id = str(id) | |
508 | self.name = name |
|
508 | self.name = name | |
509 | self.datatype = datatype |
|
509 | self.datatype = datatype | |
510 | self.inputId = inputId |
|
510 | self.inputId = inputId | |
511 | self.parentId = parentId |
|
511 | self.parentId = parentId | |
512 |
|
512 | |||
513 | self.opConfObjList = [] |
|
513 | self.opConfObjList = [] | |
514 |
|
514 | |||
515 | self.addOperation(name='run', optype='self') |
|
515 | self.addOperation(name='run', optype='self') | |
516 |
|
516 | |||
517 | def removeOperations(self): |
|
517 | def removeOperations(self): | |
518 |
|
518 | |||
519 | for obj in self.opConfObjList: |
|
519 | for obj in self.opConfObjList: | |
520 | del obj |
|
520 | del obj | |
521 |
|
521 | |||
522 | self.opConfObjList = [] |
|
522 | self.opConfObjList = [] | |
523 | self.addOperation(name='run') |
|
523 | self.addOperation(name='run') | |
524 |
|
524 | |||
525 | def addParameter(self, **kwargs): |
|
525 | def addParameter(self, **kwargs): | |
526 | ''' |
|
526 | ''' | |
527 | Add parameters to "run" operation |
|
527 | Add parameters to "run" operation | |
528 | ''' |
|
528 | ''' | |
529 | opObj = self.opConfObjList[0] |
|
529 | opObj = self.opConfObjList[0] | |
530 |
|
530 | |||
531 | opObj.addParameter(**kwargs) |
|
531 | opObj.addParameter(**kwargs) | |
532 |
|
532 | |||
533 | return opObj |
|
533 | return opObj | |
534 |
|
534 | |||
535 | def addOperation(self, name, optype='self'): |
|
535 | def addOperation(self, name, optype='self'): | |
536 |
|
536 | |||
537 | id = self.__getNewId() |
|
537 | id = self.__getNewId() | |
538 | priority = self.__getPriority() |
|
538 | priority = self.__getPriority() | |
539 |
|
539 | |||
540 | opConfObj = OperationConf() |
|
540 | opConfObj = OperationConf() | |
541 | opConfObj.setup(id, name=name, priority=priority, type=optype) |
|
541 | opConfObj.setup(id, name=name, priority=priority, type=optype) | |
542 |
|
542 | |||
543 | self.opConfObjList.append(opConfObj) |
|
543 | self.opConfObjList.append(opConfObj) | |
544 |
|
544 | |||
545 | return opConfObj |
|
545 | return opConfObj | |
546 |
|
546 | |||
547 | def makeXml(self, projectElement): |
|
547 | def makeXml(self, projectElement): | |
548 |
|
548 | |||
549 | procUnitElement = SubElement(projectElement, self.ELEMENTNAME) |
|
549 | procUnitElement = SubElement(projectElement, self.ELEMENTNAME) | |
550 | procUnitElement.set('id', str(self.id)) |
|
550 | procUnitElement.set('id', str(self.id)) | |
551 | procUnitElement.set('name', self.name) |
|
551 | procUnitElement.set('name', self.name) | |
552 | procUnitElement.set('datatype', self.datatype) |
|
552 | procUnitElement.set('datatype', self.datatype) | |
553 | procUnitElement.set('inputId', str(self.inputId)) |
|
553 | procUnitElement.set('inputId', str(self.inputId)) | |
554 |
|
554 | |||
555 | for opConfObj in self.opConfObjList: |
|
555 | for opConfObj in self.opConfObjList: | |
556 | opConfObj.makeXml(procUnitElement) |
|
556 | opConfObj.makeXml(procUnitElement) | |
557 |
|
557 | |||
558 | def readXml(self, upElement): |
|
558 | def readXml(self, upElement): | |
559 |
|
559 | |||
560 | self.id = upElement.get('id') |
|
560 | self.id = upElement.get('id') | |
561 | self.name = upElement.get('name') |
|
561 | self.name = upElement.get('name') | |
562 | self.datatype = upElement.get('datatype') |
|
562 | self.datatype = upElement.get('datatype') | |
563 | self.inputId = upElement.get('inputId') |
|
563 | self.inputId = upElement.get('inputId') | |
564 |
|
564 | |||
565 | if self.ELEMENTNAME == "ReadUnit": |
|
565 | if self.ELEMENTNAME == "ReadUnit": | |
566 | self.datatype = self.datatype.replace("Reader", "") |
|
566 | self.datatype = self.datatype.replace("Reader", "") | |
567 |
|
567 | |||
568 | if self.ELEMENTNAME == "ProcUnit": |
|
568 | if self.ELEMENTNAME == "ProcUnit": | |
569 | self.datatype = self.datatype.replace("Proc", "") |
|
569 | self.datatype = self.datatype.replace("Proc", "") | |
570 |
|
570 | |||
571 | if self.inputId == 'None': |
|
571 | if self.inputId == 'None': | |
572 | self.inputId = '0' |
|
572 | self.inputId = '0' | |
573 |
|
573 | |||
574 | self.opConfObjList = [] |
|
574 | self.opConfObjList = [] | |
575 |
|
575 | |||
576 | opElementList = upElement.getiterator(OperationConf().getElementName()) |
|
576 | opElementList = upElement.getiterator(OperationConf().getElementName()) | |
577 |
|
577 | |||
578 | for opElement in opElementList: |
|
578 | for opElement in opElementList: | |
579 | opConfObj = OperationConf() |
|
579 | opConfObj = OperationConf() | |
580 | opConfObj.readXml(opElement) |
|
580 | opConfObj.readXml(opElement) | |
581 | self.opConfObjList.append(opConfObj) |
|
581 | self.opConfObjList.append(opConfObj) | |
582 |
|
582 | |||
583 | def printattr(self): |
|
583 | def printattr(self): | |
584 |
|
584 | |||
585 | print "%s[%s]: name = %s, datatype = %s, inputId = %s" %(self.ELEMENTNAME, |
|
585 | print "%s[%s]: name = %s, datatype = %s, inputId = %s" %(self.ELEMENTNAME, | |
586 | self.id, |
|
586 | self.id, | |
587 | self.name, |
|
587 | self.name, | |
588 | self.datatype, |
|
588 | self.datatype, | |
589 | self.inputId) |
|
589 | self.inputId) | |
590 |
|
590 | |||
591 | for opConfObj in self.opConfObjList: |
|
591 | for opConfObj in self.opConfObjList: | |
592 | opConfObj.printattr() |
|
592 | opConfObj.printattr() | |
593 |
|
593 | |||
594 | def createObjects(self, plotter_queue=None): |
|
594 | def createObjects(self, plotter_queue=None): | |
595 |
|
595 | |||
596 | className = eval(self.name) |
|
596 | className = eval(self.name) | |
597 | procUnitObj = className() |
|
597 | procUnitObj = className() | |
598 |
|
598 | |||
599 | for opConfObj in self.opConfObjList: |
|
599 | for opConfObj in self.opConfObjList: | |
600 |
|
600 | |||
601 | if opConfObj.type == 'self': |
|
601 | if opConfObj.type == 'self': | |
602 | continue |
|
602 | continue | |
603 |
|
603 | |||
604 | opObj = opConfObj.createObject(plotter_queue) |
|
604 | opObj = opConfObj.createObject(plotter_queue) | |
605 |
|
605 | |||
606 | self.opObjDict[opConfObj.id] = opObj |
|
606 | self.opObjDict[opConfObj.id] = opObj | |
607 | procUnitObj.addOperation(opObj, opConfObj.id) |
|
607 | procUnitObj.addOperation(opObj, opConfObj.id) | |
608 |
|
608 | |||
609 | self.procUnitObj = procUnitObj |
|
609 | self.procUnitObj = procUnitObj | |
610 |
|
610 | |||
611 | return procUnitObj |
|
611 | return procUnitObj | |
612 |
|
612 | |||
613 | def run(self): |
|
613 | def run(self): | |
614 |
|
614 | |||
615 | is_ok = False |
|
615 | is_ok = False | |
616 |
|
616 | |||
617 | for opConfObj in self.opConfObjList: |
|
617 | for opConfObj in self.opConfObjList: | |
618 |
|
618 | |||
619 | kwargs = {} |
|
619 | kwargs = {} | |
620 | for parmConfObj in opConfObj.getParameterObjList(): |
|
620 | for parmConfObj in opConfObj.getParameterObjList(): | |
621 | if opConfObj.name == 'run' and parmConfObj.name == 'datatype': |
|
621 | if opConfObj.name == 'run' and parmConfObj.name == 'datatype': | |
622 | continue |
|
622 | continue | |
623 |
|
623 | |||
624 | kwargs[parmConfObj.name] = parmConfObj.getValue() |
|
624 | kwargs[parmConfObj.name] = parmConfObj.getValue() | |
625 |
|
625 | |||
626 | #print "\tRunning the '%s' operation with %s" %(opConfObj.name, opConfObj.id) |
|
626 | #print "\tRunning the '%s' operation with %s" %(opConfObj.name, opConfObj.id) | |
627 | sts = self.procUnitObj.call(opType = opConfObj.type, |
|
627 | sts = self.procUnitObj.call(opType = opConfObj.type, | |
628 | opName = opConfObj.name, |
|
628 | opName = opConfObj.name, | |
629 | opId = opConfObj.id, |
|
629 | opId = opConfObj.id, | |
630 | **kwargs) |
|
630 | **kwargs) | |
631 | is_ok = is_ok or sts |
|
631 | is_ok = is_ok or sts | |
632 |
|
632 | |||
633 | return is_ok |
|
633 | return is_ok | |
634 |
|
634 | |||
635 | def close(self): |
|
635 | def close(self): | |
636 |
|
636 | |||
637 | for opConfObj in self.opConfObjList: |
|
637 | for opConfObj in self.opConfObjList: | |
638 | if opConfObj.type == 'self': |
|
638 | if opConfObj.type == 'self': | |
639 | continue |
|
639 | continue | |
640 |
|
640 | |||
641 | opObj = self.procUnitObj.getOperationObj(opConfObj.id) |
|
641 | opObj = self.procUnitObj.getOperationObj(opConfObj.id) | |
642 | opObj.close() |
|
642 | opObj.close() | |
643 |
|
643 | |||
644 | self.procUnitObj.close() |
|
644 | self.procUnitObj.close() | |
645 |
|
645 | |||
646 | return |
|
646 | return | |
647 |
|
647 | |||
648 | class ReadUnitConf(ProcUnitConf): |
|
648 | class ReadUnitConf(ProcUnitConf): | |
649 |
|
649 | |||
650 | path = None |
|
650 | path = None | |
651 | startDate = None |
|
651 | startDate = None | |
652 | endDate = None |
|
652 | endDate = None | |
653 | startTime = None |
|
653 | startTime = None | |
654 | endTime = None |
|
654 | endTime = None | |
655 |
|
655 | |||
656 | ELEMENTNAME = 'ReadUnit' |
|
656 | ELEMENTNAME = 'ReadUnit' | |
657 |
|
657 | |||
658 | def __init__(self): |
|
658 | def __init__(self): | |
659 |
|
659 | |||
660 | self.id = None |
|
660 | self.id = None | |
661 | self.datatype = None |
|
661 | self.datatype = None | |
662 | self.name = None |
|
662 | self.name = None | |
663 | self.inputId = None |
|
663 | self.inputId = None | |
664 |
|
664 | |||
665 | self.parentId = None |
|
665 | self.parentId = None | |
666 |
|
666 | |||
667 | self.opConfObjList = [] |
|
667 | self.opConfObjList = [] | |
668 | self.opObjList = [] |
|
668 | self.opObjList = [] | |
669 |
|
669 | |||
670 | def getElementName(self): |
|
670 | def getElementName(self): | |
671 |
|
671 | |||
672 | return self.ELEMENTNAME |
|
672 | return self.ELEMENTNAME | |
673 |
|
673 | |||
674 | def setup(self, id, name, datatype, path, startDate="", endDate="", startTime="", endTime="", parentId=None, **kwargs): |
|
674 | def setup(self, id, name, datatype, path, startDate="", endDate="", startTime="", endTime="", parentId=None, **kwargs): | |
675 |
|
675 | |||
676 | #Compatible with old signal chain version |
|
676 | #Compatible with old signal chain version | |
677 | if datatype==None and name==None: |
|
677 | if datatype==None and name==None: | |
678 | raise ValueError, "datatype or name should be defined" |
|
678 | raise ValueError, "datatype or name should be defined" | |
679 |
|
679 | |||
680 | if name==None: |
|
680 | if name==None: | |
681 | if 'Reader' in datatype: |
|
681 | if 'Reader' in datatype: | |
682 | name = datatype |
|
682 | name = datatype | |
683 | else: |
|
683 | else: | |
684 | name = '%sReader' %(datatype) |
|
684 | name = '%sReader' %(datatype) | |
685 |
|
685 | |||
686 | if datatype==None: |
|
686 | if datatype==None: | |
687 | datatype = name.replace('Reader','') |
|
687 | datatype = name.replace('Reader','') | |
688 |
|
688 | |||
689 | self.id = id |
|
689 | self.id = id | |
690 | self.name = name |
|
690 | self.name = name | |
691 | self.datatype = datatype |
|
691 | self.datatype = datatype | |
692 |
|
692 | |||
693 | self.path = os.path.abspath(path) |
|
693 | self.path = os.path.abspath(path) | |
694 | self.startDate = startDate |
|
694 | self.startDate = startDate | |
695 | self.endDate = endDate |
|
695 | self.endDate = endDate | |
696 | self.startTime = startTime |
|
696 | self.startTime = startTime | |
697 | self.endTime = endTime |
|
697 | self.endTime = endTime | |
698 |
|
698 | |||
699 | self.inputId = '0' |
|
699 | self.inputId = '0' | |
700 | self.parentId = parentId |
|
700 | self.parentId = parentId | |
701 |
|
701 | |||
702 | self.addRunOperation(**kwargs) |
|
702 | self.addRunOperation(**kwargs) | |
703 |
|
703 | |||
704 | def update(self, datatype, path, startDate, endDate, startTime, endTime, parentId=None, name=None, **kwargs): |
|
704 | def update(self, datatype, path, startDate, endDate, startTime, endTime, parentId=None, name=None, **kwargs): | |
705 |
|
705 | |||
706 | #Compatible with old signal chain version |
|
706 | #Compatible with old signal chain version | |
707 | if datatype==None and name==None: |
|
707 | if datatype==None and name==None: | |
708 | raise ValueError, "datatype or name should be defined" |
|
708 | raise ValueError, "datatype or name should be defined" | |
709 |
|
709 | |||
710 | if name==None: |
|
710 | if name==None: | |
711 | if 'Reader' in datatype: |
|
711 | if 'Reader' in datatype: | |
712 | name = datatype |
|
712 | name = datatype | |
713 | else: |
|
713 | else: | |
714 | name = '%sReader' %(datatype) |
|
714 | name = '%sReader' %(datatype) | |
715 |
|
715 | |||
716 | if datatype==None: |
|
716 | if datatype==None: | |
717 | datatype = name.replace('Reader','') |
|
717 | datatype = name.replace('Reader','') | |
718 |
|
718 | |||
719 | self.datatype = datatype |
|
719 | self.datatype = datatype | |
720 | self.name = name |
|
720 | self.name = name | |
721 | self.path = path |
|
721 | self.path = path | |
722 | self.startDate = startDate |
|
722 | self.startDate = startDate | |
723 | self.endDate = endDate |
|
723 | self.endDate = endDate | |
724 | self.startTime = startTime |
|
724 | self.startTime = startTime | |
725 | self.endTime = endTime |
|
725 | self.endTime = endTime | |
726 |
|
726 | |||
727 | self.inputId = '0' |
|
727 | self.inputId = '0' | |
728 | self.parentId = parentId |
|
728 | self.parentId = parentId | |
729 |
|
729 | |||
730 | self.updateRunOperation(**kwargs) |
|
730 | self.updateRunOperation(**kwargs) | |
731 |
|
731 | |||
732 | def removeOperations(self): |
|
732 | def removeOperations(self): | |
733 |
|
733 | |||
734 | for obj in self.opConfObjList: |
|
734 | for obj in self.opConfObjList: | |
735 | del obj |
|
735 | del obj | |
736 |
|
736 | |||
737 | self.opConfObjList = [] |
|
737 | self.opConfObjList = [] | |
738 |
|
738 | |||
739 | def addRunOperation(self, **kwargs): |
|
739 | def addRunOperation(self, **kwargs): | |
740 |
|
740 | |||
741 | opObj = self.addOperation(name = 'run', optype = 'self') |
|
741 | opObj = self.addOperation(name = 'run', optype = 'self') | |
742 |
|
742 | |||
743 | opObj.addParameter(name='datatype' , value=self.datatype, format='str') |
|
743 | opObj.addParameter(name='datatype' , value=self.datatype, format='str') | |
744 | opObj.addParameter(name='path' , value=self.path, format='str') |
|
744 | opObj.addParameter(name='path' , value=self.path, format='str') | |
745 | opObj.addParameter(name='startDate' , value=self.startDate, format='date') |
|
745 | opObj.addParameter(name='startDate' , value=self.startDate, format='date') | |
746 | opObj.addParameter(name='endDate' , value=self.endDate, format='date') |
|
746 | opObj.addParameter(name='endDate' , value=self.endDate, format='date') | |
747 | opObj.addParameter(name='startTime' , value=self.startTime, format='time') |
|
747 | opObj.addParameter(name='startTime' , value=self.startTime, format='time') | |
748 | opObj.addParameter(name='endTime' , value=self.endTime, format='time') |
|
748 | opObj.addParameter(name='endTime' , value=self.endTime, format='time') | |
749 |
|
749 | |||
750 | for key, value in kwargs.items(): |
|
750 | for key, value in kwargs.items(): | |
751 | opObj.addParameter(name=key, value=value, format=type(value).__name__) |
|
751 | opObj.addParameter(name=key, value=value, format=type(value).__name__) | |
752 |
|
752 | |||
753 | return opObj |
|
753 | return opObj | |
754 |
|
754 | |||
755 | def updateRunOperation(self, **kwargs): |
|
755 | def updateRunOperation(self, **kwargs): | |
756 |
|
756 | |||
757 | opObj = self.getOperationObj(name = 'run') |
|
757 | opObj = self.getOperationObj(name = 'run') | |
758 | opObj.removeParameters() |
|
758 | opObj.removeParameters() | |
759 |
|
759 | |||
760 | opObj.addParameter(name='datatype' , value=self.datatype, format='str') |
|
760 | opObj.addParameter(name='datatype' , value=self.datatype, format='str') | |
761 | opObj.addParameter(name='path' , value=self.path, format='str') |
|
761 | opObj.addParameter(name='path' , value=self.path, format='str') | |
762 | opObj.addParameter(name='startDate' , value=self.startDate, format='date') |
|
762 | opObj.addParameter(name='startDate' , value=self.startDate, format='date') | |
763 | opObj.addParameter(name='endDate' , value=self.endDate, format='date') |
|
763 | opObj.addParameter(name='endDate' , value=self.endDate, format='date') | |
764 | opObj.addParameter(name='startTime' , value=self.startTime, format='time') |
|
764 | opObj.addParameter(name='startTime' , value=self.startTime, format='time') | |
765 | opObj.addParameter(name='endTime' , value=self.endTime, format='time') |
|
765 | opObj.addParameter(name='endTime' , value=self.endTime, format='time') | |
766 |
|
766 | |||
767 | for key, value in kwargs.items(): |
|
767 | for key, value in kwargs.items(): | |
768 | opObj.addParameter(name=key, value=value, format=type(value).__name__) |
|
768 | opObj.addParameter(name=key, value=value, format=type(value).__name__) | |
769 |
|
769 | |||
770 | return opObj |
|
770 | return opObj | |
771 |
|
771 | |||
772 | # def makeXml(self, projectElement): |
|
772 | # def makeXml(self, projectElement): | |
773 | # |
|
773 | # | |
774 | # procUnitElement = SubElement(projectElement, self.ELEMENTNAME) |
|
774 | # procUnitElement = SubElement(projectElement, self.ELEMENTNAME) | |
775 | # procUnitElement.set('id', str(self.id)) |
|
775 | # procUnitElement.set('id', str(self.id)) | |
776 | # procUnitElement.set('name', self.name) |
|
776 | # procUnitElement.set('name', self.name) | |
777 | # procUnitElement.set('datatype', self.datatype) |
|
777 | # procUnitElement.set('datatype', self.datatype) | |
778 | # procUnitElement.set('inputId', str(self.inputId)) |
|
778 | # procUnitElement.set('inputId', str(self.inputId)) | |
779 | # |
|
779 | # | |
780 | # for opConfObj in self.opConfObjList: |
|
780 | # for opConfObj in self.opConfObjList: | |
781 | # opConfObj.makeXml(procUnitElement) |
|
781 | # opConfObj.makeXml(procUnitElement) | |
782 |
|
782 | |||
783 | def readXml(self, upElement): |
|
783 | def readXml(self, upElement): | |
784 |
|
784 | |||
785 | self.id = upElement.get('id') |
|
785 | self.id = upElement.get('id') | |
786 | self.name = upElement.get('name') |
|
786 | self.name = upElement.get('name') | |
787 | self.datatype = upElement.get('datatype') |
|
787 | self.datatype = upElement.get('datatype') | |
788 | self.inputId = upElement.get('inputId') |
|
788 | self.inputId = upElement.get('inputId') | |
789 |
|
789 | |||
790 | if self.ELEMENTNAME == "ReadUnit": |
|
790 | if self.ELEMENTNAME == "ReadUnit": | |
791 | self.datatype = self.datatype.replace("Reader", "") |
|
791 | self.datatype = self.datatype.replace("Reader", "") | |
792 |
|
792 | |||
793 | if self.inputId == 'None': |
|
793 | if self.inputId == 'None': | |
794 | self.inputId = '0' |
|
794 | self.inputId = '0' | |
795 |
|
795 | |||
796 | self.opConfObjList = [] |
|
796 | self.opConfObjList = [] | |
797 |
|
797 | |||
798 | opElementList = upElement.getiterator(OperationConf().getElementName()) |
|
798 | opElementList = upElement.getiterator(OperationConf().getElementName()) | |
799 |
|
799 | |||
800 | for opElement in opElementList: |
|
800 | for opElement in opElementList: | |
801 | opConfObj = OperationConf() |
|
801 | opConfObj = OperationConf() | |
802 | opConfObj.readXml(opElement) |
|
802 | opConfObj.readXml(opElement) | |
803 | self.opConfObjList.append(opConfObj) |
|
803 | self.opConfObjList.append(opConfObj) | |
804 |
|
804 | |||
805 | if opConfObj.name == 'run': |
|
805 | if opConfObj.name == 'run': | |
806 | self.path = opConfObj.getParameterValue('path') |
|
806 | self.path = opConfObj.getParameterValue('path') | |
807 | self.startDate = opConfObj.getParameterValue('startDate') |
|
807 | self.startDate = opConfObj.getParameterValue('startDate') | |
808 | self.endDate = opConfObj.getParameterValue('endDate') |
|
808 | self.endDate = opConfObj.getParameterValue('endDate') | |
809 | self.startTime = opConfObj.getParameterValue('startTime') |
|
809 | self.startTime = opConfObj.getParameterValue('startTime') | |
810 | self.endTime = opConfObj.getParameterValue('endTime') |
|
810 | self.endTime = opConfObj.getParameterValue('endTime') | |
811 |
|
811 | |||
812 | class Project(): |
|
812 | class Project(): | |
813 |
|
813 | |||
814 | id = None |
|
814 | id = None | |
815 | name = None |
|
815 | name = None | |
816 | description = None |
|
816 | description = None | |
817 | filename = None |
|
817 | filename = None | |
818 |
|
818 | |||
819 | procUnitConfObjDict = None |
|
819 | procUnitConfObjDict = None | |
820 |
|
820 | |||
821 | ELEMENTNAME = 'Project' |
|
821 | ELEMENTNAME = 'Project' | |
822 |
|
822 | |||
823 | __plotterQueue = None |
|
823 | __plotterQueue = None | |
824 |
|
824 | |||
825 |
def __init__(self, filename= |
|
825 | def __init__(self, filename=None, plotter_queue=None): | |
826 |
|
826 | |||
827 | self.id = None |
|
827 | self.id = None | |
828 | self.name = None |
|
828 | self.name = None | |
829 | self.description = None |
|
829 | self.description = None | |
830 |
|
830 | |||
831 | self.filename = filename |
|
831 | self.filename = filename | |
832 | self.__plotterQueue = plotter_queue |
|
832 | self.__plotterQueue = plotter_queue | |
833 |
|
833 | |||
834 | self.procUnitConfObjDict = {} |
|
834 | self.procUnitConfObjDict = {} | |
835 |
|
835 | |||
836 | def __getNewId(self): |
|
836 | def __getNewId(self): | |
837 |
|
837 | |||
838 | id = int(self.id)*10 + len(self.procUnitConfObjDict) + 1 |
|
838 | id = int(self.id)*10 + len(self.procUnitConfObjDict) + 1 | |
839 |
|
839 | |||
840 | return str(id) |
|
840 | return str(id) | |
841 |
|
841 | |||
842 | def getElementName(self): |
|
842 | def getElementName(self): | |
843 |
|
843 | |||
844 | return self.ELEMENTNAME |
|
844 | return self.ELEMENTNAME | |
845 |
|
845 | |||
846 | def getId(self): |
|
846 | def getId(self): | |
847 |
|
847 | |||
848 | return self.id |
|
848 | return self.id | |
849 |
|
849 | |||
850 | def updateId(self, new_id): |
|
850 | def updateId(self, new_id): | |
851 |
|
851 | |||
852 | self.id = str(new_id) |
|
852 | self.id = str(new_id) | |
853 |
|
853 | |||
854 | keyList = self.procUnitConfObjDict.keys() |
|
854 | keyList = self.procUnitConfObjDict.keys() | |
855 | keyList.sort() |
|
855 | keyList.sort() | |
856 |
|
856 | |||
857 | n = 1 |
|
857 | n = 1 | |
858 | newProcUnitConfObjDict = {} |
|
858 | newProcUnitConfObjDict = {} | |
859 |
|
859 | |||
860 | for procKey in keyList: |
|
860 | for procKey in keyList: | |
861 |
|
861 | |||
862 | procUnitConfObj = self.procUnitConfObjDict[procKey] |
|
862 | procUnitConfObj = self.procUnitConfObjDict[procKey] | |
863 | idProcUnit = str(int(self.id)*10 + n) |
|
863 | idProcUnit = str(int(self.id)*10 + n) | |
864 | procUnitConfObj.updateId(idProcUnit, parentId = self.id) |
|
864 | procUnitConfObj.updateId(idProcUnit, parentId = self.id) | |
865 |
|
865 | |||
866 | newProcUnitConfObjDict[idProcUnit] = procUnitConfObj |
|
866 | newProcUnitConfObjDict[idProcUnit] = procUnitConfObj | |
867 | n += 1 |
|
867 | n += 1 | |
868 |
|
868 | |||
869 | self.procUnitConfObjDict = newProcUnitConfObjDict |
|
869 | self.procUnitConfObjDict = newProcUnitConfObjDict | |
870 |
|
870 | |||
871 | def setup(self, id, name, description): |
|
871 | def setup(self, id, name, description): | |
872 |
|
872 | |||
873 | self.id = str(id) |
|
873 | self.id = str(id) | |
874 | self.name = name |
|
874 | self.name = name | |
875 | self.description = description |
|
875 | self.description = description | |
876 |
|
876 | |||
877 | def update(self, name, description): |
|
877 | def update(self, name, description): | |
878 |
|
878 | |||
879 | self.name = name |
|
879 | self.name = name | |
880 | self.description = description |
|
880 | self.description = description | |
881 |
|
881 | |||
882 | def addReadUnit(self, id=None, datatype=None, name=None, **kwargs): |
|
882 | def addReadUnit(self, id=None, datatype=None, name=None, **kwargs): | |
883 |
|
883 | |||
884 | if id is None: |
|
884 | if id is None: | |
885 | idReadUnit = self.__getNewId() |
|
885 | idReadUnit = self.__getNewId() | |
886 | else: |
|
886 | else: | |
887 | idReadUnit = str(id) |
|
887 | idReadUnit = str(id) | |
888 |
|
888 | |||
889 | readUnitConfObj = ReadUnitConf() |
|
889 | readUnitConfObj = ReadUnitConf() | |
890 | readUnitConfObj.setup(idReadUnit, name, datatype, parentId=self.id, **kwargs) |
|
890 | readUnitConfObj.setup(idReadUnit, name, datatype, parentId=self.id, **kwargs) | |
891 |
|
891 | |||
892 | self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj |
|
892 | self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj | |
893 |
|
893 | |||
894 | return readUnitConfObj |
|
894 | return readUnitConfObj | |
895 |
|
895 | |||
896 | def addProcUnit(self, inputId='0', datatype=None, name=None): |
|
896 | def addProcUnit(self, inputId='0', datatype=None, name=None): | |
897 |
|
897 | |||
898 | idProcUnit = self.__getNewId() |
|
898 | idProcUnit = self.__getNewId() | |
899 |
|
899 | |||
900 | procUnitConfObj = ProcUnitConf() |
|
900 | procUnitConfObj = ProcUnitConf() | |
901 | procUnitConfObj.setup(idProcUnit, name, datatype, inputId, parentId=self.id) |
|
901 | procUnitConfObj.setup(idProcUnit, name, datatype, inputId, parentId=self.id) | |
902 |
|
902 | |||
903 | self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj |
|
903 | self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj | |
904 |
|
904 | |||
905 | return procUnitConfObj |
|
905 | return procUnitConfObj | |
906 |
|
906 | |||
907 | def removeProcUnit(self, id): |
|
907 | def removeProcUnit(self, id): | |
908 |
|
908 | |||
909 | if id in self.procUnitConfObjDict.keys(): |
|
909 | if id in self.procUnitConfObjDict.keys(): | |
910 | self.procUnitConfObjDict.pop(id) |
|
910 | self.procUnitConfObjDict.pop(id) | |
911 |
|
911 | |||
912 | def getReadUnitId(self): |
|
912 | def getReadUnitId(self): | |
913 |
|
913 | |||
914 | readUnitConfObj = self.getReadUnitObj() |
|
914 | readUnitConfObj = self.getReadUnitObj() | |
915 |
|
915 | |||
916 | return readUnitConfObj.id |
|
916 | return readUnitConfObj.id | |
917 |
|
917 | |||
918 | def getReadUnitObj(self): |
|
918 | def getReadUnitObj(self): | |
919 |
|
919 | |||
920 | for obj in self.procUnitConfObjDict.values(): |
|
920 | for obj in self.procUnitConfObjDict.values(): | |
921 | if obj.getElementName() == "ReadUnit": |
|
921 | if obj.getElementName() == "ReadUnit": | |
922 | return obj |
|
922 | return obj | |
923 |
|
923 | |||
924 | return None |
|
924 | return None | |
925 |
|
925 | |||
926 | def getProcUnitObj(self, id=None, name=None): |
|
926 | def getProcUnitObj(self, id=None, name=None): | |
927 |
|
927 | |||
928 | if id != None: |
|
928 | if id != None: | |
929 | return self.procUnitConfObjDict[id] |
|
929 | return self.procUnitConfObjDict[id] | |
930 |
|
930 | |||
931 | if name != None: |
|
931 | if name != None: | |
932 | return self.getProcUnitObjByName(name) |
|
932 | return self.getProcUnitObjByName(name) | |
933 |
|
933 | |||
934 | return None |
|
934 | return None | |
935 |
|
935 | |||
936 | def getProcUnitObjByName(self, name): |
|
936 | def getProcUnitObjByName(self, name): | |
937 |
|
937 | |||
938 | for obj in self.procUnitConfObjDict.values(): |
|
938 | for obj in self.procUnitConfObjDict.values(): | |
939 | if obj.name == name: |
|
939 | if obj.name == name: | |
940 | return obj |
|
940 | return obj | |
941 |
|
941 | |||
942 | return None |
|
942 | return None | |
943 |
|
943 | |||
944 | def procUnitItems(self): |
|
944 | def procUnitItems(self): | |
945 |
|
945 | |||
946 | return self.procUnitConfObjDict.items() |
|
946 | return self.procUnitConfObjDict.items() | |
947 |
|
947 | |||
948 | def makeXml(self): |
|
948 | def makeXml(self): | |
949 |
|
949 | |||
950 | projectElement = Element('Project') |
|
950 | projectElement = Element('Project') | |
951 | projectElement.set('id', str(self.id)) |
|
951 | projectElement.set('id', str(self.id)) | |
952 | projectElement.set('name', self.name) |
|
952 | projectElement.set('name', self.name) | |
953 | projectElement.set('description', self.description) |
|
953 | projectElement.set('description', self.description) | |
954 |
|
954 | |||
955 | for procUnitConfObj in self.procUnitConfObjDict.values(): |
|
955 | for procUnitConfObj in self.procUnitConfObjDict.values(): | |
956 | procUnitConfObj.makeXml(projectElement) |
|
956 | procUnitConfObj.makeXml(projectElement) | |
957 |
|
957 | |||
958 | self.projectElement = projectElement |
|
958 | self.projectElement = projectElement | |
959 |
|
959 | |||
960 | def writeXml(self, filename): |
|
960 | def writeXml(self, filename=None): | |
961 |
|
961 | |||
|
962 | if filename == None: | |||
|
963 | filename = self.filename | |||
|
964 | ||||
|
965 | if not filename: | |||
|
966 | print "filename has not been defined. Use setFilename(filename) for do it." | |||
|
967 | return 0 | |||
|
968 | ||||
962 | abs_file = os.path.abspath(filename) |
|
969 | abs_file = os.path.abspath(filename) | |
963 |
|
970 | |||
964 | if not os.access(os.path.dirname(abs_file), os.W_OK): |
|
971 | if not os.access(os.path.dirname(abs_file), os.W_OK): | |
965 | print "No write permission on %s" %os.path.dirname(abs_file) |
|
972 | print "No write permission on %s" %os.path.dirname(abs_file) | |
966 | return 0 |
|
973 | return 0 | |
967 |
|
974 | |||
968 | if os.path.isfile(abs_file) and not(os.access(abs_file, os.W_OK)): |
|
975 | if os.path.isfile(abs_file) and not(os.access(abs_file, os.W_OK)): | |
969 | print "File %s already exists and it could not be overwriten" %abs_file |
|
976 | print "File %s already exists and it could not be overwriten" %abs_file | |
970 | return 0 |
|
977 | return 0 | |
971 |
|
978 | |||
972 | self.makeXml() |
|
979 | self.makeXml() | |
973 |
|
980 | |||
974 | ElementTree(self.projectElement).write(abs_file, method='xml') |
|
981 | ElementTree(self.projectElement).write(abs_file, method='xml') | |
975 |
|
982 | |||
976 | self.filename = abs_file |
|
|||
977 |
|
||||
978 | return 1 |
|
983 | return 1 | |
979 |
|
984 | |||
980 | def readXml(self, filename): |
|
985 | def readXml(self, filename = None): | |
981 |
|
986 | |||
|
987 | if filename == None: | |||
|
988 | filename = self.filename | |||
|
989 | ||||
982 | abs_file = os.path.abspath(filename) |
|
990 | abs_file = os.path.abspath(filename) | |
983 |
|
991 | |||
984 | if not os.path.isfile(abs_file): |
|
992 | if not os.path.isfile(abs_file): | |
985 | print "%s does not exist" %abs_file |
|
993 | print "%s does not exist" %abs_file | |
986 | return 0 |
|
994 | return 0 | |
987 |
|
995 | |||
988 | self.projectElement = None |
|
996 | self.projectElement = None | |
989 | self.procUnitConfObjDict = {} |
|
997 | self.procUnitConfObjDict = {} | |
990 |
|
998 | |||
991 | self.projectElement = ElementTree().parse(abs_file) |
|
999 | self.projectElement = ElementTree().parse(abs_file) | |
992 |
|
1000 | |||
993 | self.project = self.projectElement.tag |
|
1001 | self.project = self.projectElement.tag | |
994 |
|
1002 | |||
995 | self.id = self.projectElement.get('id') |
|
1003 | self.id = self.projectElement.get('id') | |
996 | self.name = self.projectElement.get('name') |
|
1004 | self.name = self.projectElement.get('name') | |
997 | self.description = self.projectElement.get('description') |
|
1005 | self.description = self.projectElement.get('description') | |
998 |
|
1006 | |||
999 | readUnitElementList = self.projectElement.getiterator(ReadUnitConf().getElementName()) |
|
1007 | readUnitElementList = self.projectElement.getiterator(ReadUnitConf().getElementName()) | |
1000 |
|
1008 | |||
1001 | for readUnitElement in readUnitElementList: |
|
1009 | for readUnitElement in readUnitElementList: | |
1002 | readUnitConfObj = ReadUnitConf() |
|
1010 | readUnitConfObj = ReadUnitConf() | |
1003 | readUnitConfObj.readXml(readUnitElement) |
|
1011 | readUnitConfObj.readXml(readUnitElement) | |
1004 |
|
1012 | |||
1005 | if readUnitConfObj.parentId == None: |
|
1013 | if readUnitConfObj.parentId == None: | |
1006 | readUnitConfObj.parentId = self.id |
|
1014 | readUnitConfObj.parentId = self.id | |
1007 |
|
1015 | |||
1008 | self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj |
|
1016 | self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj | |
1009 |
|
1017 | |||
1010 | procUnitElementList = self.projectElement.getiterator(ProcUnitConf().getElementName()) |
|
1018 | procUnitElementList = self.projectElement.getiterator(ProcUnitConf().getElementName()) | |
1011 |
|
1019 | |||
1012 | for procUnitElement in procUnitElementList: |
|
1020 | for procUnitElement in procUnitElementList: | |
1013 | procUnitConfObj = ProcUnitConf() |
|
1021 | procUnitConfObj = ProcUnitConf() | |
1014 | procUnitConfObj.readXml(procUnitElement) |
|
1022 | procUnitConfObj.readXml(procUnitElement) | |
1015 |
|
1023 | |||
1016 | if procUnitConfObj.parentId == None: |
|
1024 | if procUnitConfObj.parentId == None: | |
1017 | procUnitConfObj.parentId = self.id |
|
1025 | procUnitConfObj.parentId = self.id | |
1018 |
|
1026 | |||
1019 | self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj |
|
1027 | self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj | |
1020 |
|
1028 | |||
|
1029 | if self.filename == None: | |||
|
1030 | self.filename = abs_file | |||
|
1031 | ||||
1021 | return 1 |
|
1032 | return 1 | |
1022 |
|
1033 | |||
1023 | def printattr(self): |
|
1034 | def printattr(self): | |
1024 |
|
1035 | |||
1025 | print "Project[%s]: name = %s, description = %s" %(self.id, |
|
1036 | print "Project[%s]: name = %s, description = %s" %(self.id, | |
1026 | self.name, |
|
1037 | self.name, | |
1027 | self.description) |
|
1038 | self.description) | |
1028 |
|
1039 | |||
1029 | for procUnitConfObj in self.procUnitConfObjDict.values(): |
|
1040 | for procUnitConfObj in self.procUnitConfObjDict.values(): | |
1030 | procUnitConfObj.printattr() |
|
1041 | procUnitConfObj.printattr() | |
1031 |
|
1042 | |||
1032 | def createObjects(self): |
|
1043 | def createObjects(self): | |
1033 |
|
1044 | |||
1034 | for procUnitConfObj in self.procUnitConfObjDict.values(): |
|
1045 | for procUnitConfObj in self.procUnitConfObjDict.values(): | |
1035 | procUnitConfObj.createObjects(self.__plotterQueue) |
|
1046 | procUnitConfObj.createObjects(self.__plotterQueue) | |
1036 |
|
1047 | |||
1037 | def __connect(self, objIN, thisObj): |
|
1048 | def __connect(self, objIN, thisObj): | |
1038 |
|
1049 | |||
1039 | thisObj.setInput(objIN.getOutputObj()) |
|
1050 | thisObj.setInput(objIN.getOutputObj()) | |
1040 |
|
1051 | |||
1041 | def connectObjects(self): |
|
1052 | def connectObjects(self): | |
1042 |
|
1053 | |||
1043 | for thisPUConfObj in self.procUnitConfObjDict.values(): |
|
1054 | for thisPUConfObj in self.procUnitConfObjDict.values(): | |
1044 |
|
1055 | |||
1045 | inputId = thisPUConfObj.getInputId() |
|
1056 | inputId = thisPUConfObj.getInputId() | |
1046 |
|
1057 | |||
1047 | if int(inputId) == 0: |
|
1058 | if int(inputId) == 0: | |
1048 | continue |
|
1059 | continue | |
1049 |
|
1060 | |||
1050 | #Get input object |
|
1061 | #Get input object | |
1051 | puConfINObj = self.procUnitConfObjDict[inputId] |
|
1062 | puConfINObj = self.procUnitConfObjDict[inputId] | |
1052 | puObjIN = puConfINObj.getProcUnitObj() |
|
1063 | puObjIN = puConfINObj.getProcUnitObj() | |
1053 |
|
1064 | |||
1054 | #Get current object |
|
1065 | #Get current object | |
1055 | thisPUObj = thisPUConfObj.getProcUnitObj() |
|
1066 | thisPUObj = thisPUConfObj.getProcUnitObj() | |
1056 |
|
1067 | |||
1057 | self.__connect(puObjIN, thisPUObj) |
|
1068 | self.__connect(puObjIN, thisPUObj) | |
1058 |
|
1069 | |||
1059 | def __handleError(self, procUnitConfObj): |
|
1070 | def __handleError(self, procUnitConfObj): | |
1060 |
|
1071 | |||
1061 | import socket |
|
1072 | import socket | |
1062 |
|
1073 | |||
1063 | err = traceback.format_exception(sys.exc_info()[0], |
|
1074 | err = traceback.format_exception(sys.exc_info()[0], | |
1064 | sys.exc_info()[1], |
|
1075 | sys.exc_info()[1], | |
1065 | sys.exc_info()[2]) |
|
1076 | sys.exc_info()[2]) | |
1066 |
|
1077 | |||
1067 | subject = "SChain v%s: Error running %s\n" %(schainpy.__version__, procUnitConfObj.name) |
|
1078 | subject = "SChain v%s: Error running %s\n" %(schainpy.__version__, procUnitConfObj.name) | |
1068 |
|
1079 | |||
1069 | subtitle = "%s: %s\n" %(procUnitConfObj.getElementName() ,procUnitConfObj.name) |
|
1080 | subtitle = "%s: %s\n" %(procUnitConfObj.getElementName() ,procUnitConfObj.name) | |
1070 | subtitle += "Hostname: %s\n" %socket.gethostbyname(socket.gethostname()) |
|
1081 | subtitle += "Hostname: %s\n" %socket.gethostbyname(socket.gethostname()) | |
1071 | subtitle += "Working directory: %s\n" %os.path.abspath("./") |
|
1082 | subtitle += "Working directory: %s\n" %os.path.abspath("./") | |
1072 | subtitle += "Configuration file: %s\n" %self.filename |
|
1083 | subtitle += "Configuration file: %s\n" %self.filename | |
1073 | subtitle += "Time: %s\n" %str(datetime.datetime.now()) |
|
1084 | subtitle += "Time: %s\n" %str(datetime.datetime.now()) | |
1074 |
|
1085 | |||
1075 | readUnitConfObj = self.getReadUnitObj() |
|
1086 | readUnitConfObj = self.getReadUnitObj() | |
1076 | if readUnitConfObj: |
|
1087 | if readUnitConfObj: | |
1077 | subtitle += "\nInput parameters:\n" |
|
1088 | subtitle += "\nInput parameters:\n" | |
1078 | subtitle += "[Data path = %s]\n" %readUnitConfObj.path |
|
1089 | subtitle += "[Data path = %s]\n" %readUnitConfObj.path | |
1079 | subtitle += "[Data type = %s]\n" %readUnitConfObj.datatype |
|
1090 | subtitle += "[Data type = %s]\n" %readUnitConfObj.datatype | |
1080 | subtitle += "[Start date = %s]\n" %readUnitConfObj.startDate |
|
1091 | subtitle += "[Start date = %s]\n" %readUnitConfObj.startDate | |
1081 | subtitle += "[End date = %s]\n" %readUnitConfObj.endDate |
|
1092 | subtitle += "[End date = %s]\n" %readUnitConfObj.endDate | |
1082 | subtitle += "[Start time = %s]\n" %readUnitConfObj.startTime |
|
1093 | subtitle += "[Start time = %s]\n" %readUnitConfObj.startTime | |
1083 | subtitle += "[End time = %s]\n" %readUnitConfObj.endTime |
|
1094 | subtitle += "[End time = %s]\n" %readUnitConfObj.endTime | |
1084 |
|
1095 | |||
1085 | message = "".join(err) |
|
1096 | message = "".join(err) | |
1086 |
|
1097 | |||
1087 | sys.stderr.write(message) |
|
1098 | sys.stderr.write(message) | |
1088 |
|
1099 | |||
1089 | adminObj = schainpy.admin.SchainNotify() |
|
1100 | adminObj = schainpy.admin.SchainNotify() | |
1090 | adminObj.sendAlert(message=message, |
|
1101 | adminObj.sendAlert(message=message, | |
1091 | subject=subject, |
|
1102 | subject=subject, | |
1092 | subtitle=subtitle, |
|
1103 | subtitle=subtitle, | |
1093 | filename=self.filename) |
|
1104 | filename=self.filename) | |
1094 |
|
1105 | |||
1095 | def isPaused(self): |
|
1106 | def isPaused(self): | |
1096 | return 0 |
|
1107 | return 0 | |
1097 |
|
1108 | |||
1098 | def isStopped(self): |
|
1109 | def isStopped(self): | |
1099 | return 0 |
|
1110 | return 0 | |
1100 |
|
1111 | |||
1101 | def runController(self): |
|
1112 | def runController(self): | |
1102 | """ |
|
1113 | """ | |
1103 | returns 0 when this process has been stopped, 1 otherwise |
|
1114 | returns 0 when this process has been stopped, 1 otherwise | |
1104 | """ |
|
1115 | """ | |
1105 |
|
1116 | |||
1106 | if self.isPaused(): |
|
1117 | if self.isPaused(): | |
1107 | print "Process suspended" |
|
1118 | print "Process suspended" | |
1108 |
|
1119 | |||
1109 | while True: |
|
1120 | while True: | |
1110 | sleep(0.1) |
|
1121 | sleep(0.1) | |
1111 |
|
1122 | |||
1112 | if not self.isPaused(): |
|
1123 | if not self.isPaused(): | |
1113 | break |
|
1124 | break | |
1114 |
|
1125 | |||
1115 | if self.isStopped(): |
|
1126 | if self.isStopped(): | |
1116 | break |
|
1127 | break | |
1117 |
|
1128 | |||
1118 | print "Process reinitialized" |
|
1129 | print "Process reinitialized" | |
1119 |
|
1130 | |||
1120 | if self.isStopped(): |
|
1131 | if self.isStopped(): | |
1121 | print "Process stopped" |
|
1132 | print "Process stopped" | |
1122 | return 0 |
|
1133 | return 0 | |
1123 |
|
1134 | |||
1124 | return 1 |
|
1135 | return 1 | |
1125 |
|
1136 | |||
1126 | def setFilename(self, filename): |
|
1137 | def setFilename(self, filename): | |
1127 |
|
1138 | |||
1128 | self.filename = filename |
|
1139 | self.filename = filename | |
1129 |
|
1140 | |||
1130 | def setPlotterQueue(self, plotter_queue): |
|
1141 | def setPlotterQueue(self, plotter_queue): | |
1131 |
|
1142 | |||
1132 | self.__plotterQueue = plotter_queue |
|
1143 | self.__plotterQueue = plotter_queue | |
1133 |
|
1144 | |||
1134 | def getPlotterQueue(self): |
|
1145 | def getPlotterQueue(self): | |
1135 |
|
1146 | |||
1136 | return self.__plotterQueue |
|
1147 | return self.__plotterQueue | |
1137 |
|
1148 | |||
1138 | def run(self): |
|
1149 | def run(self): | |
1139 |
|
1150 | |||
1140 |
|
1151 | |||
1141 | print "*"*60 |
|
1152 | print "*"*60 | |
1142 | print " Starting SIGNAL CHAIN PROCESSING v%s " %schainpy.__version__ |
|
1153 | print " Starting SIGNAL CHAIN PROCESSING v%s " %schainpy.__version__ | |
1143 | print "*"*60 |
|
1154 | print "*"*60 | |
1144 |
|
1155 | |||
1145 |
|
1156 | |||
1146 | keyList = self.procUnitConfObjDict.keys() |
|
1157 | keyList = self.procUnitConfObjDict.keys() | |
1147 | keyList.sort() |
|
1158 | keyList.sort() | |
1148 |
|
1159 | |||
1149 | while(True): |
|
1160 | while(True): | |
1150 |
|
1161 | |||
1151 | is_ok = False |
|
1162 | is_ok = False | |
1152 |
|
1163 | |||
1153 | for procKey in keyList: |
|
1164 | for procKey in keyList: | |
1154 | # print "Running the '%s' process with %s" %(procUnitConfObj.name, procUnitConfObj.id) |
|
1165 | # print "Running the '%s' process with %s" %(procUnitConfObj.name, procUnitConfObj.id) | |
1155 |
|
1166 | |||
1156 | procUnitConfObj = self.procUnitConfObjDict[procKey] |
|
1167 | procUnitConfObj = self.procUnitConfObjDict[procKey] | |
1157 |
|
1168 | |||
1158 | try: |
|
1169 | try: | |
1159 | sts = procUnitConfObj.run() |
|
1170 | sts = procUnitConfObj.run() | |
1160 | is_ok = is_ok or sts |
|
1171 | is_ok = is_ok or sts | |
1161 | except ValueError, e: |
|
1172 | except ValueError, e: | |
1162 | print "***** Error occurred in %s *****" %(procUnitConfObj.name) |
|
1173 | print "***** Error occurred in %s *****" %(procUnitConfObj.name) | |
1163 | sleep(0.5) |
|
1174 | sleep(0.5) | |
1164 | print e |
|
1175 | print e | |
1165 | is_ok = False |
|
1176 | is_ok = False | |
1166 | break |
|
1177 | break | |
1167 | except: |
|
1178 | except: | |
1168 | print "***** Error occurred in %s *****" %(procUnitConfObj.name) |
|
1179 | print "***** Error occurred in %s *****" %(procUnitConfObj.name) | |
1169 | sleep(0.5) |
|
1180 | sleep(0.5) | |
1170 | self.__handleError(procUnitConfObj) |
|
1181 | self.__handleError(procUnitConfObj) | |
1171 | is_ok = False |
|
1182 | is_ok = False | |
1172 | break |
|
1183 | break | |
1173 |
|
1184 | |||
1174 | #If every process unit finished so end process |
|
1185 | #If every process unit finished so end process | |
1175 | if not(is_ok): |
|
1186 | if not(is_ok): | |
1176 | print "Every process unit have finished" |
|
1187 | print "Every process unit have finished" | |
1177 | break |
|
1188 | break | |
1178 |
|
1189 | |||
1179 | if not self.runController(): |
|
1190 | if not self.runController(): | |
1180 | break |
|
1191 | break | |
1181 |
|
1192 | |||
1182 | #Closing every process |
|
1193 | #Closing every process | |
1183 | for procKey in keyList: |
|
1194 | for procKey in keyList: | |
1184 | procUnitConfObj = self.procUnitConfObjDict[procKey] |
|
1195 | procUnitConfObj = self.procUnitConfObjDict[procKey] | |
1185 | procUnitConfObj.close() |
|
1196 | procUnitConfObj.close() | |
1186 |
|
1197 | |||
1187 | print "Process finished" |
|
1198 | print "Process finished" | |
1188 |
|
1199 | |||
1189 | def start(self): |
|
1200 | def start(self): | |
1190 |
|
1201 | |||
1191 |
if not self.writeXml( |
|
1202 | if not self.writeXml(): | |
1192 | return |
|
1203 | return | |
1193 |
|
1204 | |||
1194 | self.createObjects() |
|
1205 | self.createObjects() | |
1195 | self.connectObjects() |
|
1206 | self.connectObjects() | |
1196 | self.run() |
|
1207 | self.run() | |
1197 |
|
1208 | |||
1198 | if __name__ == '__main__': |
|
1209 | if __name__ == '__main__': | |
1199 |
|
1210 | |||
1200 | desc = "Segundo Test" |
|
1211 | desc = "Segundo Test" | |
1201 | filename = "schain.xml" |
|
1212 | filename = "schain.xml" | |
1202 |
|
1213 | |||
1203 | controllerObj = Project() |
|
1214 | controllerObj = Project() | |
1204 |
|
1215 | |||
1205 | controllerObj.setup(id = '191', name='test01', description=desc) |
|
1216 | controllerObj.setup(id = '191', name='test01', description=desc) | |
1206 |
|
1217 | |||
1207 | readUnitConfObj = controllerObj.addReadUnit(datatype='Voltage', |
|
1218 | readUnitConfObj = controllerObj.addReadUnit(datatype='Voltage', | |
1208 | path='data/rawdata/', |
|
1219 | path='data/rawdata/', | |
1209 | startDate='2011/01/01', |
|
1220 | startDate='2011/01/01', | |
1210 | endDate='2012/12/31', |
|
1221 | endDate='2012/12/31', | |
1211 | startTime='00:00:00', |
|
1222 | startTime='00:00:00', | |
1212 | endTime='23:59:59', |
|
1223 | endTime='23:59:59', | |
1213 | online=1, |
|
1224 | online=1, | |
1214 | walk=1) |
|
1225 | walk=1) | |
1215 |
|
1226 | |||
1216 | procUnitConfObj0 = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId()) |
|
1227 | procUnitConfObj0 = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId()) | |
1217 |
|
1228 | |||
1218 | opObj10 = procUnitConfObj0.addOperation(name='selectChannels') |
|
1229 | opObj10 = procUnitConfObj0.addOperation(name='selectChannels') | |
1219 | opObj10.addParameter(name='channelList', value='3,4,5', format='intlist') |
|
1230 | opObj10.addParameter(name='channelList', value='3,4,5', format='intlist') | |
1220 |
|
1231 | |||
1221 | opObj10 = procUnitConfObj0.addOperation(name='selectHeights') |
|
1232 | opObj10 = procUnitConfObj0.addOperation(name='selectHeights') | |
1222 | opObj10.addParameter(name='minHei', value='90', format='float') |
|
1233 | opObj10.addParameter(name='minHei', value='90', format='float') | |
1223 | opObj10.addParameter(name='maxHei', value='180', format='float') |
|
1234 | opObj10.addParameter(name='maxHei', value='180', format='float') | |
1224 |
|
1235 | |||
1225 | opObj12 = procUnitConfObj0.addOperation(name='CohInt', optype='external') |
|
1236 | opObj12 = procUnitConfObj0.addOperation(name='CohInt', optype='external') | |
1226 | opObj12.addParameter(name='n', value='10', format='int') |
|
1237 | opObj12.addParameter(name='n', value='10', format='int') | |
1227 |
|
1238 | |||
1228 | procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj0.getId()) |
|
1239 | procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj0.getId()) | |
1229 | procUnitConfObj1.addParameter(name='nFFTPoints', value='32', format='int') |
|
1240 | procUnitConfObj1.addParameter(name='nFFTPoints', value='32', format='int') | |
1230 | # procUnitConfObj1.addParameter(name='pairList', value='(0,1),(0,2),(1,2)', format='') |
|
1241 | # procUnitConfObj1.addParameter(name='pairList', value='(0,1),(0,2),(1,2)', format='') | |
1231 |
|
1242 | |||
1232 |
|
1243 | |||
1233 | opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='external') |
|
1244 | opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='external') | |
1234 | opObj11.addParameter(name='idfigure', value='1', format='int') |
|
1245 | opObj11.addParameter(name='idfigure', value='1', format='int') | |
1235 | opObj11.addParameter(name='wintitle', value='SpectraPlot0', format='str') |
|
1246 | opObj11.addParameter(name='wintitle', value='SpectraPlot0', format='str') | |
1236 | opObj11.addParameter(name='zmin', value='40', format='int') |
|
1247 | opObj11.addParameter(name='zmin', value='40', format='int') | |
1237 | opObj11.addParameter(name='zmax', value='90', format='int') |
|
1248 | opObj11.addParameter(name='zmax', value='90', format='int') | |
1238 | opObj11.addParameter(name='showprofile', value='1', format='int') |
|
1249 | opObj11.addParameter(name='showprofile', value='1', format='int') | |
1239 |
|
1250 | |||
1240 | print "Escribiendo el archivo XML" |
|
1251 | print "Escribiendo el archivo XML" | |
1241 |
|
1252 | |||
1242 | controllerObj.writeXml(filename) |
|
1253 | controllerObj.writeXml(filename) | |
1243 |
|
1254 | |||
1244 | print "Leyendo el archivo XML" |
|
1255 | print "Leyendo el archivo XML" | |
1245 | controllerObj.readXml(filename) |
|
1256 | controllerObj.readXml(filename) | |
1246 | #controllerObj.printattr() |
|
1257 | #controllerObj.printattr() | |
1247 |
|
1258 | |||
1248 | controllerObj.createObjects() |
|
1259 | controllerObj.createObjects() | |
1249 | controllerObj.connectObjects() |
|
1260 | controllerObj.connectObjects() | |
1250 | controllerObj.run() |
|
1261 | controllerObj.run() | |
1251 |
|
1262 | |||
1252 | No newline at end of file |
|
1263 |
General Comments 0
You need to be logged in to leave comments.
Login now