@@ -640,6 +640,7 class Project(Process): | |||||
640 | #print("CONF: ",conf) |
|
640 | #print("CONF: ",conf) | |
641 | ok = conf.run() |
|
641 | ok = conf.run() | |
642 | if ok == 'Error': |
|
642 | if ok == 'Error': | |
|
643 | #self.removeProcUnit(conf.id) #remove proc Unit | |||
643 | n -= 1 |
|
644 | n -= 1 | |
644 | continue |
|
645 | continue | |
645 | elif not ok: |
|
646 | elif not ok: |
@@ -651,6 +651,8 class HDFWrite(Operation): | |||||
651 | #Write data |
|
651 | #Write data | |
652 | self.writeData(self.fp) |
|
652 | self.writeData(self.fp) | |
653 | log.log('Block No. {}/{} --> {}'.format(self.blockIndex+1, self.blocksPerFile,self.dataOut.datatime.ctime()), self.name) |
|
653 | log.log('Block No. {}/{} --> {}'.format(self.blockIndex+1, self.blocksPerFile,self.dataOut.datatime.ctime()), self.name) | |
|
654 | elif (self.blockIndex % 10 ==0): | |||
|
655 | log.log('Block No. {}/{} --> {}'.format(self.blockIndex+1, self.blocksPerFile,self.dataOut.datatime.ctime()), self.name) | |||
654 | else: |
|
656 | else: | |
655 |
|
657 | |||
656 | log.log('Block No. {}/{}'.format(self.blockIndex+1, self.blocksPerFile), self.name) |
|
658 | log.log('Block No. {}/{}'.format(self.blockIndex+1, self.blocksPerFile), self.name) |
@@ -769,6 +769,9 class FTP(object): | |||||
769 | Non-standard Python modules used: None |
|
769 | Non-standard Python modules used: None | |
770 |
|
770 | |||
771 | Written by "Daniel Suarez":mailto:daniel.suarez@jro.igp.gob.pe Oct. 26, 2010 |
|
771 | Written by "Daniel Suarez":mailto:daniel.suarez@jro.igp.gob.pe Oct. 26, 2010 | |
|
772 | ||||
|
773 | Modified: | |||
|
774 | Joab Apaza Feb. 2022 | |||
772 | """ |
|
775 | """ | |
773 |
|
776 | |||
774 | def __init__(self,server = None, username=None, password=None, remotefolder=None): |
|
777 | def __init__(self,server = None, username=None, password=None, remotefolder=None): | |
@@ -868,9 +871,9 class FTP(object): | |||||
868 | self.ftp.mkd(dirname) |
|
871 | self.ftp.mkd(dirname) | |
869 | except: |
|
872 | except: | |
870 | print('Error creating remote folder:%s'%dirname) |
|
873 | print('Error creating remote folder:%s'%dirname) | |
871 |
return |
|
874 | return False | |
872 |
|
875 | |||
873 |
return |
|
876 | return True | |
874 |
|
877 | |||
875 |
|
878 | |||
876 | def delete(self,filename): |
|
879 | def delete(self,filename): | |
@@ -888,9 +891,9 class FTP(object): | |||||
888 | self.ftp.delete(filename) |
|
891 | self.ftp.delete(filename) | |
889 | except: |
|
892 | except: | |
890 | print('Error deleting remote file:%s'%filename) |
|
893 | print('Error deleting remote file:%s'%filename) | |
891 |
return |
|
894 | return False | |
892 |
|
895 | |||
893 |
return |
|
896 | return True | |
894 |
|
897 | |||
895 | def download(self,filename,localfolder): |
|
898 | def download(self,filename,localfolder): | |
896 | """ |
|
899 | """ | |
@@ -938,15 +941,17 class FTP(object): | |||||
938 | self.file.write(block) |
|
941 | self.file.write(block) | |
939 |
|
942 | |||
940 |
|
943 | |||
941 | def upload(self,filename,remotefolder=None): |
|
944 | def upload(self,filename,remotefolder=None, mkdir=False): | |
942 | """ |
|
945 | """ | |
943 | upload is used to uploading local file to remote directory |
|
946 | upload is used to uploading local file to remote directory, and change the permission of the remote file | |
944 |
|
947 | |||
945 | Inputs: |
|
948 | Inputs: | |
946 | filename - full path name of local file to store in remote directory |
|
949 | filename - full path name of local file to store in remote directory | |
947 |
|
950 | |||
948 | remotefolder - remote directory |
|
951 | remotefolder - remote directory | |
949 |
|
952 | |||
|
953 | mkdir - if the remote folder doesn't exist, it will created | |||
|
954 | ||||
950 | Returns: |
|
955 | Returns: | |
951 | self.status - 1 in error case else 0 |
|
956 | self.status - 1 in error case else 0 | |
952 | """ |
|
957 | """ | |
@@ -954,6 +959,12 class FTP(object): | |||||
954 | if remotefolder == None: |
|
959 | if remotefolder == None: | |
955 | remotefolder = self.remotefolder |
|
960 | remotefolder = self.remotefolder | |
956 |
|
961 | |||
|
962 | if mkdir: | |||
|
963 | if self.if_dir_exist(remotefolder): | |||
|
964 | pass | |||
|
965 | else: | |||
|
966 | self.mkdir_r(remotefolder) | |||
|
967 | ||||
957 | self.status = 0 |
|
968 | self.status = 0 | |
958 |
|
969 | |||
959 | try: |
|
970 | try: | |
@@ -967,6 +978,7 class FTP(object): | |||||
967 |
|
978 | |||
968 | print('Uploading: ' + tail) |
|
979 | print('Uploading: ' + tail) | |
969 | self.ftp.storbinary(command, self.file) |
|
980 | self.ftp.storbinary(command, self.file) | |
|
981 | print(self.cmd('SITE CHMOD 755 {}'.format(tail))) | |||
970 | print('Upload Completed') |
|
982 | print('Upload Completed') | |
971 |
|
983 | |||
972 | except ftplib.all_errors: |
|
984 | except ftplib.all_errors: | |
@@ -982,9 +994,9 class FTP(object): | |||||
982 | return self.status |
|
994 | return self.status | |
983 |
|
995 | |||
984 |
|
996 | |||
985 | def dir(self,remotefolder): |
|
997 | def ch_dir(self,remotefolder): | |
986 | """ |
|
998 | """ | |
987 | dir is used to change working directory of remote server and get folder and file list |
|
999 | ch_dir is used to change working directory of remote server and get folder and file list | |
988 |
|
1000 | |||
989 | Input: |
|
1001 | Input: | |
990 | remotefolder - current working directory |
|
1002 | remotefolder - current working directory | |
@@ -1039,8 +1051,6 class FTP(object): | |||||
1039 | self.folderList.append(f) |
|
1051 | self.folderList.append(f) | |
1040 |
|
1052 | |||
1041 | return infoList,self.folderList |
|
1053 | return infoList,self.folderList | |
1042 |
|
||||
1043 |
|
||||
1044 | def close(self): |
|
1054 | def close(self): | |
1045 | """ |
|
1055 | """ | |
1046 | close is used to close and end FTP connection |
|
1056 | close is used to close and end FTP connection | |
@@ -1051,6 +1061,85 class FTP(object): | |||||
1051 |
|
1061 | |||
1052 | """ |
|
1062 | """ | |
1053 | self.ftp.close() |
|
1063 | self.ftp.close() | |
|
1064 | ||||
|
1065 | def get_sub_dirs(self, path): | |||
|
1066 | """ | |||
|
1067 | used internal | |||
|
1068 | ||||
|
1069 | Inputs: | |||
|
1070 | path - path to split in sub folders | |||
|
1071 | ||||
|
1072 | Returns: | |||
|
1073 | sub_dirs - list of sub folders | |||
|
1074 | """ | |||
|
1075 | sub_dirs = path.split("/") | |||
|
1076 | if sub_dirs[0]=="/": | |||
|
1077 | sub_dirs.pop(0) | |||
|
1078 | if sub_dirs[-1]=="/": | |||
|
1079 | sub_dirs.pop(-1) | |||
|
1080 | return sub_dirs | |||
|
1081 | ||||
|
1082 | def if_dir_exist(self,path): | |||
|
1083 | """ | |||
|
1084 | check if a the path folder exists in the ftp server | |||
|
1085 | ||||
|
1086 | Inputs: | |||
|
1087 | path - path to check | |||
|
1088 | ||||
|
1089 | Returns: | |||
|
1090 | status - True if exists and False if it doesn't | |||
|
1091 | """ | |||
|
1092 | sub_dirs = self.get_sub_dirs(path) | |||
|
1093 | main = self.ftp.pwd() | |||
|
1094 | #print(main) | |||
|
1095 | for subdir in sub_dirs: | |||
|
1096 | folders = self.ftp.nlst(main) | |||
|
1097 | #print(folders) | |||
|
1098 | if (os.path.join(main,subdir) in folders): | |||
|
1099 | main = os.path.join(main,subdir) | |||
|
1100 | #print(main) | |||
|
1101 | continue | |||
|
1102 | else: | |||
|
1103 | return False | |||
|
1104 | return True | |||
|
1105 | ||||
|
1106 | def cmd(self,command): | |||
|
1107 | """ | |||
|
1108 | excecute a command in the FTP server | |||
|
1109 | """ | |||
|
1110 | return self.ftp.sendcmd(command) | |||
|
1111 | ||||
|
1112 | def mkdir_r(self,path): | |||
|
1113 | """ | |||
|
1114 | create a remote folder and create sub folders if it is necessary | |||
|
1115 | ||||
|
1116 | Inputs: | |||
|
1117 | path - path to create | |||
|
1118 | ||||
|
1119 | Returns: | |||
|
1120 | status - True if succesfull else False | |||
|
1121 | """ | |||
|
1122 | sub_dirs = self.get_sub_dirs(path) | |||
|
1123 | main = self.ftp.pwd() | |||
|
1124 | st = False | |||
|
1125 | #print(main) | |||
|
1126 | for subdir in sub_dirs: | |||
|
1127 | folders = self.ftp.nlst(main) | |||
|
1128 | #print(folders) | |||
|
1129 | folder = (os.path.join(main,subdir)) | |||
|
1130 | ||||
|
1131 | if (folder in folders): | |||
|
1132 | main = folder | |||
|
1133 | #print("new_main",main) | |||
|
1134 | continue | |||
|
1135 | else: | |||
|
1136 | print("creating...",folder) | |||
|
1137 | st = self.mkd(folder) | |||
|
1138 | print(self.cmd('SITE CHMOD 755 {}'.format(folder))) | |||
|
1139 | main = folder | |||
|
1140 | ||||
|
1141 | return st | |||
|
1142 | ||||
1054 | @MPDecorator |
|
1143 | @MPDecorator | |
1055 | class SendByFTP(Operation): |
|
1144 | class SendByFTP(Operation): | |
1056 |
|
1145 |
General Comments 0
You need to be logged in to leave comments.
Login now