diff --git a/schainpy/controller.py b/schainpy/controller.py index 0ed7b6c..087b7a2 100644 --- a/schainpy/controller.py +++ b/schainpy/controller.py @@ -640,6 +640,7 @@ class Project(Process): #print("CONF: ",conf) ok = conf.run() if ok == 'Error': + #self.removeProcUnit(conf.id) #remove proc Unit n -= 1 continue elif not ok: diff --git a/schainpy/model/io/jroIO_param.py b/schainpy/model/io/jroIO_param.py index 6932c37..e74e7ac 100644 --- a/schainpy/model/io/jroIO_param.py +++ b/schainpy/model/io/jroIO_param.py @@ -651,6 +651,8 @@ class HDFWrite(Operation): #Write data self.writeData(self.fp) log.log('Block No. {}/{} --> {}'.format(self.blockIndex+1, self.blocksPerFile,self.dataOut.datatime.ctime()), self.name) + elif (self.blockIndex % 10 ==0): + log.log('Block No. {}/{} --> {}'.format(self.blockIndex+1, self.blocksPerFile,self.dataOut.datatime.ctime()), self.name) else: log.log('Block No. {}/{}'.format(self.blockIndex+1, self.blocksPerFile), self.name) diff --git a/schainpy/model/utils/jroutils_ftp.py b/schainpy/model/utils/jroutils_ftp.py index 10cab6b..68db780 100644 --- a/schainpy/model/utils/jroutils_ftp.py +++ b/schainpy/model/utils/jroutils_ftp.py @@ -769,6 +769,9 @@ class FTP(object): Non-standard Python modules used: None Written by "Daniel Suarez":mailto:daniel.suarez@jro.igp.gob.pe Oct. 26, 2010 + + Modified: + Joab Apaza Feb. 2022 """ def __init__(self,server = None, username=None, password=None, remotefolder=None): @@ -868,9 +871,9 @@ class FTP(object): self.ftp.mkd(dirname) except: print('Error creating remote folder:%s'%dirname) - return 1 + return False - return 0 + return True def delete(self,filename): @@ -888,9 +891,9 @@ class FTP(object): self.ftp.delete(filename) except: print('Error deleting remote file:%s'%filename) - return 1 + return False - return 0 + return True def download(self,filename,localfolder): """ @@ -938,15 +941,17 @@ class FTP(object): self.file.write(block) - def upload(self,filename,remotefolder=None): + def upload(self,filename,remotefolder=None, mkdir=False): """ - upload is used to uploading local file to remote directory + upload is used to uploading local file to remote directory, and change the permission of the remote file Inputs: filename - full path name of local file to store in remote directory remotefolder - remote directory + mkdir - if the remote folder doesn't exist, it will created + Returns: self.status - 1 in error case else 0 """ @@ -954,6 +959,12 @@ class FTP(object): if remotefolder == None: remotefolder = self.remotefolder + if mkdir: + if self.if_dir_exist(remotefolder): + pass + else: + self.mkdir_r(remotefolder) + self.status = 0 try: @@ -967,6 +978,7 @@ class FTP(object): print('Uploading: ' + tail) self.ftp.storbinary(command, self.file) + print(self.cmd('SITE CHMOD 755 {}'.format(tail))) print('Upload Completed') except ftplib.all_errors: @@ -982,9 +994,9 @@ class FTP(object): return self.status - def dir(self,remotefolder): + def ch_dir(self,remotefolder): """ - dir is used to change working directory of remote server and get folder and file list + ch_dir is used to change working directory of remote server and get folder and file list Input: remotefolder - current working directory @@ -1039,8 +1051,6 @@ class FTP(object): self.folderList.append(f) return infoList,self.folderList - - def close(self): """ close is used to close and end FTP connection @@ -1051,6 +1061,85 @@ class FTP(object): """ self.ftp.close() + + def get_sub_dirs(self, path): + """ + used internal + + Inputs: + path - path to split in sub folders + + Returns: + sub_dirs - list of sub folders + """ + sub_dirs = path.split("/") + if sub_dirs[0]=="/": + sub_dirs.pop(0) + if sub_dirs[-1]=="/": + sub_dirs.pop(-1) + return sub_dirs + + def if_dir_exist(self,path): + """ + check if a the path folder exists in the ftp server + + Inputs: + path - path to check + + Returns: + status - True if exists and False if it doesn't + """ + sub_dirs = self.get_sub_dirs(path) + main = self.ftp.pwd() + #print(main) + for subdir in sub_dirs: + folders = self.ftp.nlst(main) + #print(folders) + if (os.path.join(main,subdir) in folders): + main = os.path.join(main,subdir) + #print(main) + continue + else: + return False + return True + + def cmd(self,command): + """ + excecute a command in the FTP server + """ + return self.ftp.sendcmd(command) + + def mkdir_r(self,path): + """ + create a remote folder and create sub folders if it is necessary + + Inputs: + path - path to create + + Returns: + status - True if succesfull else False + """ + sub_dirs = self.get_sub_dirs(path) + main = self.ftp.pwd() + st = False + #print(main) + for subdir in sub_dirs: + folders = self.ftp.nlst(main) + #print(folders) + folder = (os.path.join(main,subdir)) + + if (folder in folders): + main = folder + #print("new_main",main) + continue + else: + print("creating...",folder) + st = self.mkd(folder) + print(self.cmd('SITE CHMOD 755 {}'.format(folder))) + main = folder + + return st + @MPDecorator class SendByFTP(Operation):