def multipart_post(filename, nees_path_id, expnum, trialnum, rep_num, datafolder, request_path = http_file_path, threading = threading_on, verbose = False): '''This is technically an upload post. It assumes that there has already been an FTP file uploaded to the NEEShub and is simply waiting assignment. This post will be the assignment. Args: filename: name of the file you wish to upload. nees_path_id: string with the format "NEES-YEAR-PRJID#.groups" This is NEEShub specified.. EXAMPLE: NEES-2007-0353.groups expnum: Experiment Number rep_num: Repetition Number trialnum: Trial Number datafolder: Folder where you wish to upload files within a Repetition. (request_path): HTTP Request Parameter, where the post is being made on the HTTP server. (threading): When True, it will create a new Thread for every post being made. (verbose): When True''' xml_sheet = multipart_http.generate_file_xml(filename, nees_path_id, expnum, trialnum, rep_num, datafolder) content_type, body = multipart_http.encode_multipart_formdata(xml_sheet, filename, utils.hub_username, utils.hub_password) headers = { 'Host' : httphost, 'Content-Type' : content_type, 'Content-Length': str(len(body)) } authentic_request = utils.authenticate_request(request_path) # If post is in threading mode, creates a separate thread that executes the post. if threading == True: threading_request = threading_http.requestThread('POST',authentic_request, body, headers, filename) threading_request.start() # If post is in non-threading mode, this creates a thread if threading == False: response_dictionary = conn.request('POST',authentic_request, body, headers) post_location = response_dictionary['location'] post_data = response_dictionary['data'] post_status = response_dictionary['status'] message = "%s posted to %s. Status: %s. Reply: %s" % (filename, post_location, post_status, post_data) nees_logging.append_log(neeshub_log_filename, message) return post_status, post_data, post_location
def multipart_post(self, filename, expnum, trialnum, ext, selector = http_file_path, verbose = False): '''This is technically an upload post. It assumes that there has already been an FTP file uploaded to the NEEShub and is simply waiting assignment. This post will be the assignment.''' full_filename = filename + ext xml_sheet = multipart_http.generate_file_xml(full_filename, expnum, trialnum, ext) content_type, body = multipart_http.encode_multipart_formdata(xml_sheet, full_filename, self.username, self.password) headers = { 'Host' : self.host, 'Content-Type' : content_type, 'Content-Length': str(len(body)) } request_path = '%s?GAsession=%s/%s' % (selector, self.username, self.password) self.conn.request('POST',request_path, body, headers) res = self.conn.getresponse() return res.status, res.reason, res.read(), res.getheader('location')