##// END OF EJS Templates
Alarm working ok
jespinoza -
r1130:d903be96a0b2
parent child
Show More
@@ -1,4 +1,5
1 """The admin module contains all administrative classes relating to the schain python api.
1 """
2 The admin module contains all administrative classes relating to the schain python api.
2 3
3 4 The main role of this module is to send some reports. It contains a
4 5 notification class and a standard error handing class.
@@ -18,6 +19,7 from email.mime.text import MIMEText
18 19 from email.mime.application import MIMEApplication
19 20 from email.mime.multipart import MIMEMultipart
20 21
22 import schainpy
21 23 from schainpy.utils import log
22 24 from schainpy.model.graphics.jroplot_data import popup
23 25
@@ -39,13 +41,13 class Alarm(Process):
39 41 '''
40 42 modes:
41 43 0 - All
42 1 - Sound alarm
43 2 - Send email
44 3 - Popup message
44 1 - Send email
45 2 - Popup message
46 3 - Sound alarm
45 47 4 - Send to alarm system TODO
46 48 '''
47 49
48 def __init__(self, modes=[1], **kwargs):
50 def __init__(self, modes=[], **kwargs):
49 51 Process.__init__(self)
50 52 self.modes = modes
51 53 self.kwargs = kwargs
@@ -63,10 +65,13 class Alarm(Process):
63 65 @staticmethod
64 66 def send_email(**kwargs):
65 67 notifier = SchainNotify()
68 print kwargs
66 69 notifier.notify(**kwargs)
67 70
68 71 @staticmethod
69 def show_popup(message='Error'):
72 def show_popup(message):
73 if isinstance(message, list):
74 message = message[-1]
70 75 popup(message)
71 76
72 77 @staticmethod
@@ -83,15 +88,15 class Alarm(Process):
83 88 def run(self):
84 89 tasks = {
85 90 1 : self.send_email,
86 2 : self.play_sound,
87 3 : self.show_popup,
91 2 : self.show_popup,
92 3 : self.play_sound,
88 93 4 : self.send_alarm,
89 94 }
90 95
91 96 tasks_args = {
92 97 1: ['email', 'message', 'subject', 'subtitle', 'filename'],
93 2: [],
94 3: ['message'],
98 2: ['message'],
99 3: [],
95 100 4: [],
96 101 }
97 102 procs = []
@@ -908,7 +908,7 class Project(Process):
908 908 self.id = None
909 909 self.description = None
910 910 self.email = None
911 self.alarm = [0]
911 self.alarm = None
912 912 self.plotterQueue = plotter_queue
913 913 self.procUnitConfObjDict = {}
914 914
@@ -956,7 +956,7 class Project(Process):
956 956
957 957 self.procUnitConfObjDict = newProcUnitConfObjDict
958 958
959 def setup(self, id, name='', description='', email=None, alarm=[0]):
959 def setup(self, id, name='', description='', email=None, alarm=[3]):
960 960
961 961 print
962 962 print '*' * 60
@@ -1180,7 +1180,7 class Project(Process):
1180 1180
1181 1181 self.__connect(puObjIN, thisPUObj)
1182 1182
1183 def __handleError(self, procUnitConfObj, modes=None):
1183 def __handleError(self, procUnitConfObj, modes=None, stdout=True):
1184 1184
1185 1185 import socket
1186 1186
@@ -1195,7 +1195,8 class Project(Process):
1195 1195
1196 1196 message = ''.join(err)
1197 1197
1198 sys.stderr.write(message)
1198 if stdout:
1199 sys.stderr.write(message)
1199 1200
1200 1201 subject = 'SChain v%s: Error running %s\n' % (
1201 1202 schainpy.__version__, procUnitConfObj.name)
@@ -1227,7 +1228,7 class Project(Process):
1227 1228 filename=self.filename
1228 1229 )
1229 1230
1230 a.start()
1231 return a
1231 1232
1232 1233 def isPaused(self):
1233 1234 return 0
@@ -1286,6 +1287,8 class Project(Process):
1286 1287 keyList = self.procUnitConfObjDict.keys()
1287 1288 keyList.sort()
1288 1289
1290 err = None
1291
1289 1292 while(True):
1290 1293
1291 1294 is_ok = False
@@ -1298,18 +1301,18 class Project(Process):
1298 1301 sts = procUnitConfObj.run()
1299 1302 is_ok = is_ok or sts
1300 1303 except SchainWarning:
1301 self.__handleError(procUnitConfObj, modes=[2, 3])
1304 err = self.__handleError(procUnitConfObj, modes=[2, 3], stdout=False)
1302 1305 except KeyboardInterrupt:
1303 1306 is_ok = False
1304 1307 break
1305 1308 except ValueError, e:
1306 1309 time.sleep(0.5)
1307 self.__handleError(procUnitConfObj)
1310 err = self.__handleError(procUnitConfObj)
1308 1311 is_ok = False
1309 1312 break
1310 1313 except:
1311 1314 time.sleep(0.5)
1312 self.__handleError(procUnitConfObj)
1315 err = self.__handleError(procUnitConfObj)
1313 1316 is_ok = False
1314 1317 break
1315 1318
@@ -1325,6 +1328,10 class Project(Process):
1325 1328 procUnitConfObj = self.procUnitConfObjDict[procKey]
1326 1329 procUnitConfObj.close()
1327 1330
1331 if err is not None:
1332 err.start()
1333 # err.join()
1334
1328 1335 log.success('{} finished (time: {}s)'.format(
1329 1336 self.name,
1330 1337 time.time()-self.start_time))
@@ -33,12 +33,19 def figpause(interval):
33 33 canvas = figManager.canvas
34 34 if canvas.figure.stale:
35 35 canvas.draw()
36 canvas.start_event_loop(interval)
36 try:
37 canvas.start_event_loop(interval)
38 except:
39 pass
37 40 return
38 41
39 42 def popup(message):
40 fig = plt.figure(figsize=(12, 8), facecolor='r')
41 fig.text(0.5, 0.5, message, ha='center', va='center', size='20', weight='heavy', color='w')
43 '''
44 '''
45
46 fig = plt.figure(figsize=(12, 8), facecolor='r')
47 text = '\n'.join([s.strip() for s in message.split(':')])
48 fig.text(0.01, 0.5, text, ha='left', va='center', size='20', weight='heavy', color='w')
42 49 fig.show()
43 50 figpause(1000)
44 51
@@ -20,6 +20,7 try:
20 20 except:
21 21 from time import sleep
22 22
23 import schainpy.admin
23 24 from schainpy.model.data.jroheaderIO import PROCFLAG, BasicHeader, SystemHeader, RadarControllerHeader, ProcessingHeader
24 25 from schainpy.model.data.jroheaderIO import get_dtype_index, get_numpy_dtype, get_procflag_dtype, get_dtype_width
25 26 from schainpy.utils import log
@@ -859,7 +860,7 class JRODataReader(JRODataIO):
859 860
860 861 firstTime_flag = False
861 862
862 print "\t[Reading] Skipping the file \"%s\" due to this file doesn't exist" % filename
863 log.warning('Skipping the file {} due to this file doesn\'t exist'.format(filename))
863 864 self.set += 1
864 865
865 866 # si no encuentro el file buscado cambio de carpeta y busco en la siguiente carpeta
@@ -883,7 +884,6 class JRODataReader(JRODataIO):
883 884 self.flagIsNewFile = 0
884 885 self.fp = None
885 886 self.flagNoMoreFiles = 1
886 # print '[Reading] No more files to read'
887 887
888 888 return fileOk_flag
889 889
@@ -896,8 +896,8 class JRODataReader(JRODataIO):
896 896 else:
897 897 newFile = self.__setNextFileOffline()
898 898
899 if not(newFile):
900 print '[Reading] No more files to read'
899 if not(newFile):
900 raise schainpy.admin.SchainWarning('No more files to read')
901 901 return 0
902 902
903 903 if self.verbose:
@@ -1318,11 +1318,11 class JRODataReader(JRODataIO):
1318 1318 if fullpath:
1319 1319 break
1320 1320
1321 print '[Reading] Waiting %0.2f sec for an valid file in %s: try %02d ...' % (self.delay, path, nTries + 1)
1322 sleep(self.delay)
1321 print '[Reading] Waiting %0.2f sec for an valid file in %s: try %02d ...' % (delay, path, nTries + 1)
1322 sleep(delay)
1323 1323
1324 if not(fullpath):
1325 print "[Reading] There 'isn't any valid file in %s" % path
1324 if not(fullpath):
1325 raise schainpy.admin.SchainWarning('There isn\'t any valid file in {}'.format(path))
1326 1326 return
1327 1327
1328 1328 self.year = year
General Comments 0
You need to be logged in to leave comments. Login now