##// END OF EJS Templates
test alarm
Juan C. Espinoza -
r1126:c6ebc7aed331
parent child
Show More
1 NO CONTENT: new file 100644, binary diff hidden
1 NO CONTENT: new file 100644, binary diff hidden
@@ -5,17 +5,53 notification class and a standard error handing class.
5 5
6 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 11 import traceback
10 12 import smtplib
11 13 import ConfigParser
12 14 import StringIO
13
15 from threading import Thread
14 16 from email.mime.text import MIMEText
15 17 from email.mime.application import MIMEApplication
16 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 56 __DEFAULT_ADMINISTRATOR_EMAIL = ""
21 57 __DEFAULT_EMAIL_SERVER = "jro-zimbra.igp.gob.pe"
@@ -204,7 +240,7 class SchainNotify:
204 240
205 241 msg.attach(part)
206 242
207 if os.path.isfile(filename):
243 if filename and os.path.isfile(filename):
208 244 # This is the binary part(The Attachment):
209 245 part = MIMEApplication(open(filename,"rb").read())
210 246 part.add_header('Content-Disposition',
@@ -220,7 +256,7 class SchainNotify:
220 256 return 0
221 257
222 258 # Start the server:
223 # smtp.ehlo()
259 # smtp.ehlo()
224 260 if self.__emailPass:
225 261 smtp.login(self.__emailFromAddress, self.__emailPass)
226 262
@@ -905,12 +905,11 class Project(Process):
905 905 def __init__(self, plotter_queue=None):
906 906
907 907 Process.__init__(self)
908 self.id = None
909 # self.name = None
908 self.id = None
910 909 self.description = None
911
910 self.email = None
911 self.alarm = False
912 912 self.plotterQueue = plotter_queue
913
914 913 self.procUnitConfObjDict = {}
915 914
916 915 def __getNewId(self):
@@ -952,13 +951,12 class Project(Process):
952 951 procUnitConfObj = self.procUnitConfObjDict[procKey]
953 952 idProcUnit = str(int(self.id) * 10 + n)
954 953 procUnitConfObj.updateId(idProcUnit, parentId=self.id)
955
956 954 newProcUnitConfObjDict[idProcUnit] = procUnitConfObj
957 955 n += 1
958 956
959 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 961 print
964 962 print '*' * 60
@@ -966,11 +964,14 class Project(Process):
966 964 print '*' * 60
967 965 print
968 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 976 def clone(self):
976 977
@@ -1179,7 +1180,7 class Project(Process):
1179 1180
1180 1181 self.__connect(puObjIN, thisPUObj)
1181 1182
1182 def __handleError(self, procUnitConfObj, send_email=False):
1183 def __handleError(self, procUnitConfObj):
1183 1184
1184 1185 import socket
1185 1186
@@ -1194,9 +1195,13 class Project(Process):
1194 1195
1195 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 1200 return
1199 1201
1202 if self.alarm:
1203 schainpy.admin.alarm(1)
1204
1200 1205 subject = 'SChain v%s: Error running %s\n' % (
1201 1206 schainpy.__version__, procUnitConfObj.name)
1202 1207
@@ -1219,10 +1224,13 class Project(Process):
1219 1224 subtitle += '[End time = %s]\n' % readUnitConfObj.endTime
1220 1225
1221 1226 adminObj = schainpy.admin.SchainNotify()
1222 adminObj.sendAlert(message=message,
1223 subject=subject,
1224 subtitle=subtitle,
1225 filename=self.filename)
1227 adminObj.notify(
1228 email=self.email,
1229 message=message,
1230 subject=subject,
1231 subtitle=subtitle,
1232 filename=self.filename
1233 )
1226 1234
1227 1235 def isPaused(self):
1228 1236 return 0
@@ -1297,7 +1305,7 class Project(Process):
1297 1305 break
1298 1306 except ValueError, e:
1299 1307 time.sleep(0.5)
1300 self.__handleError(procUnitConfObj, send_email=True)
1308 self.__handleError(procUnitConfObj)
1301 1309 is_ok = False
1302 1310 break
1303 1311 except:
@@ -41,6 +41,7 setup(name = "schainpy",
41 41 ext_package = 'schainpy',
42 42 package_data = {'': ['schain.conf.template'],
43 43 'schainpy.gui.figures': ['*.png', '*.jpg'],
44 'schainpy.files': ['*.oga']
44 45 },
45 46 include_package_data = False,
46 47 scripts = ['schainpy/gui/schainGUI'],
General Comments 0
You need to be logged in to leave comments. Login now