def return_dir(host,remote_path,otest_path): client_path=join_path(otest_path,remote_path) print "searching",client_path,remote_path sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect((host, 10001)) sock.sendall(encode_for_tcp(remote_path)) for path, dirs, files in os.walk(client_path): print path for file_name in files: #print file_name,"rod",host if file_name.endswith(".dat")==True or file_name.endswith(".inp")==True : local_file=os.path.join(path,file_name) target=os.path.join(path,file_name) if target.startswith(otest_path): target=target[len(otest_path):] if os.path.isfile(local_file): got_data=False try: sendfile = open(local_file, 'rb') #print "I will send",local_file,target,host data = sendfile.read() zip_data=data.encode("zlib") sendfile.close() got_data=True except: print "I could not open the file:"+local_file got_data=False if len(data)!=0 and got_data==True: try: sock.sendall(encode_for_tcp(target)+encode_for_tcp(len(zip_data))) sock.sendall(zip_data) except: print "I could not send the data!!!" return False #sock.close() sock.close() return True
def send_dir(self,node,directory): print "Coping directory ",directory," to ", self.nodes[node].ip_address sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect((self.nodes[node].ip_address, 10000)) sock.sendall(encode_for_tcp(directory)) #send job name print ">>>>>>>>>>>>>>>>>>>>>>>"+self.exe_name if os.path.isfile(self.exe_name)==False: return False exe_file_name=os.path.basename(self.exe_name) #send exe file sendfile = open(self.exe_name, 'rb') data = sendfile.read() data_zip=data.encode("zlib") sendfile.close() sock.sendall(encode_for_tcp(os.path.join(directory,exe_file_name))+encode_for_tcp(len(data_zip))) sock.sendall(data_zip) for path, dirs, files in os.walk(directory): for file_name in files: whole_file_name=os.path.join(path,file_name) #print whole_file_name,"rod",self.ip_address[node] sendfile = open(whole_file_name, 'rb') data = sendfile.read() data_zip=data.encode("zlib") sendfile.close() sock.sendall(encode_for_tcp(whole_file_name)+encode_for_tcp(len(data_zip))) sock.sendall(data_zip) sock.close() return True