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