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