@@ -4,9 +4,10 | |||||
4 | import os |
|
4 | import os | |
5 | import glob |
|
5 | import glob | |
6 | import ftplib |
|
6 | import ftplib | |
|
7 | import multiprocessing | |||
7 | from model.proc.jroproc_base import ProcessingUnit, Operation |
|
8 | from model.proc.jroproc_base import ProcessingUnit, Operation | |
8 |
|
9 | |||
9 | class FTP(): |
|
10 | class FTP(object): | |
10 | """ |
|
11 | """ | |
11 | Ftp is a public class used to define custom File Transfer Protocol from "ftplib" python module |
|
12 | Ftp is a public class used to define custom File Transfer Protocol from "ftplib" python module | |
12 |
|
13 | |||
@@ -305,31 +306,31 class SendByFTP(Operation): | |||||
305 | print ValueError, 'Error FTP' |
|
306 | print ValueError, 'Error FTP' | |
306 | print "don't worry the program is running..." |
|
307 | print "don't worry the program is running..." | |
307 |
|
308 | |||
308 |
def |
|
309 | def worker_ftp(self, server, username, password, remotefolder, filenameList): | |
309 | if not(self.status): |
|
310 | ||
310 | return |
|
311 | self.ftpObj = FTP(server, username, password, remotefolder) | |
311 | try: |
|
312 | for filename in filenameList: | |
312 | self.ftpObj = FTP(server, username, password, remotefolder) |
|
313 | self.ftpObj.upload(filename) | |
313 | except: |
|
314 | self.ftpObj.close() | |
314 | self.error_print(ValueError) |
|
|||
315 | self.status = 0 |
|
|||
316 |
|
315 | |||
317 | def put(self): |
|
316 | def ftp_thread(self, server, username, password, remotefolder): | |
318 | if not(self.status): |
|
317 | if not(self.status): | |
319 | return |
|
318 | return | |
320 |
|
319 | |||
321 | try: |
|
320 | p = multiprocessing.Process(target=self.worker_ftp, args=(server, username, password, remotefolder, self.filenameList,)) | |
322 | for filename in self.filenameList: |
|
321 | p.start() | |
323 | self.ftpObj.upload(filename) |
|
322 | ||
324 | except: |
|
323 | p.join(3) | |
325 | self.error_print(ValueError) |
|
324 | ||
|
325 | if p.is_alive(): | |||
|
326 | p.terminate() | |||
|
327 | p.join() | |||
|
328 | print 'killing ftp process...' | |||
326 | self.status = 0 |
|
329 | self.status = 0 | |
327 |
|
||||
328 | def close(self): |
|
|||
329 | if not(self.status): |
|
|||
330 | return |
|
330 | return | |
331 |
|
331 | |||
332 |
self. |
|
332 | self.status = 1 | |
|
333 | return | |||
333 |
|
334 | |||
334 | def filterByExt(self, ext, localfolder): |
|
335 | def filterByExt(self, ext, localfolder): | |
335 | fnameList = glob.glob1(localfolder,ext) |
|
336 | fnameList = glob.glob1(localfolder,ext) | |
@@ -344,11 +345,9 class SendByFTP(Operation): | |||||
344 | if self.counter >= period: |
|
345 | if self.counter >= period: | |
345 | self.filterByExt(ext, localfolder) |
|
346 | self.filterByExt(ext, localfolder) | |
346 |
|
347 | |||
347 |
self. |
|
348 | self.ftp_thread(server, username, password, remotefolder) | |
348 |
|
349 | |||
349 | self.put() |
|
|||
350 |
|
||||
351 | self.close() |
|
|||
352 |
|
||||
353 | self.counter = 0 |
|
350 | self.counter = 0 | |
354 |
|
351 | |||
|
352 | self.status = 1 | |||
|
353 |
General Comments 0
You need to be logged in to leave comments.
Login now