@@ -4,9 +4,51 import time, datetime | |||||
4 | import mpldriver |
|
4 | import mpldriver | |
5 | from customftp import * |
|
5 | from customftp import * | |
6 |
|
6 | |||
|
7 | import Queue | |||
|
8 | import threading | |||
|
9 | ||||
|
10 | class FTP_Thread (threading.Thread): | |||
|
11 | def __init__(self): | |||
|
12 | threading.Thread.__init__(self) | |||
|
13 | self.exitFlag = 0 | |||
|
14 | self.queueLock = threading.Lock() | |||
|
15 | self.workQueue = Queue.Queue() | |||
|
16 | ||||
|
17 | def run(self): | |||
|
18 | self.send_data() | |||
|
19 | ||||
|
20 | def fin(self): | |||
|
21 | self.exitFlag = 1 | |||
|
22 | ||||
|
23 | def put_data(self, data): | |||
|
24 | # Fill the queue | |||
|
25 | self.queueLock.acquire() | |||
|
26 | self.workQueue.put(data) | |||
|
27 | self.queueLock.release() | |||
|
28 | ||||
|
29 | def send_data(self): | |||
|
30 | while not self.exitFlag: | |||
|
31 | if self.workQueue.qsize(): | |||
|
32 | ||||
|
33 | data = self.workQueue.get(True) | |||
|
34 | ||||
|
35 | try: | |||
|
36 | ftpObj = Ftp(host=data['server'], | |||
|
37 | username=data['username'], | |||
|
38 | passw=data['password'], | |||
|
39 | remotefolder=data['folder']) | |||
|
40 | ||||
|
41 | ftpObj.upload(data['figfilename']) | |||
|
42 | ftpObj.close() | |||
|
43 | except: | |||
|
44 | print ValueError, 'Error FTP' | |||
|
45 | print "don't worry still running the program" | |||
|
46 | ||||
|
47 | ||||
7 | class Figure: |
|
48 | class Figure: | |
8 |
|
49 | |||
9 | __driver = mpldriver |
|
50 | __driver = mpldriver | |
|
51 | __isConfigThread = False | |||
10 | fig = None |
|
52 | fig = None | |
11 |
|
53 | |||
12 | id = None |
|
54 | id = None | |
@@ -177,6 +219,19 class Figure: | |||||
177 | ftpObj.upload(figfilename) |
|
219 | ftpObj.upload(figfilename) | |
178 | ftpObj.close() |
|
220 | ftpObj.close() | |
179 |
|
221 | |||
|
222 | def sendByFTP_Thread(self, figfilename, server, folder, username, password): | |||
|
223 | data = {'figfilename':figfilename,'server':server,'folder':folder,'username':username,'password':password} | |||
|
224 | ||||
|
225 | if not(self.__isConfigThread): | |||
|
226 | ||||
|
227 | self.thread = FTP_Thread() | |||
|
228 | self.thread.start() | |||
|
229 | self.__isConfigThread = True | |||
|
230 | ||||
|
231 | self.thread.put_data(data) | |||
|
232 | print 'thread.isAlive()', self.thread.isAlive() | |||
|
233 | ||||
|
234 | ||||
180 | def getNameToFtp(self, thisDatetime, FTP_WEI, EXP_CODE, SUB_EXP_CODE, PLOT_CODE, PLOT_POS): |
|
235 | def getNameToFtp(self, thisDatetime, FTP_WEI, EXP_CODE, SUB_EXP_CODE, PLOT_CODE, PLOT_POS): | |
181 | YEAR_STR = '%4.4d'%thisDatetime.timetuple().tm_year |
|
236 | YEAR_STR = '%4.4d'%thisDatetime.timetuple().tm_year | |
182 | DOY_STR = '%3.3d'%thisDatetime.timetuple().tm_yday |
|
237 | DOY_STR = '%3.3d'%thisDatetime.timetuple().tm_yday |
@@ -596,11 +596,9 class SpectraPlot(Figure): | |||||
596 | ftp_file = os.path.join(path,'ftp','%s.png'%name) |
|
596 | ftp_file = os.path.join(path,'ftp','%s.png'%name) | |
597 | self.saveFigure(figpath, ftp_file) |
|
597 | self.saveFigure(figpath, ftp_file) | |
598 | ftp_filename = os.path.join(figpath,ftp_file) |
|
598 | ftp_filename = os.path.join(figpath,ftp_file) | |
599 | try: |
|
599 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) | |
600 | self.sendByFTP(ftp_filename, server, folder, username, password) |
|
600 | self.counter_imagwr = 0 | |
601 | except: |
|
601 | ||
602 | self.counter_imagwr = 0 |
|
|||
603 | print ValueError, 'Error FTP' |
|
|||
604 |
|
602 | |||
605 | self.counter_imagwr = 0 |
|
603 | self.counter_imagwr = 0 | |
606 |
|
604 |
General Comments 0
You need to be logged in to leave comments.
Login now