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