##// END OF EJS Templates
Fix SendByFTP and add plot codes
jespinoza -
r1142:f05281601d69
parent child
Show More
@@ -39,15 +39,20 PLOT_CODES = {
39 'beacon' : 18,
39 'beacon': 18,
40 'wind' : 22,
40 'wind': 22,
41 'skymap' : 23,
41 'skymap': 23,
42 'V-E' : 25,
42 'Unknown': 24,
43 'Z-E' : 26,
43 'V-E': 25, # PIP Velocity.
44 'V-A' : 27,
44 'Z-E': 26, # PIP Reflectivity.
45 'Z-A' : 28,
45 'V-A': 27, # RHI Velocity.
46 'Z-A': 28, # RHI Reflectivity.
46 }
47 }
47
48
48 class PrettyFloat(float):
49 def get_plot_code(s):
49 def __repr__(self):
50 label = s.split('_')[0]
50 return '%.2f' % self
51 codes = [key for key in PLOT_CODES if key in label]
52 if codes:
53 return PLOT_CODES[codes[0]]
54 else:
55 return 24
51
56
52 def roundFloats(obj):
57 def roundFloats(obj):
53 if isinstance(obj, list):
58 if isinstance(obj, list):
@@ -753,7 +758,7 class SendToFTP(Operation, Process):
753 DOY_STR = '%3.3d'%thisDatetime.timetuple().tm_yday
758 DOY_STR = '%3.3d'%thisDatetime.timetuple().tm_yday
754 exp_code = '%3.3d'%exp_code
759 exp_code = '%3.3d'%exp_code
755 sub_exp_code = '%2.2d'%sub_exp_code
760 sub_exp_code = '%2.2d'%sub_exp_code
756 plot_code = '%2.2d'% PLOT_CODES[filename.split('_')[0].split('-')[1]]
761 plot_code = '%2.2d'% get_plot_code(filename)
757 name = YEAR_STR + DOY_STR + '00' + exp_code + sub_exp_code + plot_code + '00.png'
762 name = YEAR_STR + DOY_STR + '00' + exp_code + sub_exp_code + plot_code + '00.png'
758 return name
763 return name
759
764
@@ -766,24 +771,25 class SendToFTP(Operation, Process):
766
771
767 try:
772 try:
768 self.ftp.storbinary(command, fp, blocksize=1024)
773 self.ftp.storbinary(command, fp, blocksize=1024)
769 except ftplib.all_errors, e:
774 except Exception, e:
770 log.error('{}'.format(e), self.name)
775 log.error('{}'.format(e), self.name)
771 if self.ftp is not None:
776 if self.ftp is not None:
772 self.ftp.close()
777 self.ftp.close()
773 self.ftp = None
778 self.ftp = None
774 return
779 return 0
775
780
776 try:
781 try:
777 self.ftp.sendcmd('SITE CHMOD 755 {}'.format(dst))
782 self.ftp.sendcmd('SITE CHMOD 755 {}'.format(dst))
778 except ftplib.all_errors, e:
783 except Exception, e:
779 log.error('{}'.format(e), self.name)
784 log.error('{}'.format(e), self.name)
780 if self.ftp is not None:
785 if self.ftp is not None:
781 self.ftp.close()
786 self.ftp.close()
782 self.ftp = None
787 self.ftp = None
788 return 0
783
789
784 fp.close()
790 fp.close()
785
786 log.success('OK', tag='')
791 log.success('OK', tag='')
792 return 1
787
793
788 def send_files(self):
794 def send_files(self):
789
795
@@ -791,6 +797,9 class SendToFTP(Operation, Process):
791 local, remote, ext, delay, exp_code, sub_exp_code = pattern
797 local, remote, ext, delay, exp_code, sub_exp_code = pattern
792 if time.time()-self.times[x] >= delay:
798 if time.time()-self.times[x] >= delay:
793 srcname = self.find_files(local, ext)
799 srcname = self.find_files(local, ext)
800 src = os.path.join(local, srcname)
801 if os.path.getmtime(src) < time.time() - 30*60:
802 continue
794
803
795 if srcname is None or srcname == self.latest[x]:
804 if srcname is None or srcname == self.latest[x]:
796 continue
805 continue
@@ -800,20 +809,14 class SendToFTP(Operation, Process):
800 else:
809 else:
801 dstname = srcname
810 dstname = srcname
802
811
803 src = os.path.join(local, srcname)
804
805 if os.path.getmtime(src) < time.time() - 30*60:
806 continue
807
808 dst = os.path.join(remote, dstname)
812 dst = os.path.join(remote, dstname)
809
813
810 if self.ftp is None:
814 if self.upload(src, dst):
811 continue
812
813 self.upload(src, dst)
814
815 self.times[x] = time.time()
815 self.times[x] = time.time()
816 self.latest[x] = srcname
816 self.latest[x] = srcname
817 else:
818 self.isConfig = False
819 break
817
820
818 def run(self):
821 def run(self):
819
822
General Comments 0
You need to be logged in to leave comments. Login now