Example #1
0
    def multipart_post_generic(self, filename, expnum, trialnum, 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
        xml_sheet           = multipart_http.generate_report_xml(full_filename, expnum, trialnum)
        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')
Example #2
0
def multipart_post_generic(filename, nees_path_id, expnum, trialnum, selector = http_file_path, threading=False, 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
        trialnum: Trial Number
        (selector): 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'''
    full_filename       = filename
    xml_sheet           = multipart_http.generate_report_xml(full_filename, nees_path_id, expnum, trialnum)
    content_type, body  = multipart_http.encode_multipart_formdata(xml_sheet, full_filename, utils.hub_username, utils.hub_password)


    headers         = { 
                       'Host'          : httphost,
                       'Content-Type'  : content_type,
                       'Content-Length': str(len(body))
                       }


    authentic_request = utils.authenticate_request(selector)

    if threading == True:
        threading_request = threading_http.requestThread('POST',authentic_request, body, headers)
        threading_request.start()

    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']
        return post_status, post_data, post_location