equal
deleted
inserted
replaced
33 self.paths = paths |
33 self.paths = paths |
34 self.diamondsid = diamondsid |
34 self.diamondsid = diamondsid |
35 self.ftp = None |
35 self.ftp = None |
36 |
36 |
37 def upload(self): |
37 def upload(self): |
38 """upload""" |
38 """ Proceed to the upload. """ |
39 self._open() |
39 self._open() |
40 """ Proceed to the upload. """ |
|
41 monsyms = [] |
40 monsyms = [] |
42 i = 1 |
41 i = 1 |
43 for p_path in self.paths: |
42 for p_path in self.paths: |
44 if os.path.exists(p_path) and os.path.isfile(p_path): |
43 if os.path.exists(p_path) and os.path.isfile(p_path): |
45 # ftp://1.2.3.4/ctc_helium/[diamonds_id]/mon_syms/2/mon.sym |
44 # ftp://1.2.3.4/ctc_helium/[diamonds_id]/mon_syms/2/mon.sym |
46 outputdir = "ctc_helium/%s/mon_syms/%d" % (self.diamondsid , i) |
45 outputdir = "%s/mon_syms/%d" % (self.diamondsid , i) |
47 output = outputdir + "/MON.SYM" |
46 output = outputdir + "/MON.SYM" |
48 self._ftpmkdirs(outputdir) |
47 self._ftpmkdirs(outputdir) |
49 print "Copying %s under %s" % (p_path, output) |
48 print "Copying %s under %s" % (p_path, output) |
50 self._send(p_path, output) |
49 self._send(p_path, output) |
51 monsyms.append(output) |
50 monsyms.append(output) |
59 |
58 |
60 def _close(self): |
59 def _close(self): |
61 """close""" |
60 """close""" |
62 self.ftp.quit() |
61 self.ftp.quit() |
63 |
62 |
64 def _ftpmkdirs(self, dir): |
63 def _ftpmkdirs(self, dir_): |
65 """ftp make directory""" |
64 """ftp make directory""" |
66 pwd = self.ftp.pwd() |
65 pwd = self.ftp.pwd() |
67 for d_dir in dir.split('/'): |
66 for d_dir in dir_.split('/'): |
68 if len(d_dir)!=0: |
67 if len(d_dir) != 0: |
69 # pylint: disable-msg=W0704 |
|
70 #disable except not doing anything |
|
71 try: |
68 try: |
72 print "Creating %s under %s" % (d_dir, self.ftp.pwd()) |
69 print "Creating %s under %s" % (d_dir, self.ftp.pwd()) |
73 self.ftp.mkd(d_dir) |
70 self.ftp.mkd(d_dir) |
74 except ftplib.error_perm: #capture the exception but not display it. |
71 except ftplib.error_perm: #capture the exception but not display it. |
75 pass |
72 pass |
76 # pylint: enable-msg=W0704 |
|
77 self.ftp.cwd(d_dir) |
73 self.ftp.cwd(d_dir) |
78 self.ftp.cwd(pwd) |
74 self.ftp.cwd(pwd) |
79 |
75 |
80 def _send(self, src, dst): |
76 def _send(self, src, dst): |
81 """send """ |
77 """send """ |
82 self.ftp.storbinary("STOR " + dst, open(src, "rb"), 1024) |
78 try: |
|
79 self.ftp.storbinary("STOR " + dst, open(src, "rb"), 1024) |
|
80 except ftplib.error_perm, e: |
|
81 print 'File already uploaded. ' + str(e) |
|
82 |
|
83 |