def write_module(version, charset_info, output_folder):
    """Write the Python module"""
    charset_module = os.path.join(output_folder, CHARSET_MODULE)
    logging.debug("Writing character sets to '{}'".format(charset_module))

    fp = codecs.open(charset_module, 'w', 'utf8')
    write_cpy_source_header(fp, version, start_year=2013)

    fp.write('"""This module contains the MySQL Server Character Sets"""\n\n')

    fp.write('MYSQL_CHARACTER_SETS = [\n')
    fp.write('    # (character set name, collation, default)\n')
    prev_id = 0
    for (id, charset, collation, default) in charset_info:
        for i in range(id - prev_id):
            fp.write('    None,\n')
        if default == 'Yes':
            default = 'True'
        else:
            default = 'False'
        fp.write('    ("{0}", "{1}", {2}),  # {3}\n'.format(
            charset, collation, default, id))
        prev_id = id + 1
    fp.write("]\n\n")
    print("Wrote {0}".format(charset_module))

    fp.close()
Example #2
0
    def _write_error_messages(self, language, locale_folder,
                              module_name, errtype=None):
        """Write the error messages to a Python module

        This method will write error messages for a certain language into a
        python module locate in the locale_folder. If the errtype is
        given, it will only write message corresponding to a certain error
        type.
        """
        modfile = os.path.join(locale_folder, language.replace('-','_'),
                               module_name)

        logging.debug("Writing error module for {}, ".format(
            modfile, self._mysql_version_str))
        fp = codecs.open(modfile, 'w', 'utf8')
        write_cpy_source_header(fp, self._mysql_version,  start_year=2013)

        fp.write("# Start MySQL Error messages\n")
        for err_name, err in self._errors.items():
            if errtype and err['type'] != errtype:
                continue

            try:
                err_msg = err['messages'][language]
            except KeyError:
                # No translation available
                continue

            err_msg = err_msg.replace('%d', '%s')
            err_msg = err_msg.replace('%lu', '%s')

            fp.write(u'{code} = u"{msg}"\n'.format(code=err_name, msg=err_msg))

        fp.write("# End MySQL Error messages\n\n")
        fp.close()
Example #3
0
def write_module(version, output_folder=None, dbconfig=None):
    """Write the module"""
    if not dbconfig:
        dbconfig = _DB_CONFIG.copy()

    output_folder = output_folder

    charset_module = os.path.join(output_folder, CHARSET_MODULE)
    logging.debug("Writing character sets to '{}'".format(
                  charset_module))

    fp = codecs.open(charset_module, 'w', 'utf8')
    write_cpy_source_header(fp, version, start_year=2013)

    cnx = mysql.connector.connect(**dbconfig)
    cur = cnx.cursor()

    cur.execute(
        "SELECT id, character_set_name, collation_name, is_default "
        "FROM collations ORDER BY id"
    )

    fp.write('"""This module contains the MySQL Server Character Sets"""\n\n')

    fp.write('MYSQL_CHARACTER_SETS = [\n')
    fp.write('    # (character set name, collation, default)\n')
    prev_id = 0
    for (id, charset, collation, default) in cur:
        for i in range(id - prev_id):
            fp.write('    None,\n')
        if default == 'Yes':
            default = 'True'
        else:
            default = 'False'
        fp.write('    ("{0}", "{1}", {2}),  # {3}\n'.format(
                 charset, collation, default, id))
        prev_id = id + 1
    fp.write("]\n\n")
    print("Wrote {0}".format(charset_module))

    cnx.close()
    fp.close()
Example #4
0
    def write_module(self, output_folder=None):
        output_folder = output_folder or self._output_folder

        errcode_module = os.path.join(output_folder, ERRCODE_MODULE)
        logging.debug("Writing error codes to '{}', MySQL v{}".format(
                      errcode_module, self._mysql_version_str))

        fp = codecs.open(errcode_module, 'w', 'utf8')
        write_cpy_source_header(fp, self._mysql_version, start_year=2013)

        fp.write("\"\"\"This module contains the MySQL Server "
            "and Client error codes\"\"\"\n\n")

        fp.write("# Start MySQL Errors\n")
        for err_name, err in self._errors.items():
            fp.write('{0} = {1}\n'.format(err_name, err['code']))

        fp.write("# End MySQL Errors\n\n")

        fp.close()
Example #5
0
def write_module(version, output_folder=None, dbconfig=None):
    """Write the module"""
    if not dbconfig:
        dbconfig = _DB_CONFIG.copy()

    output_folder = output_folder

    charset_module = os.path.join(output_folder, CHARSET_MODULE)
    logging.debug("Writing character sets to '{}'".format(charset_module))

    fp = codecs.open(charset_module, 'w', 'utf8')
    write_cpy_source_header(fp, version, start_year=2013)

    cnx = mysql.connector.connect(**dbconfig)
    cur = cnx.cursor()

    cur.execute("SELECT id, character_set_name, collation_name, is_default "
                "FROM collations ORDER BY id")

    fp.write('"""This module contains the MySQL Server Character Sets"""\n\n')

    fp.write('MYSQL_CHARACTER_SETS = [\n')
    fp.write('    # (character set name, collation, default)\n')
    prev_id = 0
    for (id, charset, collation, default) in cur:
        for i in range(id - prev_id):
            fp.write('    None,\n')
        if default == 'Yes':
            default = 'True'
        else:
            default = 'False'
        fp.write('    ("{0}", "{1}", {2}),  # {3}\n'.format(
            charset, collation, default, id))
        prev_id = id + 1
    fp.write("]\n\n")
    print("Wrote {0}".format(charset_module))

    cnx.close()
    fp.close()