diff --git a/pleskdistup/common/src/mariadb.py b/pleskdistup/common/src/mariadb.py index e9b5b07..66c60b4 100644 --- a/pleskdistup/common/src/mariadb.py +++ b/pleskdistup/common/src/mariadb.py @@ -3,6 +3,7 @@ import typing from . import dist, log +import re def is_version_larger(left: str, right: str) -> bool: @@ -56,6 +57,16 @@ def _extract_from_mysql_util(self, util_output: str): self.minor = int(minor_part) self.patch = int(patch_part) + def _extract_from_mariadb_util(self, util_output: str): + # String example: "mariadb from 11.6.2-MariaDB, client 15.2 for Linux (x86_64) using EditLine wrapper" + match = re.search(r"mariadb from (\d+)\.(\d+)\.(\d+)-MariaDB", util_output) + if not match: + raise ValueError(f"Cannot extract mariadb version from '{util_output}'") + major_part, minor_part, patch_part = match.groups() + self.major = int(major_part) + self.minor = int(minor_part) + self.patch = int(patch_part) + def __init__(self, to_extract: str): """Initialize a version object.""" self.major = 0 @@ -66,8 +77,10 @@ def __init__(self, to_extract: str): self._extract_from_version_str(to_extract) elif "Distrib" in to_extract: self._extract_from_mysql_util(to_extract) + elif to_extract.startswith("mariadb"): + self._extract_from_mariadb_util(to_extract) else: - raise ValueError(f"Cannot extract php version from '{to_extract}'") + raise ValueError(f"Cannot extract mariadb version from '{to_extract}'") def __str__(self): """Return a string representation of a PHPVersion object.""" @@ -88,8 +101,9 @@ def get_installed_mariadb_version() -> MariaDBVersion: if not utility: raise RuntimeError("Unable to find mariadb or mysql utility") out = subprocess.check_output([utility, "--version"], universal_newlines=True) - log.debug("Detected mariadb version is: {version}".format(version=out.split("Distrib ")[1].split(",")[0].split("-")[0])) - return MariaDBVersion(out) + result = MariaDBVersion(out) + log.debug(f"Detected mariadb version is: {result}") + return result def get_mariadb_config_file_path() -> str: diff --git a/pleskdistup/common/tests/mariadbtests.py b/pleskdistup/common/tests/mariadbtests.py index c19a83b..347e77c 100644 --- a/pleskdistup/common/tests/mariadbtests.py +++ b/pleskdistup/common/tests/mariadbtests.py @@ -6,16 +6,22 @@ class MariaDBVersionsTests(unittest.TestCase): def test_parse_simple(self): - php = mariadb.MariaDBVersion("10.6.12") - self.assertEqual(php.major, 10) - self.assertEqual(php.minor, 6) - self.assertEqual(php.patch, 12) + mariadb_ver = mariadb.MariaDBVersion("10.6.12") + self.assertEqual(mariadb_ver.major, 10) + self.assertEqual(mariadb_ver.minor, 6) + self.assertEqual(mariadb_ver.patch, 12) def test_parse_utility_output(self): - php = mariadb.MariaDBVersion("mysql Ver 15.1 Distrib 10.6.12-MariaDB, for debian-linux-gnu (x86_64) using EditLine wrapper") - self.assertEqual(php.major, 10) - self.assertEqual(php.minor, 6) - self.assertEqual(php.patch, 12) + mariadb_ver = mariadb.MariaDBVersion("mysql Ver 15.1 Distrib 10.6.12-MariaDB, for debian-linux-gnu (x86_64) using EditLine wrapper") + self.assertEqual(mariadb_ver.major, 10) + self.assertEqual(mariadb_ver.minor, 6) + self.assertEqual(mariadb_ver.patch, 12) + + def test_parse_utility_output_no_distrib(self): + mariadb_ver = mariadb.MariaDBVersion("mariadb from 11.6.2-MariaDB, client 15.2 for Linux (x86_64) using EditLine wrapper") + self.assertEqual(mariadb_ver.major, 11) + self.assertEqual(mariadb_ver.minor, 6) + self.assertEqual(mariadb_ver.patch, 2) def test_parse_wrong_string(self): with self.assertRaises(ValueError): diff --git a/pleskdistup/main.py b/pleskdistup/main.py index 679ec26..54f866a 100644 --- a/pleskdistup/main.py +++ b/pleskdistup/main.py @@ -289,9 +289,11 @@ def do_convert( if locale.getpreferredencoding(False).lower() != "utf-8": printerr(messages.ENCODING_INCONSISTENCY_ERROR_MESSAGE) - handle_error(str(e), logfile_path, util_name, options.status_flag_path, options.phase, upgrader) + full_error_message = f"Conversion failed due to encoding problem: {e}\nTrace: {traceback.format_exc()}" + handle_error(full_error_message, logfile_path, util_name, options.status_flag_path, options.phase, upgrader) return pleskdistup.convert.ConvertResult(success=False, reboot_requested=False) except Exception as e: + full_error_message = f"Conversion failed: {e}\nTrace: {traceback.format_exc()}" handle_error(str(e), logfile_path, util_name, options.status_flag_path, options.phase, upgrader) return pleskdistup.convert.ConvertResult(success=False, reboot_requested=False)