Skip to content

Commit

Permalink
fixup! Add a checker to ensure that the currently installed version o…
Browse files Browse the repository at this point in the history
…f Plesk is available on autoinstall.plesk.com
  • Loading branch information
Mikhail Sandakov committed Apr 16, 2024
1 parent 5bf5f21 commit 07f5722
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
16 changes: 9 additions & 7 deletions pleskdistup/common/src/plesk.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

from . import log, mariadb, systemd, version

# http://autoinstall.plesk.com/products.inf3 is a xml file with available products,
# including all versions of plesk.
DEFAULT_AUTOINSTALL_PRODUCTS_FILE = "http://autoinstall.plesk.com/products.inf3"

def send_error_report(error_message: str) -> None:
log.debug(f"Error report: {error_message}")
Expand All @@ -35,7 +38,7 @@ def get_plesk_version() -> version.PleskVersion:
raise Exception("Unable to parse plesk version output.")


def extract_plesk_versions(products_xml) -> typing.List[version.PleskVersion]:
def extract_plesk_versions(products_xml: str) -> typing.List[version.PleskVersion]:
if not products_xml:
return []

Expand All @@ -48,17 +51,16 @@ def extract_plesk_versions(products_xml) -> typing.List[version.PleskVersion]:
return versions


def get_available_plesk_versions() -> typing.List[version.PleskVersion]:
# http://autoinstall.plesk.com/products.inf3 is a xml file with available products,
# including all versions of plesk.
products_info_url = "http://autoinstall.plesk.com/products.inf3"
def get_available_plesk_versions(
autoinstall_products_file_url: str = DEFAULT_AUTOINSTALL_PRODUCTS_FILE
) -> typing.List[version.PleskVersion]:
try:
with urllib.request.urlopen(products_info_url) as response:
with urllib.request.urlopen(autoinstall_products_file_url) as response:
products_config = response.read().decode('utf-8')
return extract_plesk_versions(products_config)

except Exception as ex:
log.warn(f"Unable to retrieve available versions of plesk from '{products_info_url}': {ex}")
log.warn(f"Unable to retrieve available versions of plesk from '{autoinstall_products_file_url}': {ex}")
return []


Expand Down
28 changes: 14 additions & 14 deletions pleskdistup/common/src/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,17 @@ def __ge__(self, other) -> bool:


class PleskVersion():
"""Plesk version representation class."""
"""
Plesk version representation class.
Plesk version is represented as a string in format "major.minor.patch.hotfix".
Examples:
- "18.0.50"
- "18.0.51.2"
Versions could be compared with each other, represented as a string.
Available fields are: major, minor, patch and hotfix.
"""

major: int
minor: int
Expand All @@ -167,10 +177,7 @@ def _extract_from_version(self, version: str) -> None:
raise ValueError("Incorrect version length")

# Version string example is "18.0.50" or "18.0.50.2"
major_part, minor_part, patch_part = split_version[:3]
self.major = int(major_part)
self.minor = int(minor_part)
self.patch = int(patch_part)
self.major, self.minor, self.patch = map(int, split_version[:3])
if len(split_version) > 3:
self.hotfix = int(split_version[3])
else:
Expand All @@ -195,17 +202,10 @@ def __str__(self) -> str:
return f"{self.major}.{self.minor}.{self.patch}.{self.hotfix}"

def __lt__(self, other) -> bool:
if self.major != other.major:
return self.major < other.major
elif self.minor != other.minor:
return self.minor < other.minor
elif self.patch != other.patch:
return self.patch < other.patch

return self.hotfix < other.hotfix
return (self.major, self.minor, self.patch, self.hotfix) < (other.major, other.minor, other.patch, other.hotfix)

def __eq__(self, other) -> bool:
return self.major == other.major and self.minor == other.minor and self.patch == other.patch and self.hotfix == other.hotfix
return (self.major, self.minor, self.patch, self.hotfix) == (other.major, other.minor, other.patch, other.hotfix)

def __ge__(self, other) -> bool:
return not self.__lt__(other)

0 comments on commit 07f5722

Please sign in to comment.