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