def pack_attrs( job_attrs, connect_attrs ): """ Given job attributes and connection attributes, convert them into a Pragma HTTP header understandable to iftutil.iftd_HTTPServer_handler. """ # which protocols? proto_list = job_attrs.get(iftfile.JOB_ATTR_PROTOS) packed_attrs = [] if proto_list: for proto in proto_list: packed_attrs.append("protocol=" + str(proto)) # which connection attributes? for (proto, connect_dict) in connect_attrs.items(): for (k, v) in connect_dict.items(): packed_attrs.append( str(proto) + "=" + str(k) + ":" + str(v)) # load in job attributes for (k, v) in job_attrs.items(): packed_attrs.append( str(k) + "=" + str(v) ) # pack values together into a single string packed_str = "" for attr in packed_attrs: packed_str += attr + "\x01" packed_str = packed_str[:-1] return packed_str iftfile.acquire_iftfile_recv( self, self.ift_job.get_attr( iftfile.JOB_ATTR_DEST_NAME ), self.ift_job.attrs )
proto_instances.append( p ) # make sure the directory exists if not os.path.exists( job.get_attr( iftfile.JOB_ATTR_DEST_CHUNK_DIR ) ): iftlog.log(1, "WARNING: path " + job.get_attr( iftfile.JOB_ATTR_DEST_CHUNK_DIR ) + " does not exist, creating...") os.system("mkdir -p " + job.get_attr( iftfile.JOB_ATTR_DEST_CHUNK_DIR )) elif not os.path.isdir( job.get_attr( iftfile.JOB_ATTR_DEST_CHUNK_DIR ) ): iftlog.log(1, "WARNING: path " + job.get_attr( iftfile.JOB_ATTR_DEST_CHUNK_DIR ) + " exists and is not a directory...") path = job.get_attr( iftfile.JOB_ATTR_DEST_CHUNK_DIR ) + ".iftd_" + str(os.getpid()) job.set_attr( iftfile.JOB_ATTR_DEST_CHUNK_DIR, path ) # get an iftfile reference iftfile_ref = iftfile.acquire_iftfile_recv( xmit_id, job.get_attr( iftfile.JOB_ATTR_DEST_NAME ), job.attrs ) job.set_attr( iftfile.JOB_ATTR_IFTFILE, iftfile_ref ) # start up the receiving protocols iftlog.log(1, "iftreceive: protocol instances: " + str([p.name for p in proto_instances])) connected_protos = start_protos( user_job=job, connect_dict=connect_dict, protos=proto_instances, timeout=xmlrpc_response_time*2 ) connected_proto_names = [p.name for p in connected_protos] if len(connected_proto_names) == 0: iftlog.log(5, "iftreceive: no receiving protocols could be activated") iftfile.release_iftfile_recv( xmit_id, iftfile_ref.path ) iftfile.cleanup_chunks_dir( job.get_attr( iftfile.JOB_ATTR_DEST_NAME ), job.get_attr( iftfile.JOB_ATTR_FILE_HASH ) ) return E_NO_CONNECT # begin listening for the sender (both actively and passively) rc = TransferCore.begin_ift_recv( xmit_id, job, connected_protos, remote_iftd, -1, job.get_attr( iftfile.JOB_ATTR_TRANSFER_TIMEOUT ) ) if rc != 0: