improvement: replacing the use of LegacyVersion

This commit is contained in:
Vinicius Moreira
2022-11-25 06:57:22 -03:00
parent 69cf81dbe9
commit 93d2d66b71
15 changed files with 130 additions and 119 deletions

View File

@@ -5,10 +5,10 @@ from threading import Thread
from typing import Set, List, Tuple, Dict, Iterable, Optional, Generator, Pattern
from bauh.api.abstract.handler import ProcessWatcher
from bauh.commons.version_util import match_required_version
from bauh.gems.arch import pacman, message, sorting, confirmation
from bauh.gems.arch.aur import AURClient
from bauh.gems.arch.exceptions import PackageNotFoundException
from bauh.gems.arch.version import match_required_version
from bauh.view.util.translation import I18n

View File

@@ -5,7 +5,7 @@ from typing import Optional, List, Dict
from bauh.api.abstract.model import PackageStatus
from bauh.api.http import HttpClient
from bauh.gems.arch.model import ArchPackage
from bauh.gems.arch.version import normalize_version
from bauh.commons.version_util import normalize_version
from bauh.view.util.translation import I18n
URL_PKG_DOWNLOAD = 'https://aur.archlinux.org/{}'

View File

@@ -12,7 +12,7 @@ from bauh.gems.arch.dependencies import DependenciesAnalyser
from bauh.gems.arch.exceptions import PackageNotFoundException
from bauh.gems.arch.model import ArchPackage
from bauh.gems.arch.pacman import RE_DEP_OPERATORS
from bauh.gems.arch.version import match_required_version
from bauh.commons.version_util import match_required_version
from bauh.view.util.translation import I18n
@@ -22,8 +22,9 @@ class UpdateRequirementsContext:
aur_to_update: Dict[str, ArchPackage], repo_to_install: Dict[str, ArchPackage],
aur_to_install: Dict[str, ArchPackage], to_install: Dict[str, ArchPackage],
pkgs_data: Dict[str, dict], cannot_upgrade: Dict[str, UpgradeRequirement],
to_remove: Dict[str, UpgradeRequirement], installed_names: Dict[str, str], provided_map: Dict[str, Set[str]],
aur_index: Set[str], arch_config: dict, remote_provided_map: Dict[str, Set[str]], remote_repo_map: Dict[str, str],
to_remove: Dict[str, UpgradeRequirement], installed_names: Dict[str, str],
provided_map: Dict[str, Set[str]], aur_index: Set[str], arch_config: dict,
remote_provided_map: Dict[str, Set[str]], remote_repo_map: Dict[str, str],
root_password: Optional[str], aur_supported: bool):
self.to_update = to_update
self.repo_to_update = repo_to_update

View File

@@ -1,53 +0,0 @@
import re
from packaging.version import LegacyVersion
RE_VERSION_WITH_RELEASE = re.compile(r'^(.+)-\d+$')
RE_VERSION_WITH_EPOCH = re.compile(r'^\d+:(.+)$')
def normalize_version(version: str) -> LegacyVersion:
final_version = version.strip()
if not RE_VERSION_WITH_EPOCH.match(final_version):
final_version = f'0:{final_version}'
if not RE_VERSION_WITH_RELEASE.match(final_version):
final_version = f'{final_version}-1'
return LegacyVersion(final_version)
def match_required_version(current_version: str, operator: str, required_version: str) -> bool:
final_required, final_current = required_version.strip(), current_version.strip()
required_has_epoch = bool(RE_VERSION_WITH_EPOCH.match(final_required))
current_no_epoch = RE_VERSION_WITH_EPOCH.split(final_current)
current_has_epoch = len(current_no_epoch) > 1
if required_has_epoch and not current_has_epoch:
final_current = f'0:{final_current}'
elif current_has_epoch and not required_has_epoch:
final_current = current_no_epoch[1]
required_has_release = bool(RE_VERSION_WITH_RELEASE.match(final_required))
current_no_release = RE_VERSION_WITH_RELEASE.split(final_current)
current_has_release = len(current_no_release) > 1
if required_has_release and not current_has_release:
final_current = f'{final_current}-1'
elif current_has_release and not required_has_release:
final_current = current_no_release[1]
final_required, final_current = LegacyVersion(final_required), LegacyVersion(final_current)
if operator == '==' or operator == '=':
return final_current == final_required
elif operator == '>':
return final_current > final_required
elif operator == '>=':
return final_current >= final_required
elif operator == '<':
return final_current < final_required
elif operator == '<=':
return final_current <= final_required