##// END OF EJS Templates
SendToServer:...
Miguel Valdez -
r633:bcf0a5d4812c
parent child
Show More
@@ -11,20 +11,19 try:
11 11 except:
12 12 print "You should install paramiko if you will use SSH protocol to upload files to a server"
13 13
14 import multiprocessing
15
16 14 import time
17 import threading
18 15
16 import threading
17 Thread = threading.Thread
19 18
20 try:
21 from gevent import sleep
22 except:
19 # try:
20 # from gevent import sleep
21 # except:
23 22 from time import sleep
24 23
25 24 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation
26 25
27 class Remote(threading.Thread):
26 class Remote(Thread):
28 27 """
29 28 Remote is a parent class used to define the behaviour of FTP and SSH class. These clases are
30 29 used to upload or download files remotely.
@@ -49,8 +48,7 class Remote(threading.Thread):
49 48
50 49 def __init__(self, server, username, password, remotefolder, period=60):
51 50
52 threading.Thread.__init__(self)
53 self._stop = threading.Event()
51 Thread.__init__(self)
54 52
55 53 self.setDaemon(True)
56 54
@@ -66,9 +64,12 class Remote(threading.Thread):
66 64 if self.open(server, username, password, remotefolder):
67 65 print "[Remote Server] %s server was opened successfully" %server
68 66
67 self.mutex = threading.Lock()
68
69 69 def stop(self):
70 70
71 71 self.stopFlag = True
72 self.join(10)
72 73
73 74 def open(self):
74 75 """
@@ -158,15 +159,16 class Remote(threading.Thread):
158 159 if fileList == self.fileList:
159 160 return 0
160 161
161 init = time.time()
162
163 while(self.bussy):
164 sleep(0.1)
165 if time.time() - init > 2*self.period:
166 return 0
162 self.mutex.acquire()
163 # init = time.time()
164 #
165 # while(self.bussy):
166 # sleep(0.1)
167 # if time.time() - init > 2*self.period:
168 # return 0
167 169
168 170 self.fileList = fileList
169
171 self.mutex.release()
170 172 return 1
171 173
172 174 def run(self):
@@ -182,19 +184,25 class Remote(threading.Thread):
182 184
183 185 while True:
184 186
185 sleep(self.period)
187 for i in range(self.period):
188 if self.stopFlag:
189 break
190 sleep(1)
191
192 if self.stopFlag:
193 break
186 194
187 self.bussy = True
195 # self.bussy = True
196 self.mutex.acquire()
188 197
189 198 for thisFile in self.fileList:
190 199 sts = self.upload(thisFile, self.remotefolder)
191 200 if not sts: break
192 201
193 self.bussy = False
194
195 if not sts: break
202 self.mutex.release()
203 # self.bussy = False
196 204
197 if self.stopFlag:
205 if not sts:
198 206 break
199 207
200 208 print "[Remote Server] Thread stopped successfully"
@@ -581,10 +589,15 class SendToServer(ProcessingUnit):
581 589 else:
582 590 folderList = self.localfolder
583 591
592 #Remove duplicate items
593 folderList = list(set(folderList))
594
584 595 fullfilenameList = []
585 596
586 597 for thisFolder in folderList:
587 598
599 print "[Remote Server]: Searching files on %s" %thisFolder
600
588 601 filenameList = glob.glob1(thisFolder, '*%s' %self.ext)
589 602
590 603 if len(filenameList) < 1:
@@ -592,6 +605,14 class SendToServer(ProcessingUnit):
592 605
593 606 for thisFile in filenameList:
594 607 fullfilename = os.path.join(thisFolder, thisFile)
608
609 if fullfilename in fullfilenameList:
610 continue
611
612 #Only files modified in the last 30 minutes are considered
613 if os.path.getmtime(fullfilename) < time.time() - 30*60:
614 continue
615
595 616 fullfilenameList.append(fullfilename)
596 617
597 618 return fullfilenameList
@@ -929,6 +950,8 class SendByFTP(Operation):
929 950 if not(self.status):
930 951 return
931 952
953 import multiprocessing
954
932 955 p = multiprocessing.Process(target=self.worker_ftp, args=(server, username, password, remotefolder, self.filenameList,))
933 956 p.start()
934 957
General Comments 0
You need to be logged in to leave comments. Login now