Skip to content

Commit

Permalink
Add version parcing for mariadb utility
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikhail Sandakov committed Dec 20, 2024
1 parent 9d318bf commit 890a9e9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
11 changes: 10 additions & 1 deletion pleskdistup/common/src/mariadb.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ 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"
major_part, minor_part, patch_part = util_output.split("from ")[1].split("-MariaDB")[0].split(".")[:3]
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
Expand All @@ -66,8 +73,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."""
Expand Down
6 changes: 6 additions & 0 deletions pleskdistup/common/tests/mariadbtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ def test_parse_utility_output(self):
self.assertEqual(php.minor, 6)
self.assertEqual(php.patch, 12)

def test_parse_utility_output_no_distrib(self):
php = mariadb.MariaDBVersion("mariadb from 11.6.2-MariaDB, client 15.2 for Linux (x86_64) using EditLine wrapper")
self.assertEqual(php.major, 11)
self.assertEqual(php.minor, 6)
self.assertEqual(php.patch, 2)

def test_parse_wrong_string(self):
with self.assertRaises(ValueError):
mariadb.MariaDBVersion("nothing")
Expand Down

0 comments on commit 890a9e9

Please sign in to comment.