From d903be96a0b2a0f03926ea487434a19dcf548f41 2018-01-11 18:22:56 From: jespinoza Date: 2018-01-11 18:22:56 Subject: [PATCH] Alarm working ok --- diff --git a/schainpy/admin.py b/schainpy/admin.py index 98617ca..ef2ed57 100644 --- a/schainpy/admin.py +++ b/schainpy/admin.py @@ -1,4 +1,5 @@ -"""The admin module contains all administrative classes relating to the schain python api. +""" +The admin module contains all administrative classes relating to the schain python api. The main role of this module is to send some reports. It contains a notification class and a standard error handing class. @@ -18,6 +19,7 @@ from email.mime.text import MIMEText from email.mime.application import MIMEApplication from email.mime.multipart import MIMEMultipart +import schainpy from schainpy.utils import log from schainpy.model.graphics.jroplot_data import popup @@ -39,13 +41,13 @@ class Alarm(Process): ''' modes: 0 - All - 1 - Sound alarm - 2 - Send email - 3 - Popup message + 1 - Send email + 2 - Popup message + 3 - Sound alarm 4 - Send to alarm system TODO ''' - def __init__(self, modes=[1], **kwargs): + def __init__(self, modes=[], **kwargs): Process.__init__(self) self.modes = modes self.kwargs = kwargs @@ -63,10 +65,13 @@ class Alarm(Process): @staticmethod def send_email(**kwargs): notifier = SchainNotify() + print kwargs notifier.notify(**kwargs) @staticmethod - def show_popup(message='Error'): + def show_popup(message): + if isinstance(message, list): + message = message[-1] popup(message) @staticmethod @@ -83,15 +88,15 @@ class Alarm(Process): def run(self): tasks = { 1 : self.send_email, - 2 : self.play_sound, - 3 : self.show_popup, + 2 : self.show_popup, + 3 : self.play_sound, 4 : self.send_alarm, } tasks_args = { 1: ['email', 'message', 'subject', 'subtitle', 'filename'], - 2: [], - 3: ['message'], + 2: ['message'], + 3: [], 4: [], } procs = [] diff --git a/schainpy/controller.py b/schainpy/controller.py index 2542e85..f44c4ce 100644 --- a/schainpy/controller.py +++ b/schainpy/controller.py @@ -908,7 +908,7 @@ class Project(Process): self.id = None self.description = None self.email = None - self.alarm = [0] + self.alarm = None self.plotterQueue = plotter_queue self.procUnitConfObjDict = {} @@ -956,7 +956,7 @@ class Project(Process): self.procUnitConfObjDict = newProcUnitConfObjDict - def setup(self, id, name='', description='', email=None, alarm=[0]): + def setup(self, id, name='', description='', email=None, alarm=[3]): print print '*' * 60 @@ -1180,7 +1180,7 @@ class Project(Process): self.__connect(puObjIN, thisPUObj) - def __handleError(self, procUnitConfObj, modes=None): + def __handleError(self, procUnitConfObj, modes=None, stdout=True): import socket @@ -1195,7 +1195,8 @@ class Project(Process): message = ''.join(err) - sys.stderr.write(message) + if stdout: + sys.stderr.write(message) subject = 'SChain v%s: Error running %s\n' % ( schainpy.__version__, procUnitConfObj.name) @@ -1227,7 +1228,7 @@ class Project(Process): filename=self.filename ) - a.start() + return a def isPaused(self): return 0 @@ -1286,6 +1287,8 @@ class Project(Process): keyList = self.procUnitConfObjDict.keys() keyList.sort() + err = None + while(True): is_ok = False @@ -1298,18 +1301,18 @@ class Project(Process): sts = procUnitConfObj.run() is_ok = is_ok or sts except SchainWarning: - self.__handleError(procUnitConfObj, modes=[2, 3]) + err = self.__handleError(procUnitConfObj, modes=[2, 3], stdout=False) except KeyboardInterrupt: is_ok = False break except ValueError, e: time.sleep(0.5) - self.__handleError(procUnitConfObj) + err = self.__handleError(procUnitConfObj) is_ok = False break except: time.sleep(0.5) - self.__handleError(procUnitConfObj) + err = self.__handleError(procUnitConfObj) is_ok = False break @@ -1325,6 +1328,10 @@ class Project(Process): procUnitConfObj = self.procUnitConfObjDict[procKey] procUnitConfObj.close() + if err is not None: + err.start() + # err.join() + log.success('{} finished (time: {}s)'.format( self.name, time.time()-self.start_time)) diff --git a/schainpy/model/graphics/jroplot_data.py b/schainpy/model/graphics/jroplot_data.py index cb401c4..8c3aafe 100644 --- a/schainpy/model/graphics/jroplot_data.py +++ b/schainpy/model/graphics/jroplot_data.py @@ -33,12 +33,19 @@ def figpause(interval): canvas = figManager.canvas if canvas.figure.stale: canvas.draw() - canvas.start_event_loop(interval) + try: + canvas.start_event_loop(interval) + except: + pass return def popup(message): - fig = plt.figure(figsize=(12, 8), facecolor='r') - fig.text(0.5, 0.5, message, ha='center', va='center', size='20', weight='heavy', color='w') + ''' + ''' + + fig = plt.figure(figsize=(12, 8), facecolor='r') + text = '\n'.join([s.strip() for s in message.split(':')]) + fig.text(0.01, 0.5, text, ha='left', va='center', size='20', weight='heavy', color='w') fig.show() figpause(1000) diff --git a/schainpy/model/io/jroIO_base.py b/schainpy/model/io/jroIO_base.py index 04e9232..6d6bc14 100644 --- a/schainpy/model/io/jroIO_base.py +++ b/schainpy/model/io/jroIO_base.py @@ -20,6 +20,7 @@ try: except: from time import sleep +import schainpy.admin from schainpy.model.data.jroheaderIO import PROCFLAG, BasicHeader, SystemHeader, RadarControllerHeader, ProcessingHeader from schainpy.model.data.jroheaderIO import get_dtype_index, get_numpy_dtype, get_procflag_dtype, get_dtype_width from schainpy.utils import log @@ -859,7 +860,7 @@ class JRODataReader(JRODataIO): firstTime_flag = False - print "\t[Reading] Skipping the file \"%s\" due to this file doesn't exist" % filename + log.warning('Skipping the file {} due to this file doesn\'t exist'.format(filename)) self.set += 1 # si no encuentro el file buscado cambio de carpeta y busco en la siguiente carpeta @@ -883,7 +884,6 @@ class JRODataReader(JRODataIO): self.flagIsNewFile = 0 self.fp = None self.flagNoMoreFiles = 1 -# print '[Reading] No more files to read' return fileOk_flag @@ -896,8 +896,8 @@ class JRODataReader(JRODataIO): else: newFile = self.__setNextFileOffline() - if not(newFile): - print '[Reading] No more files to read' + if not(newFile): + raise schainpy.admin.SchainWarning('No more files to read') return 0 if self.verbose: @@ -1318,11 +1318,11 @@ class JRODataReader(JRODataIO): if fullpath: break - print '[Reading] Waiting %0.2f sec for an valid file in %s: try %02d ...' % (self.delay, path, nTries + 1) - sleep(self.delay) + print '[Reading] Waiting %0.2f sec for an valid file in %s: try %02d ...' % (delay, path, nTries + 1) + sleep(delay) - if not(fullpath): - print "[Reading] There 'isn't any valid file in %s" % path + if not(fullpath): + raise schainpy.admin.SchainWarning('There isn\'t any valid file in {}'.format(path)) return self.year = year