@@ -0,0 +1,346 | |||||
|
1 | """The admin module contains all administrative classes relating to the schain python api. | |||
|
2 | ||||
|
3 | The main role of this module is to send some reports. It contains a | |||
|
4 | notification class and a standard error handing class. | |||
|
5 | ||||
|
6 | $Id: admin.py 3966 2015-12-01 14:32:29Z miguel.urco $ | |||
|
7 | """ | |||
|
8 | import os | |||
|
9 | import smtplib | |||
|
10 | import ConfigParser | |||
|
11 | import StringIO | |||
|
12 | ||||
|
13 | from email.mime.text import MIMEText | |||
|
14 | from email.mime.application import MIMEApplication | |||
|
15 | from email.mime.multipart import MIMEMultipart | |||
|
16 | ||||
|
17 | class SchainConfigure(): | |||
|
18 | ||||
|
19 | __DEFAULT_SENDER_EMAIL = "notifier-schain@jro.igp.gob.pe" | |||
|
20 | __DEFAULT_ADMINISTRATOR_EMAIL = "miguel.urco@jro.igp.gob.pe" | |||
|
21 | __DEFAULT_EMAIL_SERVER = "jro-zimbra.igp.gob.pe" | |||
|
22 | ||||
|
23 | __SCHAIN_ADMINISTRATOR_EMAIL = "CONTACT" | |||
|
24 | __SCHAIN_EMAIL_SERVER = "MAILSERVER" | |||
|
25 | __SCHAIN_SENDER_EMAIL = "MAILSERVER_ACCOUNT" | |||
|
26 | ||||
|
27 | def __init__(self, initFile = None): | |||
|
28 | ||||
|
29 | # Set configuration file | |||
|
30 | if (initFile == None): | |||
|
31 | self.__confFilePath = "/etc/schain.conf" | |||
|
32 | else: | |||
|
33 | self.__confFilePath = initFile | |||
|
34 | ||||
|
35 | # open configuration file | |||
|
36 | try: | |||
|
37 | self.__confFile = open(self.__confFilePath, "r") | |||
|
38 | except IOError: | |||
|
39 | # can't read from file - use all hard-coded values | |||
|
40 | self.__initFromHardCode() | |||
|
41 | return | |||
|
42 | ||||
|
43 | # create Parser using standard module ConfigParser | |||
|
44 | self.__parser = ConfigParser.ConfigParser() | |||
|
45 | ||||
|
46 | # read conf file into a StringIO with "[madrigal]\n" section heading prepended | |||
|
47 | strConfFile = StringIO.StringIO("[schain]\n" + self.__confFile.read()) | |||
|
48 | ||||
|
49 | # parse StringIO configuration file | |||
|
50 | self.__parser.readfp(strConfFile) | |||
|
51 | ||||
|
52 | # read information from configuration file | |||
|
53 | self.__readConfFile() | |||
|
54 | ||||
|
55 | # close conf file | |||
|
56 | self.__confFile.close() | |||
|
57 | ||||
|
58 | ||||
|
59 | def __initFromHardCode(self): | |||
|
60 | ||||
|
61 | self.__sender_email = self.__DEFAULT_SENDER_EMAIL | |||
|
62 | self.__admin_email = self.__DEFAULT_ADMINISTRATOR_EMAIL | |||
|
63 | self.__email_server = self.__DEFAULT_EMAIL_SERVER | |||
|
64 | ||||
|
65 | def __readConfFile(self): | |||
|
66 | """__readConfFile is a private helper function that reads information from the parsed config file. | |||
|
67 | ||||
|
68 | Inputs: None | |||
|
69 | ||||
|
70 | Returns: Void. | |||
|
71 | ||||
|
72 | Affects: Initializes class member variables that are found in the config file. | |||
|
73 | ||||
|
74 | Exceptions: MadrigalError thrown if any key not found. | |||
|
75 | """ | |||
|
76 | ||||
|
77 | # get the sender email | |||
|
78 | try: | |||
|
79 | self.__sender_email = self.__parser.get("schain", self.__SCHAIN_SENDER_EMAIL) | |||
|
80 | except: | |||
|
81 | self.__sender_email = self.__DEFAULT_SENDER_EMAIL | |||
|
82 | ||||
|
83 | # get the administrator email | |||
|
84 | try: | |||
|
85 | self.__admin_email = self.__parser.get("schain", self.__SCHAIN_ADMINISTRATOR_EMAIL) | |||
|
86 | except: | |||
|
87 | self.__admin_email = self.__DEFAULT_ADMINISTRATOR_EMAIL | |||
|
88 | ||||
|
89 | # get the server email | |||
|
90 | try: | |||
|
91 | self.__email_server = self.__parser.get("schain", self.__SCHAIN_EMAIL_SERVER) | |||
|
92 | except: | |||
|
93 | self.__email_server = self.__DEFAULT_EMAIL_SERVER | |||
|
94 | ||||
|
95 | def getEmailServer(self): | |||
|
96 | ||||
|
97 | return self.__email_server | |||
|
98 | ||||
|
99 | def getSenderEmail(self): | |||
|
100 | ||||
|
101 | return self.__sender_email | |||
|
102 | ||||
|
103 | def getAdminEmail(self): | |||
|
104 | ||||
|
105 | return self.__admin_email | |||
|
106 | ||||
|
107 | class SchainNotify: | |||
|
108 | """SchainNotify is an object used to send messages to an administrator about a Schain software. | |||
|
109 | ||||
|
110 | This object provides functions needed to send messages to an administrator about a Schain , for now | |||
|
111 | only sendAlert, which sends an email to the site administrator found is ADMIN_EMAIL | |||
|
112 | ||||
|
113 | Usage example: | |||
|
114 | ||||
|
115 | import schainpy.admin | |||
|
116 | ||||
|
117 | try: | |||
|
118 | ||||
|
119 | adminObj = schainpy.admin.SchainNotify() | |||
|
120 | adminObj.sendAlert('This is important!', 'Important Message') | |||
|
121 | ||||
|
122 | except schainpy.admin.SchainError, e: | |||
|
123 | ||||
|
124 | print e.getExceptionStr() | |||
|
125 | ||||
|
126 | ||||
|
127 | Non-standard Python modules used: | |||
|
128 | None | |||
|
129 | ||||
|
130 | Exceptions thrown: None - Note that SchainNotify tries every trick it knows to avoid | |||
|
131 | throwing exceptions, since this is the class that will generally be called when there is a problem. | |||
|
132 | ||||
|
133 | Change history: | |||
|
134 | ||||
|
135 | Written by "Miguel Urco":mailto:miguel.urco@jro.igp.gob.pe Dec. 1, 2015 | |||
|
136 | """ | |||
|
137 | ||||
|
138 | #constants | |||
|
139 | ||||
|
140 | def __init__(self): | |||
|
141 | """__init__ initializes SchainNotify by getting some basic information from SchainDB and SchainSite. | |||
|
142 | ||||
|
143 | Note that SchainNotify tries every trick it knows to avoid throwing exceptions, since | |||
|
144 | this is the class that will generally be called when there is a problem. | |||
|
145 | ||||
|
146 | Inputs: Existing SchainDB object, by default = None. | |||
|
147 | ||||
|
148 | Returns: void | |||
|
149 | ||||
|
150 | Affects: Initializes self.__binDir. | |||
|
151 | ||||
|
152 | Exceptions: None. | |||
|
153 | """ | |||
|
154 | ||||
|
155 | # note that the main configuration file is unavailable | |||
|
156 | # the best that can be done is send an email to root using localhost mailserver | |||
|
157 | confObj = SchainConfigure() | |||
|
158 | ||||
|
159 | self.__emailFromAddress = confObj.getSenderEmail() | |||
|
160 | self.__emailToAddress = confObj.getAdminEmail() | |||
|
161 | self.__emailServer = confObj.getEmailServer() | |||
|
162 | ||||
|
163 | def sendEmail(self, email_from, email_to, subject='Error running ...', message="", subtitle="", filename="", html_format=True): | |||
|
164 | ||||
|
165 | msg = MIMEMultipart() | |||
|
166 | msg['Subject'] = subject | |||
|
167 | msg['From'] = "(Python SChain API): " + email_from | |||
|
168 | msg['Reply-to'] = email_from | |||
|
169 | msg['To'] = email_to | |||
|
170 | ||||
|
171 | # That is what u see if dont have an email reader: | |||
|
172 | msg.preamble = 'SChainPy' | |||
|
173 | ||||
|
174 | if html_format: | |||
|
175 | message = "<h1> %s </h1>" %subject + "<h3>" + subtitle.replace("\n", "</h3><h3>\n") + "</h3>" + message.replace("\n", "<br>\n") | |||
|
176 | message = "<html>\n" + message + '</html>' | |||
|
177 | ||||
|
178 | # This is the textual part: | |||
|
179 | part = MIMEText(message, "html") | |||
|
180 | else: | |||
|
181 | message = subject + "\n" + subtitle + "\n" + message | |||
|
182 | part = MIMEText(message) | |||
|
183 | ||||
|
184 | msg.attach(part) | |||
|
185 | ||||
|
186 | if os.path.isfile(filename): | |||
|
187 | # This is the binary part(The Attachment): | |||
|
188 | part = MIMEApplication(open(filename,"rb").read()) | |||
|
189 | part.add_header('Content-Disposition', | |||
|
190 | 'attachment', | |||
|
191 | filename=os.path.basename(filename)) | |||
|
192 | msg.attach(part) | |||
|
193 | ||||
|
194 | # Create an instance in SMTP server | |||
|
195 | smtp = smtplib.SMTP(self.__emailServer) | |||
|
196 | # Start the server: | |||
|
197 | # smtp.ehlo() | |||
|
198 | # smtp.login(email_from, email_from_pass) | |||
|
199 | ||||
|
200 | # Send the email | |||
|
201 | smtp.sendmail(msg['From'], msg['To'], msg.as_string()) | |||
|
202 | smtp.quit() | |||
|
203 | ||||
|
204 | ||||
|
205 | def sendAlert(self, message, subject = "", subtitle="", filename=""): | |||
|
206 | """sendAlert sends an email with the given message and optional title. | |||
|
207 | ||||
|
208 | Inputs: message (string), and optional title (string) | |||
|
209 | ||||
|
210 | Returns: void | |||
|
211 | ||||
|
212 | Affects: none | |||
|
213 | ||||
|
214 | Exceptions: None. | |||
|
215 | """ | |||
|
216 | print "***** Sending alert to %s *****" %self.__emailToAddress | |||
|
217 | # set up message | |||
|
218 | ||||
|
219 | self.sendEmail(email_from=self.__emailFromAddress, | |||
|
220 | email_to=self.__emailToAddress, | |||
|
221 | subject=subject, | |||
|
222 | message=message, | |||
|
223 | subtitle=subtitle, | |||
|
224 | filename=filename) | |||
|
225 | ||||
|
226 | print "***** Your system administrator has been notified *****" | |||
|
227 | ||||
|
228 | ||||
|
229 | def notify(self, email, message, subject = "", subtitle="", filename=""): | |||
|
230 | """notify sends an email with the given message and title to email. | |||
|
231 | ||||
|
232 | Inputs: email (string), message (string), and subject (string) | |||
|
233 | ||||
|
234 | Returns: void | |||
|
235 | ||||
|
236 | Affects: none | |||
|
237 | ||||
|
238 | Exceptions: None. | |||
|
239 | """ | |||
|
240 | ||||
|
241 | print "Notifying to %s ..." %email | |||
|
242 | ||||
|
243 | self.sendEmail(email_from=self.__emailFromAddress, | |||
|
244 | email_to=email, | |||
|
245 | subject=subject, | |||
|
246 | message=message, | |||
|
247 | subtitle=subtitle, | |||
|
248 | filename=filename) | |||
|
249 | ||||
|
250 | print "***** Your system administrator has been notified *****" | |||
|
251 | ||||
|
252 | class SchainError: | |||
|
253 | """SchainError is an exception class that is thrown for all known errors in using Schain Py lib. | |||
|
254 | ||||
|
255 | Usage example: | |||
|
256 | ||||
|
257 | import sys, traceback | |||
|
258 | import schainpy.admin | |||
|
259 | ||||
|
260 | try: | |||
|
261 | ||||
|
262 | test = open('ImportantFile.txt', 'r') | |||
|
263 | ||||
|
264 | except: | |||
|
265 | ||||
|
266 | raise schainpy.admin.SchainError('ImportantFile.txt not opened!', | |||
|
267 | traceback.format_exception(sys.exc_info()[0], | |||
|
268 | sys.exc_info()[1], | |||
|
269 | sys.exc_info()[2])) | |||
|
270 | """ | |||
|
271 | ||||
|
272 | ||||
|
273 | def __init__(self, strInterpretation, exceptionList): | |||
|
274 | """ __init__ gathers the interpretation string along with all information from sys.exc_info(). | |||
|
275 | ||||
|
276 | Inputs: strIntepretation - A string representing the programmer's interpretation of | |||
|
277 | why the exception occurred | |||
|
278 | ||||
|
279 | exceptionList - a list of strings completely describing the exception. | |||
|
280 | Generated by traceback.format_exception(sys.exc_info()[0], | |||
|
281 | sys.exc_info()[1], | |||
|
282 | sys.exc_info()[2]) | |||
|
283 | ||||
|
284 | Returns: Void. | |||
|
285 | ||||
|
286 | Affects: Initializes class member variables _strInterp, _strExcList. | |||
|
287 | ||||
|
288 | Exceptions: None. | |||
|
289 | """ | |||
|
290 | ||||
|
291 | self._strInterp = strInterpretation | |||
|
292 | self._strExcList = exceptionList | |||
|
293 | ||||
|
294 | ||||
|
295 | def getExceptionStr(self): | |||
|
296 | """ getExceptionStr returns a formatted string ready for printing completely describing the exception. | |||
|
297 | ||||
|
298 | Inputs: None | |||
|
299 | ||||
|
300 | Returns: A formatted string ready for printing completely describing the exception. | |||
|
301 | ||||
|
302 | Affects: None | |||
|
303 | ||||
|
304 | Exceptions: None. | |||
|
305 | """ | |||
|
306 | excStr = 'The following Schain Python exception has occurred:\n' | |||
|
307 | excStr = excStr + self._strInterp + '\n\n' | |||
|
308 | ||||
|
309 | if self._strExcList != None: | |||
|
310 | for item in self._strExcList: | |||
|
311 | excStr = excStr + str(item) + '\n' | |||
|
312 | ||||
|
313 | return excStr | |||
|
314 | ||||
|
315 | def __str__(self): | |||
|
316 | return(self.getExceptionStr()) | |||
|
317 | ||||
|
318 | ||||
|
319 | def getExceptionHtml(self): | |||
|
320 | """ getExceptionHtml returns an Html formatted string completely describing the exception. | |||
|
321 | ||||
|
322 | Inputs: None | |||
|
323 | ||||
|
324 | Returns: A formatted string ready for printing completely describing the exception. | |||
|
325 | ||||
|
326 | Affects: None | |||
|
327 | ||||
|
328 | Exceptions: None. | |||
|
329 | """ | |||
|
330 | ||||
|
331 | excStr = '<BR>The following Schain Python exception has occurred:\n<BR>' | |||
|
332 | excStr = excStr + self._strInterp + '\n<BR>\n' | |||
|
333 | ||||
|
334 | if self._strExcList != None: | |||
|
335 | for item in self._strExcList: | |||
|
336 | excStr = excStr + str(item) + '\n<BR>' | |||
|
337 | ||||
|
338 | return excStr | |||
|
339 | ||||
|
340 | if __name__ == '__main__': | |||
|
341 | ||||
|
342 | test = SchainNotify() | |||
|
343 | ||||
|
344 | test.sendAlert('This is a message from the python module SchainNotify', 'Test from SchainNotify') | |||
|
345 | ||||
|
346 | print 'Hopefully message sent - check.' |
@@ -0,0 +1,5 | |||||
|
1 | #Copy this file to /etc/schain.conf | |||
|
2 | [schain] | |||
|
3 | CONTACT = miguel.urco@jro.igp.gob.pe | |||
|
4 | MAILSERVER = jro-zimbra.igp.gob.pe | |||
|
5 | MALSERVER_ACCOUNT = notifier-schain@jro.igp.gob.pe No newline at end of file |
@@ -1,26 +1,29 | |||||
1 | VERSIONS: |
|
1 | VERSIONS: | |
2 |
|
2 | |||
3 | 2.1.2: |
|
3 | 2.1.2: | |
4 | -jroutils_ftp.py: Bug fixed, Any error sending file stopped the Server Thread |
|
4 | -jroutils_ftp.py: Bug fixed, Any error sending file stopped the Server Thread | |
5 | Server thread opens and closes remote server each time file list is sent |
|
5 | Server thread opens and closes remote server each time file list is sent | |
6 | -jroplot_spectra.py: Noise path was not being created saving noise data. |
|
6 | -jroplot_spectra.py: Noise path was not being created saving noise data. | |
7 | -jroIO_base.py: startTime can be greater than endTime |
|
7 | -jroIO_base.py: startTime can be greater than endTime | |
8 |
|
8 | |||
9 | 2.1.3: |
|
9 | 2.1.3: | |
10 | -jroplot_heispectra.py: SpectraHeisScope was not showing the right channels |
|
10 | -jroplot_heispectra.py: SpectraHeisScope was not showing the right channels | |
11 | -jroproc_voltage.py: Bug fixed selecting profiles (self.nProfiles took a wrong value), |
|
11 | -jroproc_voltage.py: Bug fixed selecting profiles (self.nProfiles took a wrong value), | |
12 | Bug fixed selecting heights by block (selecting profiles instead heights) |
|
12 | Bug fixed selecting heights by block (selecting profiles instead heights) | |
13 | -jroproc_voltage.py: New feature added: decoding data by block using FFT. |
|
13 | -jroproc_voltage.py: New feature added: decoding data by block using FFT. | |
14 | -jroIO_heispectra.py: Bug fixed in FitsReader. Using local Fits object instead schainpy.mode.data.jrodata.Fits object. |
|
14 | -jroIO_heispectra.py: Bug fixed in FitsReader. Using local Fits object instead schainpy.mode.data.jrodata.Fits object. | |
15 | -jroIO_heispectra.py: Channel index list does not exist. |
|
15 | -jroIO_heispectra.py: Channel index list does not exist. | |
16 |
|
16 | |||
17 | 2.1.3.1: |
|
17 | 2.1.3.1: | |
18 | -GUI: every icon were resized |
|
18 | -GUI: every icon were resized | |
19 | -jroproc_voltage.py: Print a message when "Read from code" option is selected and the code is not defined inside data file |
|
19 | -jroproc_voltage.py: Print a message when "Read from code" option is selected and the code is not defined inside data file | |
20 |
|
20 | |||
21 | 2.1.3.2: |
|
21 | 2.1.3.2: | |
22 | -GUI: user interaction enhanced |
|
22 | -GUI: user interaction enhanced | |
23 | -controller_api.py: Safe access to ControllerThead |
|
23 | -controller_api.py: Safe access to ControllerThead | |
24 |
|
24 | |||
25 | 2.1.3.3: |
|
25 | 2.1.3.3: | |
26 | -Colored Button Icons were added to GUI No newline at end of file |
|
26 | -Colored Button Icons were added to GUI | |
|
27 | ||||
|
28 | 2.1.4: | |||
|
29 | -Sending error notifications to signal chain administrator No newline at end of file |
@@ -1,7 +1,7 | |||||
1 | ''' |
|
1 | ''' | |
2 | Created on Feb 7, 2012 |
|
2 | Created on Feb 7, 2012 | |
3 |
|
3 | |||
4 | @author $Author$ |
|
4 | @author $Author$ | |
5 | @version $Id$ |
|
5 | @version $Id$ | |
6 | ''' |
|
6 | ''' | |
7 |
__version__ = "2.1. |
|
7 | __version__ = "2.1.4" No newline at end of file |
@@ -1,1150 +1,1206 | |||||
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 |
|
|||
6 | from xml.dom import minidom |
|
|||
7 |
|
||||
8 | from model import * |
|
|||
9 | from time import sleep |
|
|||
10 |
|
5 | |||
11 | import sys |
|
6 | import sys | |
12 | import ast |
|
7 | import ast | |
13 | import traceback |
|
8 | import traceback | |
|
9 | import schainpy | |||
|
10 | import schainpy.admin | |||
14 |
|
11 | |||
15 | SCHAIN_MAIL = "miguel.urco@jro.igp.gob.pe" |
|
12 | from xml.etree.ElementTree import ElementTree, Element, SubElement, tostring | |
16 | EMAIL_SERVER = "jro.igp.gob.pe" |
|
13 | from xml.dom import minidom | |
|
14 | ||||
|
15 | from schainpy.model import * | |||
|
16 | from time import sleep | |||
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, |
|
328 | def makeXml(self, procUnitElement): | |
329 |
|
329 | |||
330 |
opElement = SubElement( |
|
330 | opElement = SubElement(procUnitElement, 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, proc |
|
542 | def makeXml(self, projectElement): | |
543 |
|
543 | |||
544 |
|
|
544 | procUnitElement = SubElement(projectElement, self.ELEMENTNAME) | |
545 |
|
|
545 | procUnitElement.set('id', str(self.id)) | |
546 |
|
|
546 | procUnitElement.set('name', self.name) | |
547 |
|
|
547 | procUnitElement.set('datatype', self.datatype) | |
548 |
|
|
548 | procUnitElement.set('inputId', str(self.inputId)) | |
549 |
|
549 | |||
550 | for opConfObj in self.opConfObjList: |
|
550 | for opConfObj in self.opConfObjList: | |
551 |
opConfObj.makeXml( |
|
551 | opConfObj.makeXml(procUnitElement) | |
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 | # def makeXml(self, projectElement): | |||
|
761 | # | |||
|
762 | # procUnitElement = SubElement(projectElement, self.ELEMENTNAME) | |||
|
763 | # procUnitElement.set('id', str(self.id)) | |||
|
764 | # procUnitElement.set('name', self.name) | |||
|
765 | # procUnitElement.set('datatype', self.datatype) | |||
|
766 | # procUnitElement.set('inputId', str(self.inputId)) | |||
|
767 | # | |||
|
768 | # for opConfObj in self.opConfObjList: | |||
|
769 | # opConfObj.makeXml(procUnitElement) | |||
|
770 | ||||
|
771 | def readXml(self, upElement): | |||
|
772 | ||||
|
773 | self.id = upElement.get('id') | |||
|
774 | self.name = upElement.get('name') | |||
|
775 | self.datatype = upElement.get('datatype') | |||
|
776 | self.inputId = upElement.get('inputId') | |||
|
777 | ||||
|
778 | if self.ELEMENTNAME == "ReadUnit": | |||
|
779 | self.datatype = self.datatype.replace("Reader", "") | |||
|
780 | ||||
|
781 | if self.inputId == 'None': | |||
|
782 | self.inputId = '0' | |||
|
783 | ||||
|
784 | self.opConfObjList = [] | |||
|
785 | ||||
|
786 | opElementList = upElement.getiterator(OperationConf().getElementName()) | |||
|
787 | ||||
|
788 | for opElement in opElementList: | |||
|
789 | opConfObj = OperationConf() | |||
|
790 | opConfObj.readXml(opElement) | |||
|
791 | self.opConfObjList.append(opConfObj) | |||
|
792 | ||||
|
793 | if opConfObj.name == 'run': | |||
|
794 | self.path = opConfObj.getParameterValue('path') | |||
|
795 | self.startDate = opConfObj.getParameterValue('startDate') | |||
|
796 | self.endDate = opConfObj.getParameterValue('endDate') | |||
|
797 | self.startTime = opConfObj.getParameterValue('startTime') | |||
|
798 | self.endTime = opConfObj.getParameterValue('endTime') | |||
|
799 | ||||
760 | class Project(): |
|
800 | class Project(): | |
761 |
|
801 | |||
762 | id = None |
|
802 | id = None | |
763 | name = None |
|
803 | name = None | |
764 | description = None |
|
804 | description = None | |
765 | # readUnitConfObjList = None |
|
805 | filename = None | |
|
806 | ||||
766 | procUnitConfObjDict = None |
|
807 | procUnitConfObjDict = None | |
767 |
|
808 | |||
768 | ELEMENTNAME = 'Project' |
|
809 | ELEMENTNAME = 'Project' | |
769 |
|
810 | |||
770 | def __init__(self): |
|
811 | def __init__(self): | |
771 |
|
812 | |||
772 | self.id = None |
|
813 | self.id = None | |
773 | self.name = None |
|
814 | self.name = None | |
774 | self.description = None |
|
815 | self.description = None | |
775 |
|
816 | |||
776 | self.procUnitConfObjDict = {} |
|
817 | self.procUnitConfObjDict = {} | |
777 |
|
818 | |||
778 | def __getNewId(self): |
|
819 | def __getNewId(self): | |
779 |
|
820 | |||
780 | id = int(self.id)*10 + len(self.procUnitConfObjDict) + 1 |
|
821 | id = int(self.id)*10 + len(self.procUnitConfObjDict) + 1 | |
781 |
|
822 | |||
782 | return str(id) |
|
823 | return str(id) | |
783 |
|
824 | |||
784 | def getElementName(self): |
|
825 | def getElementName(self): | |
785 |
|
826 | |||
786 | return self.ELEMENTNAME |
|
827 | return self.ELEMENTNAME | |
787 |
|
828 | |||
788 | def getId(self): |
|
829 | def getId(self): | |
789 |
|
830 | |||
790 | return self.id |
|
831 | return self.id | |
791 |
|
832 | |||
792 | def updateId(self, new_id): |
|
833 | def updateId(self, new_id): | |
793 |
|
834 | |||
794 | self.id = str(new_id) |
|
835 | self.id = str(new_id) | |
795 |
|
836 | |||
796 | keyList = self.procUnitConfObjDict.keys() |
|
837 | keyList = self.procUnitConfObjDict.keys() | |
797 | keyList.sort() |
|
838 | keyList.sort() | |
798 |
|
839 | |||
799 | n = 1 |
|
840 | n = 1 | |
800 | newProcUnitConfObjDict = {} |
|
841 | newProcUnitConfObjDict = {} | |
801 |
|
842 | |||
802 | for procKey in keyList: |
|
843 | for procKey in keyList: | |
803 |
|
844 | |||
804 | procUnitConfObj = self.procUnitConfObjDict[procKey] |
|
845 | procUnitConfObj = self.procUnitConfObjDict[procKey] | |
805 | idProcUnit = str(int(self.id)*10 + n) |
|
846 | idProcUnit = str(int(self.id)*10 + n) | |
806 | procUnitConfObj.updateId(idProcUnit, parentId = self.id) |
|
847 | procUnitConfObj.updateId(idProcUnit, parentId = self.id) | |
807 |
|
848 | |||
808 | newProcUnitConfObjDict[idProcUnit] = procUnitConfObj |
|
849 | newProcUnitConfObjDict[idProcUnit] = procUnitConfObj | |
809 | n += 1 |
|
850 | n += 1 | |
810 |
|
851 | |||
811 | self.procUnitConfObjDict = newProcUnitConfObjDict |
|
852 | self.procUnitConfObjDict = newProcUnitConfObjDict | |
812 |
|
853 | |||
813 | def setup(self, id, name, description): |
|
854 | def setup(self, id, name, description): | |
814 |
|
855 | |||
815 | self.id = str(id) |
|
856 | self.id = str(id) | |
816 | self.name = name |
|
857 | self.name = name | |
817 | self.description = description |
|
858 | self.description = description | |
818 |
|
859 | |||
819 | def update(self, name, description): |
|
860 | def update(self, name, description): | |
820 |
|
861 | |||
821 | self.name = name |
|
862 | self.name = name | |
822 | self.description = description |
|
863 | self.description = description | |
823 |
|
864 | |||
824 | def addReadUnit(self, datatype=None, name=None, **kwargs): |
|
865 | def addReadUnit(self, datatype=None, name=None, **kwargs): | |
825 |
|
866 | |||
826 | idReadUnit = self.__getNewId() |
|
867 | idReadUnit = self.__getNewId() | |
827 |
|
868 | |||
828 | readUnitConfObj = ReadUnitConf() |
|
869 | readUnitConfObj = ReadUnitConf() | |
829 | readUnitConfObj.setup(idReadUnit, name, datatype, parentId=self.id, **kwargs) |
|
870 | readUnitConfObj.setup(idReadUnit, name, datatype, parentId=self.id, **kwargs) | |
830 |
|
871 | |||
831 | self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj |
|
872 | self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj | |
832 |
|
873 | |||
833 | return readUnitConfObj |
|
874 | return readUnitConfObj | |
834 |
|
875 | |||
835 | def addProcUnit(self, inputId='0', datatype=None, name=None): |
|
876 | def addProcUnit(self, inputId='0', datatype=None, name=None): | |
836 |
|
877 | |||
837 | idProcUnit = self.__getNewId() |
|
878 | idProcUnit = self.__getNewId() | |
838 |
|
879 | |||
839 | procUnitConfObj = ProcUnitConf() |
|
880 | procUnitConfObj = ProcUnitConf() | |
840 | procUnitConfObj.setup(idProcUnit, name, datatype, inputId, parentId=self.id) |
|
881 | procUnitConfObj.setup(idProcUnit, name, datatype, inputId, parentId=self.id) | |
841 |
|
882 | |||
842 | self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj |
|
883 | self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj | |
843 |
|
884 | |||
844 | return procUnitConfObj |
|
885 | return procUnitConfObj | |
845 |
|
886 | |||
846 | def removeProcUnit(self, id): |
|
887 | def removeProcUnit(self, id): | |
847 |
|
888 | |||
848 | if id in self.procUnitConfObjDict.keys(): |
|
889 | if id in self.procUnitConfObjDict.keys(): | |
849 | self.procUnitConfObjDict.pop(id) |
|
890 | self.procUnitConfObjDict.pop(id) | |
850 |
|
891 | |||
851 | def getReadUnitId(self): |
|
892 | def getReadUnitId(self): | |
852 |
|
893 | |||
853 | readUnitConfObj = self.getReadUnitObj() |
|
894 | readUnitConfObj = self.getReadUnitObj() | |
854 |
|
895 | |||
855 | return readUnitConfObj.id |
|
896 | return readUnitConfObj.id | |
856 |
|
897 | |||
857 | def getReadUnitObj(self): |
|
898 | def getReadUnitObj(self): | |
858 |
|
899 | |||
859 | for obj in self.procUnitConfObjDict.values(): |
|
900 | for obj in self.procUnitConfObjDict.values(): | |
860 | if obj.getElementName() == "ReadUnit": |
|
901 | if obj.getElementName() == "ReadUnit": | |
861 | return obj |
|
902 | return obj | |
862 |
|
903 | |||
863 | return None |
|
904 | return None | |
864 |
|
905 | |||
865 | def getProcUnitObj(self, id=None, name=None): |
|
906 | def getProcUnitObj(self, id=None, name=None): | |
866 |
|
907 | |||
867 | if id != None: |
|
908 | if id != None: | |
868 | return self.procUnitConfObjDict[id] |
|
909 | return self.procUnitConfObjDict[id] | |
869 |
|
910 | |||
870 | if name != None: |
|
911 | if name != None: | |
871 | return self.getProcUnitObjByName(name) |
|
912 | return self.getProcUnitObjByName(name) | |
872 |
|
913 | |||
873 | return None |
|
914 | return None | |
874 |
|
915 | |||
875 | def getProcUnitObjByName(self, name): |
|
916 | def getProcUnitObjByName(self, name): | |
876 |
|
917 | |||
877 | for obj in self.procUnitConfObjDict.values(): |
|
918 | for obj in self.procUnitConfObjDict.values(): | |
878 | if obj.name == name: |
|
919 | if obj.name == name: | |
879 | return obj |
|
920 | return obj | |
880 |
|
921 | |||
881 | return None |
|
922 | return None | |
882 |
|
923 | |||
883 | def procUnitItems(self): |
|
924 | def procUnitItems(self): | |
884 |
|
925 | |||
885 | return self.procUnitConfObjDict.items() |
|
926 | return self.procUnitConfObjDict.items() | |
886 |
|
927 | |||
887 | def makeXml(self): |
|
928 | def makeXml(self): | |
888 |
|
929 | |||
889 | projectElement = Element('Project') |
|
930 | projectElement = Element('Project') | |
890 | projectElement.set('id', str(self.id)) |
|
931 | projectElement.set('id', str(self.id)) | |
891 | projectElement.set('name', self.name) |
|
932 | projectElement.set('name', self.name) | |
892 | projectElement.set('description', self.description) |
|
933 | projectElement.set('description', self.description) | |
893 |
|
934 | |||
894 | for procUnitConfObj in self.procUnitConfObjDict.values(): |
|
935 | for procUnitConfObj in self.procUnitConfObjDict.values(): | |
895 | procUnitConfObj.makeXml(projectElement) |
|
936 | procUnitConfObj.makeXml(projectElement) | |
896 |
|
937 | |||
897 | self.projectElement = projectElement |
|
938 | self.projectElement = projectElement | |
898 |
|
939 | |||
899 | def writeXml(self, filename): |
|
940 | def writeXml(self, filename): | |
900 |
|
941 | |||
901 | self.makeXml() |
|
942 | if not os.access(os.path.dirname(filename), os.W_OK): | |
|
943 | return 0 | |||
902 |
|
944 | |||
903 | #print prettify(self.projectElement) |
|
945 | if os.path.isfile(filename) and not(os.access(filename, os.W_OK)): | |
|
946 | return 0 | |||
|
947 | ||||
|
948 | self.makeXml() | |||
904 |
|
949 | |||
905 | ElementTree(self.projectElement).write(filename, method='xml') |
|
950 | ElementTree(self.projectElement).write(filename, method='xml') | |
|
951 | ||||
|
952 | self.filename = filename | |||
|
953 | ||||
|
954 | return 1 | |||
906 |
|
955 | |||
907 | def readXml(self, filename): |
|
956 | def readXml(self, filename): | |
908 |
|
957 | |||
|
958 | if not os.path.isfile(filename): | |||
|
959 | print "%s does not exist" %filename | |||
|
960 | return 0 | |||
|
961 | ||||
909 | self.projectElement = None |
|
962 | self.projectElement = None | |
910 | self.procUnitConfObjDict = {} |
|
963 | self.procUnitConfObjDict = {} | |
911 |
|
964 | |||
912 | self.projectElement = ElementTree().parse(filename) |
|
965 | self.projectElement = ElementTree().parse(filename) | |
913 |
|
966 | |||
914 | self.project = self.projectElement.tag |
|
967 | self.project = self.projectElement.tag | |
915 |
|
968 | |||
916 | self.id = self.projectElement.get('id') |
|
969 | self.id = self.projectElement.get('id') | |
917 | self.name = self.projectElement.get('name') |
|
970 | self.name = self.projectElement.get('name') | |
918 | self.description = self.projectElement.get('description') |
|
971 | self.description = self.projectElement.get('description') | |
919 |
|
972 | |||
920 | readUnitElementList = self.projectElement.getiterator(ReadUnitConf().getElementName()) |
|
973 | readUnitElementList = self.projectElement.getiterator(ReadUnitConf().getElementName()) | |
921 |
|
974 | |||
922 | for readUnitElement in readUnitElementList: |
|
975 | for readUnitElement in readUnitElementList: | |
923 | readUnitConfObj = ReadUnitConf() |
|
976 | readUnitConfObj = ReadUnitConf() | |
924 | readUnitConfObj.readXml(readUnitElement) |
|
977 | readUnitConfObj.readXml(readUnitElement) | |
925 |
|
978 | |||
926 | if readUnitConfObj.parentId == None: |
|
979 | if readUnitConfObj.parentId == None: | |
927 | readUnitConfObj.parentId = self.id |
|
980 | readUnitConfObj.parentId = self.id | |
928 |
|
981 | |||
929 | self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj |
|
982 | self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj | |
930 |
|
983 | |||
931 | procUnitElementList = self.projectElement.getiterator(ProcUnitConf().getElementName()) |
|
984 | procUnitElementList = self.projectElement.getiterator(ProcUnitConf().getElementName()) | |
932 |
|
985 | |||
933 | for procUnitElement in procUnitElementList: |
|
986 | for procUnitElement in procUnitElementList: | |
934 | procUnitConfObj = ProcUnitConf() |
|
987 | procUnitConfObj = ProcUnitConf() | |
935 | procUnitConfObj.readXml(procUnitElement) |
|
988 | procUnitConfObj.readXml(procUnitElement) | |
936 |
|
989 | |||
937 | if procUnitConfObj.parentId == None: |
|
990 | if procUnitConfObj.parentId == None: | |
938 | procUnitConfObj.parentId = self.id |
|
991 | procUnitConfObj.parentId = self.id | |
939 |
|
992 | |||
940 | self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj |
|
993 | self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj | |
941 |
|
|
994 | ||
|
995 | return 1 | |||
|
996 | ||||
942 | def printattr(self): |
|
997 | def printattr(self): | |
943 |
|
998 | |||
944 | print "Project[%s]: name = %s, description = %s" %(self.id, |
|
999 | print "Project[%s]: name = %s, description = %s" %(self.id, | |
945 | self.name, |
|
1000 | self.name, | |
946 | self.description) |
|
1001 | self.description) | |
947 |
|
1002 | |||
948 | for procUnitConfObj in self.procUnitConfObjDict.values(): |
|
1003 | for procUnitConfObj in self.procUnitConfObjDict.values(): | |
949 | procUnitConfObj.printattr() |
|
1004 | procUnitConfObj.printattr() | |
950 |
|
1005 | |||
951 | def createObjects(self): |
|
1006 | def createObjects(self): | |
952 |
|
1007 | |||
953 | for procUnitConfObj in self.procUnitConfObjDict.values(): |
|
1008 | for procUnitConfObj in self.procUnitConfObjDict.values(): | |
954 | procUnitConfObj.createObjects() |
|
1009 | procUnitConfObj.createObjects() | |
955 |
|
1010 | |||
956 | def __connect(self, objIN, thisObj): |
|
1011 | def __connect(self, objIN, thisObj): | |
957 |
|
1012 | |||
958 | thisObj.setInput(objIN.getOutputObj()) |
|
1013 | thisObj.setInput(objIN.getOutputObj()) | |
959 |
|
1014 | |||
960 | def connectObjects(self): |
|
1015 | def connectObjects(self): | |
961 |
|
1016 | |||
962 | for thisPUConfObj in self.procUnitConfObjDict.values(): |
|
1017 | for thisPUConfObj in self.procUnitConfObjDict.values(): | |
963 |
|
1018 | |||
964 | inputId = thisPUConfObj.getInputId() |
|
1019 | inputId = thisPUConfObj.getInputId() | |
965 |
|
1020 | |||
966 | if int(inputId) == 0: |
|
1021 | if int(inputId) == 0: | |
967 | continue |
|
1022 | continue | |
968 |
|
1023 | |||
969 | #Get input object |
|
1024 | #Get input object | |
970 | puConfINObj = self.procUnitConfObjDict[inputId] |
|
1025 | puConfINObj = self.procUnitConfObjDict[inputId] | |
971 | puObjIN = puConfINObj.getProcUnitObj() |
|
1026 | puObjIN = puConfINObj.getProcUnitObj() | |
972 |
|
1027 | |||
973 | #Get current object |
|
1028 | #Get current object | |
974 | thisPUObj = thisPUConfObj.getProcUnitObj() |
|
1029 | thisPUObj = thisPUConfObj.getProcUnitObj() | |
975 |
|
1030 | |||
976 | self.__connect(puObjIN, thisPUObj) |
|
1031 | self.__connect(puObjIN, thisPUObj) | |
977 |
|
1032 | |||
978 | def isPaused(self): |
|
1033 | def isPaused(self): | |
979 | return 0 |
|
1034 | return 0 | |
980 |
|
1035 | |||
981 | def isStopped(self): |
|
1036 | def isStopped(self): | |
982 | return 0 |
|
1037 | return 0 | |
983 |
|
1038 | |||
984 | def runController(self): |
|
1039 | def runController(self): | |
985 | """ |
|
1040 | """ | |
986 | returns 0 when this process has been stopped, 1 otherwise |
|
1041 | returns 0 when this process has been stopped, 1 otherwise | |
987 | """ |
|
1042 | """ | |
988 |
|
1043 | |||
989 | if self.isPaused(): |
|
1044 | if self.isPaused(): | |
990 | print "Process suspended" |
|
1045 | print "Process suspended" | |
991 |
|
1046 | |||
992 | while True: |
|
1047 | while True: | |
993 | sleep(0.1) |
|
1048 | sleep(0.1) | |
994 |
|
1049 | |||
995 | if not self.isPaused(): |
|
1050 | if not self.isPaused(): | |
996 | break |
|
1051 | break | |
997 |
|
1052 | |||
998 | if self.isStopped(): |
|
1053 | if self.isStopped(): | |
999 | break |
|
1054 | break | |
1000 |
|
1055 | |||
1001 | print "Process reinitialized" |
|
1056 | print "Process reinitialized" | |
1002 |
|
1057 | |||
1003 | if self.isStopped(): |
|
1058 | if self.isStopped(): | |
1004 | print "Process stopped" |
|
1059 | print "Process stopped" | |
1005 | return 0 |
|
1060 | return 0 | |
1006 |
|
1061 | |||
1007 | return 1 |
|
1062 | return 1 | |
1008 |
|
1063 | |||
1009 | def run(self): |
|
1064 | def run(self): | |
1010 |
|
1065 | |||
1011 |
|
1066 | |||
1012 | print "*"*60 |
|
1067 | print "*"*60 | |
1013 | print " Starting SIGNAL CHAIN PROCESSING " |
|
1068 | print " Starting SIGNAL CHAIN PROCESSING v%s " %schainpy.__version__ | |
1014 | print "*"*60 |
|
1069 | print "*"*60 | |
1015 |
|
1070 | |||
1016 |
|
1071 | |||
1017 | keyList = self.procUnitConfObjDict.keys() |
|
1072 | keyList = self.procUnitConfObjDict.keys() | |
1018 | keyList.sort() |
|
1073 | keyList.sort() | |
1019 |
|
1074 | |||
1020 | while(True): |
|
1075 | while(True): | |
1021 |
|
1076 | |||
1022 | is_ok = False |
|
1077 | is_ok = False | |
1023 |
|
1078 | |||
1024 | for procKey in keyList: |
|
1079 | for procKey in keyList: | |
1025 | # print "Running the '%s' process with %s" %(procUnitConfObj.name, procUnitConfObj.id) |
|
1080 | # print "Running the '%s' process with %s" %(procUnitConfObj.name, procUnitConfObj.id) | |
1026 |
|
1081 | |||
1027 | procUnitConfObj = self.procUnitConfObjDict[procKey] |
|
1082 | procUnitConfObj = self.procUnitConfObjDict[procKey] | |
1028 |
|
1083 | |||
1029 | message = "" |
|
|||
1030 | try: |
|
1084 | try: | |
1031 | sts = procUnitConfObj.run() |
|
1085 | sts = procUnitConfObj.run() | |
1032 | is_ok = is_ok or sts |
|
1086 | is_ok = is_ok or sts | |
1033 | except: |
|
1087 | except: | |
1034 |
print "***** Error |
|
1088 | print "***** Error occurred in %s *****" %(procUnitConfObj.name) | |
1035 |
|
|
1089 | ||
|
1090 | sleep(0.5) | |||
1036 |
|
1091 | |||
1037 | err = traceback.format_exception(sys.exc_info()[0], |
|
1092 | err = traceback.format_exception(sys.exc_info()[0], | |
1038 | sys.exc_info()[1], |
|
1093 | sys.exc_info()[1], | |
1039 | sys.exc_info()[2]) |
|
1094 | sys.exc_info()[2]) | |
1040 |
|
1095 | |||
1041 |
|
|
1096 | import socket | |
1042 |
|
|
1097 | ||
|
1098 | subject = "SChain v%s: Error running %s\n" %(schainpy.__version__, procUnitConfObj.name) | |||
|
1099 | ||||
|
1100 | subtitle = "%s: %s\n" %(procUnitConfObj.getElementName() ,procUnitConfObj.name) | |||
|
1101 | subtitle += "Hostname: %s\n" %socket.gethostbyname(socket.gethostname()) | |||
|
1102 | subtitle += "Working directory: %s\n" %os.path.abspath("./") | |||
|
1103 | subtitle += "Configuration file: %s\n" %self.filename | |||
|
1104 | ||||
|
1105 | readUnitConfObj = self.getReadUnitObj() | |||
|
1106 | if readUnitConfObj: | |||
|
1107 | subtitle += "Data path: %s\n" %readUnitConfObj.path | |||
|
1108 | subtitle += "Data type: %s\n" %readUnitConfObj.datatype | |||
|
1109 | subtitle += "Start date: %s\n" %readUnitConfObj.startDate | |||
|
1110 | subtitle += "End date: %s\n" %readUnitConfObj.endDate | |||
|
1111 | subtitle += "Start time: %s\n" %readUnitConfObj.startTime | |||
|
1112 | subtitle += "End time: %s\n" %readUnitConfObj.endTime | |||
|
1113 | ||||
|
1114 | message = "".join(err) | |||
1043 |
|
1115 | |||
1044 | sys.stderr.write(message) |
|
1116 | sys.stderr.write(message) | |
1045 | # print "*"*60 |
|
1117 | ||
1046 | # print message |
|
1118 | adminObj = schainpy.admin.SchainNotify() | |
1047 | # print "*"*60 |
|
1119 | adminObj.sendAlert(message=message, | |
|
1120 | subject=subject, | |||
|
1121 | subtitle=subtitle, | |||
|
1122 | filename=self.filename) | |||
1048 |
|
1123 | |||
1049 | # self.sendReport(message) |
|
|||
1050 | sleep(0.1) |
|
|||
1051 | is_ok = False |
|
1124 | is_ok = False | |
1052 |
|
1125 | |||
1053 | break |
|
1126 | break | |
1054 |
|
1127 | |||
1055 | #If every process unit finished so end process |
|
1128 | #If every process unit finished so end process | |
1056 | if not(is_ok): |
|
1129 | if not(is_ok): | |
1057 | print "Every process unit have finished" |
|
1130 | print "Every process unit have finished" | |
1058 | break |
|
1131 | break | |
1059 |
|
1132 | |||
1060 | if not self.runController(): |
|
1133 | if not self.runController(): | |
1061 | break |
|
1134 | break | |
1062 |
|
1135 | |||
1063 | #Closing every process |
|
1136 | #Closing every process | |
1064 | for procKey in keyList: |
|
1137 | for procKey in keyList: | |
1065 | procUnitConfObj = self.procUnitConfObjDict[procKey] |
|
1138 | procUnitConfObj = self.procUnitConfObjDict[procKey] | |
1066 | procUnitConfObj.close() |
|
1139 | procUnitConfObj.close() | |
1067 |
|
1140 | |||
1068 | print "Process finished" |
|
1141 | print "Process finished" | |
1069 |
|
1142 | |||
1070 | def start(self, filename): |
|
1143 | def start(self, filename): | |
1071 |
|
1144 | |||
1072 | self.writeXml(filename) |
|
1145 | self.writeXml(filename) | |
1073 | self.readXml(filename) |
|
1146 | self.readXml(filename) | |
1074 |
|
1147 | |||
1075 | self.createObjects() |
|
1148 | self.createObjects() | |
1076 | self.connectObjects() |
|
1149 | self.connectObjects() | |
1077 | self.run() |
|
1150 | self.run() | |
1078 |
|
||||
1079 | def sendReport(self, message, subject="Error occurred in Signal Chain", email=SCHAIN_MAIL): |
|
|||
1080 |
|
||||
1081 | import smtplib |
|
|||
1082 |
|
||||
1083 | print subject |
|
|||
1084 | print "Sending report to %s ..." %email |
|
|||
1085 |
|
||||
1086 | message = 'From: (Python Signal Chain API) ' + email + '\n' + \ |
|
|||
1087 | 'To: ' + email + '\n' + \ |
|
|||
1088 | 'Subject: ' + str(subject) + '\n' + \ |
|
|||
1089 | 'Content-type: text/html\n\n' + message |
|
|||
1090 |
|
||||
1091 | server = smtplib.SMTP(EMAIL_SERVER) |
|
|||
1092 | server.sendmail(email.split(',')[0], |
|
|||
1093 | email.split(','), message) |
|
|||
1094 | server.quit() |
|
|||
1095 |
|
1151 | |||
1096 | if __name__ == '__main__': |
|
1152 | if __name__ == '__main__': | |
1097 |
|
1153 | |||
1098 | desc = "Segundo Test" |
|
1154 | desc = "Segundo Test" | |
1099 | filename = "schain.xml" |
|
1155 | filename = "schain.xml" | |
1100 |
|
1156 | |||
1101 | controllerObj = Project() |
|
1157 | controllerObj = Project() | |
1102 |
|
1158 | |||
1103 | controllerObj.setup(id = '191', name='test01', description=desc) |
|
1159 | controllerObj.setup(id = '191', name='test01', description=desc) | |
1104 |
|
1160 | |||
1105 | readUnitConfObj = controllerObj.addReadUnit(datatype='Voltage', |
|
1161 | readUnitConfObj = controllerObj.addReadUnit(datatype='Voltage', | |
1106 | path='data/rawdata/', |
|
1162 | path='data/rawdata/', | |
1107 | startDate='2011/01/01', |
|
1163 | startDate='2011/01/01', | |
1108 | endDate='2012/12/31', |
|
1164 | endDate='2012/12/31', | |
1109 | startTime='00:00:00', |
|
1165 | startTime='00:00:00', | |
1110 | endTime='23:59:59', |
|
1166 | endTime='23:59:59', | |
1111 | online=1, |
|
1167 | online=1, | |
1112 | walk=1) |
|
1168 | walk=1) | |
1113 |
|
1169 | |||
1114 | procUnitConfObj0 = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId()) |
|
1170 | procUnitConfObj0 = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId()) | |
1115 |
|
1171 | |||
1116 | opObj10 = procUnitConfObj0.addOperation(name='selectChannels') |
|
1172 | opObj10 = procUnitConfObj0.addOperation(name='selectChannels') | |
1117 | opObj10.addParameter(name='channelList', value='3,4,5', format='intlist') |
|
1173 | opObj10.addParameter(name='channelList', value='3,4,5', format='intlist') | |
1118 |
|
1174 | |||
1119 | opObj10 = procUnitConfObj0.addOperation(name='selectHeights') |
|
1175 | opObj10 = procUnitConfObj0.addOperation(name='selectHeights') | |
1120 | opObj10.addParameter(name='minHei', value='90', format='float') |
|
1176 | opObj10.addParameter(name='minHei', value='90', format='float') | |
1121 | opObj10.addParameter(name='maxHei', value='180', format='float') |
|
1177 | opObj10.addParameter(name='maxHei', value='180', format='float') | |
1122 |
|
1178 | |||
1123 | opObj12 = procUnitConfObj0.addOperation(name='CohInt', optype='external') |
|
1179 | opObj12 = procUnitConfObj0.addOperation(name='CohInt', optype='external') | |
1124 | opObj12.addParameter(name='n', value='10', format='int') |
|
1180 | opObj12.addParameter(name='n', value='10', format='int') | |
1125 |
|
1181 | |||
1126 | procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj0.getId()) |
|
1182 | procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj0.getId()) | |
1127 | procUnitConfObj1.addParameter(name='nFFTPoints', value='32', format='int') |
|
1183 | procUnitConfObj1.addParameter(name='nFFTPoints', value='32', format='int') | |
1128 | # procUnitConfObj1.addParameter(name='pairList', value='(0,1),(0,2),(1,2)', format='') |
|
1184 | # procUnitConfObj1.addParameter(name='pairList', value='(0,1),(0,2),(1,2)', format='') | |
1129 |
|
1185 | |||
1130 |
|
1186 | |||
1131 | opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='external') |
|
1187 | opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='external') | |
1132 | opObj11.addParameter(name='idfigure', value='1', format='int') |
|
1188 | opObj11.addParameter(name='idfigure', value='1', format='int') | |
1133 | opObj11.addParameter(name='wintitle', value='SpectraPlot0', format='str') |
|
1189 | opObj11.addParameter(name='wintitle', value='SpectraPlot0', format='str') | |
1134 | opObj11.addParameter(name='zmin', value='40', format='int') |
|
1190 | opObj11.addParameter(name='zmin', value='40', format='int') | |
1135 | opObj11.addParameter(name='zmax', value='90', format='int') |
|
1191 | opObj11.addParameter(name='zmax', value='90', format='int') | |
1136 | opObj11.addParameter(name='showprofile', value='1', format='int') |
|
1192 | opObj11.addParameter(name='showprofile', value='1', format='int') | |
1137 |
|
1193 | |||
1138 | print "Escribiendo el archivo XML" |
|
1194 | print "Escribiendo el archivo XML" | |
1139 |
|
1195 | |||
1140 | controllerObj.writeXml(filename) |
|
1196 | controllerObj.writeXml(filename) | |
1141 |
|
1197 | |||
1142 | print "Leyendo el archivo XML" |
|
1198 | print "Leyendo el archivo XML" | |
1143 | controllerObj.readXml(filename) |
|
1199 | controllerObj.readXml(filename) | |
1144 | #controllerObj.printattr() |
|
1200 | #controllerObj.printattr() | |
1145 |
|
1201 | |||
1146 | controllerObj.createObjects() |
|
1202 | controllerObj.createObjects() | |
1147 | controllerObj.connectObjects() |
|
1203 | controllerObj.connectObjects() | |
1148 | controllerObj.run() |
|
1204 | controllerObj.run() | |
1149 |
|
1205 | |||
1150 | No newline at end of file |
|
1206 |
@@ -1,141 +1,141 | |||||
1 | import threading |
|
1 | import threading | |
2 |
|
2 | |||
3 | from PyQt4 import QtCore |
|
|||
4 | from PyQt4.QtCore import SIGNAL |
|
|||
5 |
|
||||
6 | from schainpy.controller import Project |
|
3 | from schainpy.controller import Project | |
7 |
|
4 | |||
8 | class ControllerThread(threading.Thread, Project): |
|
5 | class ControllerThread(threading.Thread, Project): | |
9 |
|
6 | |||
10 | def __init__(self, filename): |
|
7 | def __init__(self, filename): | |
11 |
|
8 | |||
12 | threading.Thread.__init__(self) |
|
9 | threading.Thread.__init__(self) | |
13 | Project.__init__(self) |
|
10 | Project.__init__(self) | |
14 |
|
11 | |||
15 | self.setDaemon(True) |
|
12 | self.setDaemon(True) | |
16 |
|
13 | |||
17 | self.filename = filename |
|
14 | self.filename = filename | |
18 |
|
15 | |||
19 | self.lock = threading.Lock() |
|
16 | self.lock = threading.Lock() | |
20 | self.control = {'stop':False, 'pause':False} |
|
17 | self.control = {'stop':False, 'pause':False} | |
21 |
|
18 | |||
22 | def __del__(self): |
|
19 | def __del__(self): | |
23 |
|
20 | |||
24 | self.control['stop'] = True |
|
21 | self.control['stop'] = True | |
25 |
|
22 | |||
26 | def stop(self): |
|
23 | def stop(self): | |
27 |
|
24 | |||
28 | self.lock.acquire() |
|
25 | self.lock.acquire() | |
29 |
|
26 | |||
30 | self.control['stop'] = True |
|
27 | self.control['stop'] = True | |
31 |
|
28 | |||
32 | self.lock.release() |
|
29 | self.lock.release() | |
33 |
|
30 | |||
34 | def pause(self): |
|
31 | def pause(self): | |
35 |
|
32 | |||
36 | self.lock.acquire() |
|
33 | self.lock.acquire() | |
37 |
|
34 | |||
38 | self.control['pause'] = not(self.control['pause']) |
|
35 | self.control['pause'] = not(self.control['pause']) | |
39 | paused = self.control['pause'] |
|
36 | paused = self.control['pause'] | |
40 |
|
37 | |||
41 | self.lock.release() |
|
38 | self.lock.release() | |
42 |
|
39 | |||
43 | return paused |
|
40 | return paused | |
44 |
|
41 | |||
45 | def isPaused(self): |
|
42 | def isPaused(self): | |
46 |
|
43 | |||
47 | self.lock.acquire() |
|
44 | self.lock.acquire() | |
48 | paused = self.control['pause'] |
|
45 | paused = self.control['pause'] | |
49 | self.lock.release() |
|
46 | self.lock.release() | |
50 |
|
47 | |||
51 | return paused |
|
48 | return paused | |
52 |
|
49 | |||
53 | def isStopped(self): |
|
50 | def isStopped(self): | |
54 |
|
51 | |||
55 | self.lock.acquire() |
|
52 | self.lock.acquire() | |
56 | stopped = self.control['stop'] |
|
53 | stopped = self.control['stop'] | |
57 | self.lock.release() |
|
54 | self.lock.release() | |
58 |
|
55 | |||
59 | return stopped |
|
56 | return stopped | |
60 |
|
57 | |||
61 | def run(self): |
|
58 | def run(self): | |
62 | self.control['stop'] = False |
|
59 | self.control['stop'] = False | |
63 | self.control['pause'] = False |
|
60 | self.control['pause'] = False | |
64 |
|
61 | |||
65 | self.readXml(self.filename) |
|
62 | self.readXml(self.filename) | |
66 | self.createObjects() |
|
63 | self.createObjects() | |
67 | self.connectObjects() |
|
64 | self.connectObjects() | |
68 | Project.run(self) |
|
65 | Project.run(self) | |
69 |
|
66 | |||
70 | def isRunning(self): |
|
67 | def isRunning(self): | |
71 |
|
68 | |||
72 | return self.is_alive() |
|
69 | return self.is_alive() | |
73 |
|
70 | |||
74 | def isFinished(self): |
|
71 | def isFinished(self): | |
75 |
|
72 | |||
76 | return not self.is_alive() |
|
73 | return not self.is_alive() | |
77 |
|
74 | |||
78 | class ControllerQThread(QtCore.QThread, Project): |
|
75 | # from PyQt4 import QtCore | |
79 |
|
76 | # from PyQt4.QtCore import SIGNAL | ||
80 | def __init__(self, filename): |
|
77 | # | |
81 |
|
78 | # class ControllerQThread(QtCore.QThread, Project): | ||
82 | QtCore.QThread.__init__(self) |
|
79 | # | |
83 |
|
|
80 | # def __init__(self, filename): | |
84 |
|
81 | # | ||
85 | self.filename = filename |
|
82 | # QtCore.QThread.__init__(self) | |
86 |
|
83 | # Project.__init__(self) | ||
87 | self.lock = threading.Lock() |
|
84 | # | |
88 | self.control = {'stop':False, 'pause':False} |
|
85 | # self.filename = filename | |
89 |
|
86 | # | ||
90 | def __del__(self): |
|
87 | # self.lock = threading.Lock() | |
91 |
|
88 | # self.control = {'stop':False, 'pause':False} | ||
92 | self.control['stop'] = True |
|
89 | # | |
93 | self.wait() |
|
90 | # def __del__(self): | |
94 |
|
91 | # | ||
95 | def stop(self): |
|
92 | # self.control['stop'] = True | |
96 |
|
93 | # self.wait() | ||
97 | self.lock.acquire() |
|
94 | # | |
98 |
|
95 | # def stop(self): | ||
99 | self.control['stop'] = True |
|
96 | # | |
100 |
|
97 | # self.lock.acquire() | ||
101 | self.lock.release() |
|
98 | # | |
102 |
|
99 | # self.control['stop'] = True | ||
103 | def pause(self): |
|
100 | # | |
104 |
|
101 | # self.lock.release() | ||
105 | self.lock.acquire() |
|
102 | # | |
106 |
|
103 | # def pause(self): | ||
107 | self.control['pause'] = not(self.control['pause']) |
|
104 | # | |
108 | paused = self.control['pause'] |
|
105 | # self.lock.acquire() | |
109 |
|
106 | # | ||
110 | self.lock.release() |
|
107 | # self.control['pause'] = not(self.control['pause']) | |
111 |
|
108 | # paused = self.control['pause'] | ||
112 | return paused |
|
109 | # | |
113 |
|
110 | # self.lock.release() | ||
114 | def isPaused(self): |
|
111 | # | |
115 |
|
112 | # return paused | ||
116 | self.lock.acquire() |
|
113 | # | |
117 | paused = self.control['pause'] |
|
114 | # def isPaused(self): | |
118 | self.lock.release() |
|
115 | # | |
119 |
|
116 | # self.lock.acquire() | ||
120 | return paused |
|
117 | # paused = self.control['pause'] | |
121 |
|
118 | # self.lock.release() | ||
122 | def isStopped(self): |
|
119 | # | |
123 |
|
120 | # return paused | ||
124 | self.lock.acquire() |
|
121 | # | |
125 | stopped = self.control['stop'] |
|
122 | # def isStopped(self): | |
126 | self.lock.release() |
|
123 | # | |
127 |
|
124 | # self.lock.acquire() | ||
128 | return stopped |
|
125 | # stopped = self.control['stop'] | |
129 |
|
126 | # self.lock.release() | ||
130 | def run(self): |
|
127 | # | |
131 |
|
128 | # return stopped | ||
132 | self.control['stop'] = False |
|
129 | # | |
133 | self.control['pause'] = False |
|
130 | # def run(self): | |
134 |
|
131 | # | ||
135 | self.readXml(self.filename) |
|
132 | # self.control['stop'] = False | |
136 | self.createObjects() |
|
133 | # self.control['pause'] = False | |
137 | self.connectObjects() |
|
134 | # | |
138 | self.emit( SIGNAL( "jobStarted( PyQt_PyObject )" ), 1) |
|
135 | # self.readXml(self.filename) | |
139 | Project.run(self) |
|
136 | # self.createObjects() | |
140 | self.emit( SIGNAL( "jobFinished( PyQt_PyObject )" ), 1) |
|
137 | # self.connectObjects() | |
141 | No newline at end of file |
|
138 | # self.emit( SIGNAL( "jobStarted( PyQt_PyObject )" ), 1) | |
|
139 | # Project.run(self) | |||
|
140 | # self.emit( SIGNAL( "jobFinished( PyQt_PyObject )" ), 1) | |||
|
141 | # No newline at end of file |
@@ -1,39 +1,41 | |||||
1 | ''' |
|
1 | ''' | |
2 | Created on Jul 16, 2014 |
|
2 | Created on Jul 16, 2014 | |
3 |
|
3 | |||
4 | @author: roj-idl71 |
|
4 | @author: roj-idl71 | |
5 | ''' |
|
5 | ''' | |
6 |
|
6 | |||
7 | from schainpy import __version__ |
|
7 | from schainpy import __version__ | |
8 | from setuptools import setup, Extension |
|
8 | from setuptools import setup, Extension | |
9 |
|
9 | |||
10 | setup(name="schainpy", |
|
10 | setup(name="schainpy", | |
11 | version=__version__, |
|
11 | version=__version__, | |
12 | description="Python tools to read, write and process Jicamarca data", |
|
12 | description="Python tools to read, write and process Jicamarca data", | |
13 | author="Miguel Urco", |
|
13 | author="Miguel Urco", | |
14 | author_email="miguel.urco@jro.igp.gob.pe", |
|
14 | author_email="miguel.urco@jro.igp.gob.pe", | |
15 | url="http://jro.igp.gob.pe", |
|
15 | url="http://jro.igp.gob.pe", | |
16 | packages = {'schainpy', |
|
16 | packages = {'schainpy', | |
17 | 'schainpy.model', |
|
17 | 'schainpy.model', | |
18 | 'schainpy.model.data', |
|
18 | 'schainpy.model.data', | |
19 | 'schainpy.model.graphics', |
|
19 | 'schainpy.model.graphics', | |
20 | 'schainpy.model.io', |
|
20 | 'schainpy.model.io', | |
21 | 'schainpy.model.proc', |
|
21 | 'schainpy.model.proc', | |
22 | 'schainpy.model.utils', |
|
22 | 'schainpy.model.utils', | |
23 | 'schainpy.gui', |
|
23 | 'schainpy.gui', | |
24 | 'schainpy.gui.figures', |
|
24 | 'schainpy.gui.figures', | |
25 | 'schainpy.gui.viewcontroller', |
|
25 | 'schainpy.gui.viewcontroller', | |
26 | 'schainpy.gui.viewer', |
|
26 | 'schainpy.gui.viewer', | |
27 | 'schainpy.gui.viewer.windows'}, |
|
27 | 'schainpy.gui.viewer.windows'}, | |
28 | py_modules=['schainpy.serializer.DataTranslate', |
|
28 | py_modules=['schainpy.serializer.DataTranslate', | |
29 | 'schainpy.serializer.JROSerializer'], |
|
29 | 'schainpy.serializer.JROSerializer'], | |
30 |
package_data={'schainpy |
|
30 | package_data={'schainpy': ['*.cfg'], | |
|
31 | 'schainpy.gui.figures': ['*.png','*.jpg'] | |||
|
32 | }, | |||
31 | include_package_data=True, |
|
33 | include_package_data=True, | |
32 | scripts =['schainpy/gui/schainGUI'], |
|
34 | scripts =['schainpy/gui/schainGUI'], | |
33 | install_requires=["numpy >= 1.6.0", |
|
35 | install_requires=["numpy >= 1.6.0", | |
34 | "scipy >= 0.9.0", |
|
36 | "scipy >= 0.9.0", | |
35 | "h5py >= 2.0.1", |
|
37 | "h5py >= 2.0.1", | |
36 | "wxpython >= 2.8", |
|
38 | "wxpython >= 2.8", | |
37 | "matplotlib >= 1.0.0" |
|
39 | "matplotlib >= 1.0.0" | |
38 | ], |
|
40 | ], | |
39 | ) No newline at end of file |
|
41 | ) |
General Comments 0
You need to be logged in to leave comments.
Login now