def attach_file(opener, bug_number, file):

    # default error response
    ret_val = 'Unknown error attaching log file to bug report'

    # The file names to be used
    local_file_name = "wb.log"
    zip_file_name = 'wb_log.zip'

    # Copies the file to the local folder
    normalized_path = file.replace("\\", "/")

    try:
        shutil.copyfile(normalized_path, local_file_name)

        # Creates the zip file
        zip_file = zipfile.ZipFile(zip_file_name, 'w')
        zip_file.write(local_file_name, os.path.basename(local_file_name),
                       zipfile.ZIP_DEFLATED)
        zip_file.close()

        # Reads the file as binary data
        zip_data = open(zip_file_name, 'rb').read()

        # Creates the list of fields to be encoded
        fields = [('MAX_FILE_SIZE', '512000'),
                  ('file_desc', 'Workbench Log File'), ('file_private', '1'),
                  ('file_add', 'Add file')]

        # Creates the file to be encoded
        files = [('file', zip_file_name, zip_data)]

        # Encodes the request data
        content_type, body = encode_multipart_formdata(fields, files)

        # Creates a custom request for the file submition
        request = urllib2.Request('http://bugs.mysql.com/bug.php?id=' +
                                  bug_number + '&files=2')
        request.add_unredirected_header('Content-Type', content_type)
        request.add_unredirected_header('Content-Length', str(len(body)))

        # Performs the request
        response = opener.open(request, body)

        data = response.read()

        parser = MySQLGetRequestResult()
        parser.feed(data)

        if parser.result_type == 'success':
            ret_val = ''
        else:
            ret_val = 'Error attaching the log file to the bug report'

    except urllib2.URLError, e:
        ret_val = 'Error attaching the log file to the bug report'
        log_error('WB Bug Report',
                  'Error attaching the log file: %s \n' % str(e))
Exemplo n.º 2
0
def attach_file(opener, bug_number, file):

    # default error response
    ret_val = 'Unknown error attaching log file to bug report'
    
    # The file names to be used
    local_file_name = "wb.log"
    zip_file_name = 'wb_log.zip'

    # Copies the file to the local folder
    normalized_path = file.replace("\\","/")

    try:
        shutil.copyfile(normalized_path, local_file_name)

        # Creates the zip file
        zip_file = zipfile.ZipFile(zip_file_name,'w')
        zip_file.write(local_file_name, os.path.basename(local_file_name), zipfile.ZIP_DEFLATED)
        zip_file.close()

        # Reads the file as binary data
        zip_data = open(zip_file_name,'rb').read()


        # Creates the list of fields to be encoded
        fields = [  ('MAX_FILE_SIZE','512000'),
                    ('file_desc', 'Workbench Log File'),
                    ('file_private' , '1'),
                    ('file_add' , 'Add file')]

        # Creates the file to be encoded
        files = [('file',zip_file_name, zip_data)]

        # Encodes the request data
        content_type, body = encode_multipart_formdata(fields, files)


        # Creates a custom request for the file submition
        request = urllib2.Request('http://bugs.mysql.com/bug.php?id=' + bug_number + '&files=2')
        request.add_unredirected_header('Content-Type', content_type)
        request.add_unredirected_header('Content-Length', str(len(body)))

        # Performs the request
        response = opener.open(request, body)

        data = response.read();

        parser = MySQLGetRequestResult()
        parser.feed(data)

        if parser.result_type == 'success':
            ret_val = ''
        else:
            ret_val = 'Error attaching the log file to the bug report'

    except urllib2.URLError, e:
        ret_val = 'Error attaching the log file to the bug report'
        log_error('WB Bug Report', 'Error attaching the log file: %s \n' % str(e))
def submit_bug(opener, data, log_file):

    # The default error in case of unknown failure
    ret_val = 'error|Unknown error while submitting the bug, please proceed through http://bugs.mysql.com/report.php'

    try:
        # Encodes the received information for the bug submition
        params = urllib.urlencode(data)

        # Submits the bug
        response = opener.open('http://bugs.mysql.com/report.php', params)

        # Reads the server response
        data = response.read()

        parser = MySQLGetRequestResult()
        parser.feed(data)

        # If we have a result...
        if parser.result_type != '':
            # Starts creating the result of the bug submition
            ret_val = parser.result_type + '|'

            # Creates the bug submition result
            new_line = "\n"
            result_data = new_line.join(parser.result)

            # When a log file is to be appended, tries uploading it
            # On error, add an entry into the bug submition result data
            if parser.result_type == 'success' and log_file != '':
                file_attach_error = attach_file(opener, parser.result[1][1:],
                                                log_file)

                if file_attach_error != '':
                    ret_val = ret_val + 'no_log_submitted: ' + file_attach_error + new_line

            ret_val = ret_val + result_data

    except urllib2.URLError, e:
        # The default error in case of unknown failure
        ret_val = 'error|An error occurred while submitting the report, please proceed through http://bugs.mysql.com/report.php'
        log_error(
            "WB Bug Report",
            'An error occurred while submitting the request: %s\n' % str(e))
Exemplo n.º 4
0
def submit_bug(opener, data, log_file):

    # The default error in case of unknown failure
    ret_val = 'error|Unknown error while submitting the bug, please proceed through http://bugs.mysql.com/report.php'

    try:
        # Encodes the received information for the bug submition
        params = urllib.urlencode(data)

        # Submits the bug
        response = opener.open('http://bugs.mysql.com/report.php', params)


        # Reads the server response
        data = response.read()

        parser = MySQLGetRequestResult()
        parser.feed(data)

        # If we have a result...
        if parser.result_type != '':
            # Starts creating the result of the bug submition
            ret_val = parser.result_type + '|'

            # Creates the bug submition result
            new_line = "\n"
            result_data = new_line.join(parser.result)

            # When a log file is to be appended, tries uploading it
            # On error, add an entry into the bug submition result data
            if parser.result_type == 'success' and log_file != '':
                file_attach_error = attach_file(opener, parser.result[1][1:], log_file)
                
                if file_attach_error != '':
                    ret_val = ret_val + 'no_log_submitted: ' + file_attach_error + new_line

            ret_val = ret_val + result_data
            
    except urllib2.URLError, e:
        # The default error in case of unknown failure
        ret_val = 'error|An error occurred while submitting the report, please proceed through http://bugs.mysql.com/report.php'
        log_error("WB Bug Report", 'An error occurred while submitting the request: %s\n' % str(e))