##// END OF EJS Templates
test alarm
Juan C. Espinoza -
r1126:c6ebc7aed331
parent child
Show More
1 NO CONTENT: new file 100644, binary diff hidden
NO CONTENT: new file 100644, binary diff hidden
1 NO CONTENT: new file 100644, binary diff hidden
NO CONTENT: new file 100644, binary diff hidden
@@ -5,17 +5,53 notification class and a standard error handing class.
5
5
6 $Id: admin.py 3966 2015-12-01 14:32:29Z miguel.urco $
6 $Id: admin.py 3966 2015-12-01 14:32:29Z miguel.urco $
7 """
7 """
8 import os, sys
8 import os
9 import sys
10 import time
9 import traceback
11 import traceback
10 import smtplib
12 import smtplib
11 import ConfigParser
13 import ConfigParser
12 import StringIO
14 import StringIO
13
15 from threading import Thread
14 from email.mime.text import MIMEText
16 from email.mime.text import MIMEText
15 from email.mime.application import MIMEApplication
17 from email.mime.application import MIMEApplication
16 from email.mime.multipart import MIMEMultipart
18 from email.mime.multipart import MIMEMultipart
17
19
18 class SchainConfigure():
20 from schainpy.utils import log
21
22 def get_path():
23 '''
24 Return schainpy path
25 '''
26
27 try:
28 root = __file__
29 if os.path.islink(root):
30 root = os.path.realpath(root)
31
32 return os.path.dirname(os.path.abspath(root))
33 except:
34 log.error('I am sorry, but something is wrong... __file__ not found')
35
36 def alarm(level=1, cycle=2):
37 '''
38 '''
39
40 def target(sound, level, cycle):
41 for __ in range(cycle):
42 os.system('paplay {}'.format(sound))
43 time.sleep(0.5)
44
45 sound = os.path.join(get_path(), 'alarm{}.oga'.format(level))
46
47 if os.path.exists(sound):
48 t = Thread(target=target, args=(sound, level, cycle))
49 t.start()
50 else:
51 log.warning('Unable to play alarm', 'ADMIN')
52
53
54 class SchainConfigure():
19
55
20 __DEFAULT_ADMINISTRATOR_EMAIL = ""
56 __DEFAULT_ADMINISTRATOR_EMAIL = ""
21 __DEFAULT_EMAIL_SERVER = "jro-zimbra.igp.gob.pe"
57 __DEFAULT_EMAIL_SERVER = "jro-zimbra.igp.gob.pe"
@@ -204,7 +240,7 class SchainNotify:
204
240
205 msg.attach(part)
241 msg.attach(part)
206
242
207 if os.path.isfile(filename):
243 if filename and os.path.isfile(filename):
208 # This is the binary part(The Attachment):
244 # This is the binary part(The Attachment):
209 part = MIMEApplication(open(filename,"rb").read())
245 part = MIMEApplication(open(filename,"rb").read())
210 part.add_header('Content-Disposition',
246 part.add_header('Content-Disposition',
@@ -220,7 +256,7 class SchainNotify:
220 return 0
256 return 0
221
257
222 # Start the server:
258 # Start the server:
223 # smtp.ehlo()
259 # smtp.ehlo()
224 if self.__emailPass:
260 if self.__emailPass:
225 smtp.login(self.__emailFromAddress, self.__emailPass)
261 smtp.login(self.__emailFromAddress, self.__emailPass)
226
262
@@ -905,12 +905,11 class Project(Process):
905 def __init__(self, plotter_queue=None):
905 def __init__(self, plotter_queue=None):
906
906
907 Process.__init__(self)
907 Process.__init__(self)
908 self.id = None
908 self.id = None
909 # self.name = None
910 self.description = None
909 self.description = None
911
910 self.email = None
911 self.alarm = False
912 self.plotterQueue = plotter_queue
912 self.plotterQueue = plotter_queue
913
914 self.procUnitConfObjDict = {}
913 self.procUnitConfObjDict = {}
915
914
916 def __getNewId(self):
915 def __getNewId(self):
@@ -952,13 +951,12 class Project(Process):
952 procUnitConfObj = self.procUnitConfObjDict[procKey]
951 procUnitConfObj = self.procUnitConfObjDict[procKey]
953 idProcUnit = str(int(self.id) * 10 + n)
952 idProcUnit = str(int(self.id) * 10 + n)
954 procUnitConfObj.updateId(idProcUnit, parentId=self.id)
953 procUnitConfObj.updateId(idProcUnit, parentId=self.id)
955
956 newProcUnitConfObjDict[idProcUnit] = procUnitConfObj
954 newProcUnitConfObjDict[idProcUnit] = procUnitConfObj
957 n += 1
955 n += 1
958
956
959 self.procUnitConfObjDict = newProcUnitConfObjDict
957 self.procUnitConfObjDict = newProcUnitConfObjDict
960
958
961 def setup(self, id, name='', description=''):
959 def setup(self, id, name='', description='', email=None, alarm=False):
962
960
963 print
961 print
964 print '*' * 60
962 print '*' * 60
@@ -966,11 +964,14 class Project(Process):
966 print '*' * 60
964 print '*' * 60
967 print
965 print
968 self.id = str(id)
966 self.id = str(id)
969 self.description = description
967 self.description = description
968 self.email = email
969 self.alarm = alarm
970
970
971 def update(self, name, description):
971 def update(self, **kwargs):
972
972
973 self.description = description
973 for key, value in kwargs:
974 setattr(self, key, value)
974
975
975 def clone(self):
976 def clone(self):
976
977
@@ -1179,7 +1180,7 class Project(Process):
1179
1180
1180 self.__connect(puObjIN, thisPUObj)
1181 self.__connect(puObjIN, thisPUObj)
1181
1182
1182 def __handleError(self, procUnitConfObj, send_email=False):
1183 def __handleError(self, procUnitConfObj):
1183
1184
1184 import socket
1185 import socket
1185
1186
@@ -1194,9 +1195,13 class Project(Process):
1194
1195
1195 sys.stderr.write(message)
1196 sys.stderr.write(message)
1196
1197
1197 if not send_email:
1198 if self.email is None:
1199 log.warning('Email attribute has not been set', self.name)
1198 return
1200 return
1199
1201
1202 if self.alarm:
1203 schainpy.admin.alarm(1)
1204
1200 subject = 'SChain v%s: Error running %s\n' % (
1205 subject = 'SChain v%s: Error running %s\n' % (
1201 schainpy.__version__, procUnitConfObj.name)
1206 schainpy.__version__, procUnitConfObj.name)
1202
1207
@@ -1219,10 +1224,13 class Project(Process):
1219 subtitle += '[End time = %s]\n' % readUnitConfObj.endTime
1224 subtitle += '[End time = %s]\n' % readUnitConfObj.endTime
1220
1225
1221 adminObj = schainpy.admin.SchainNotify()
1226 adminObj = schainpy.admin.SchainNotify()
1222 adminObj.sendAlert(message=message,
1227 adminObj.notify(
1223 subject=subject,
1228 email=self.email,
1224 subtitle=subtitle,
1229 message=message,
1225 filename=self.filename)
1230 subject=subject,
1231 subtitle=subtitle,
1232 filename=self.filename
1233 )
1226
1234
1227 def isPaused(self):
1235 def isPaused(self):
1228 return 0
1236 return 0
@@ -1297,7 +1305,7 class Project(Process):
1297 break
1305 break
1298 except ValueError, e:
1306 except ValueError, e:
1299 time.sleep(0.5)
1307 time.sleep(0.5)
1300 self.__handleError(procUnitConfObj, send_email=True)
1308 self.__handleError(procUnitConfObj)
1301 is_ok = False
1309 is_ok = False
1302 break
1310 break
1303 except:
1311 except:
@@ -41,6 +41,7 setup(name = "schainpy",
41 ext_package = 'schainpy',
41 ext_package = 'schainpy',
42 package_data = {'': ['schain.conf.template'],
42 package_data = {'': ['schain.conf.template'],
43 'schainpy.gui.figures': ['*.png', '*.jpg'],
43 'schainpy.gui.figures': ['*.png', '*.jpg'],
44 'schainpy.files': ['*.oga']
44 },
45 },
45 include_package_data = False,
46 include_package_data = False,
46 scripts = ['schainpy/gui/schainGUI'],
47 scripts = ['schainpy/gui/schainGUI'],
General Comments 0
You need to be logged in to leave comments. Login now