# # Copyright (c) 2016, 2024, Oracle and/or its affiliates. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License, version 2.0, # as published by the Free Software Foundation. # # This program is designed to work with certain software (including # but not limited to OpenSSL) that is licensed under separate terms, # as designated in a particular file or component or in included license # documentation. The authors of MySQL hereby grant you an additional # permission to link the program and your derivative works with the # separately licensed software that they have either included with # the program or referenced in the documentation. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See # the GNU General Public License, version 2.0, for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # """ Module to manage (read and write) MySQL option files. """ from __future__ import print_function import codecs import logging import os import re import shutil import sys import stat # Use backported OrderedDict if not available (for Python 2.6) try: from collections import OrderedDict except ImportError: from ordered_dict_backport import OrderedDict from mysql_gadgets.exceptions import GadgetConfigParserError, GadgetError from mysql_gadgets.common.tools import get_abs_path, fs_encode, fs_decode from mysql_gadgets.common.logger import CustomLevelLogger # Get logger (must set class to custom logger to be used). logging.setLoggerClass(CustomLevelLogger) _LOGGER = logging.getLogger(__name__) PY2 = int(sys.version[0]) == 2 # pylint: disable=F0401 # pylint: disable=E0012, C0413, C0411 if PY2: from ConfigParser import (RawConfigParser, NoOptionError, NoSectionError, Error, MissingSectionHeaderError, ParsingError) else: from configparser import (RawConfigParser, NoOptionError, NoSectionError, Error, MissingSectionHeaderError, DuplicateSectionError, SectionProxy, DuplicateOptionError) unicode = str DEFAULT_EXTENSIONS = { 'nt': ('ini', 'cnf'), 'posix': ('cnf',) } MYSQL_OPTCRE_NV = re.compile( r'\s*' # any starting space/tab r'(?P