Updated for new added packages

Signed-off-by: Dimitris Zlatanidis <d.zlatanidis@gmail.com>
This commit is contained in:
Dimitris Zlatanidis 2024-09-22 23:36:18 +03:00
parent 9de0813d56
commit ded1282381
2 changed files with 14 additions and 7 deletions

View file

@ -9,7 +9,7 @@ from slpkg.utilities import Utilities
from slpkg.dialog_box import DialogBox from slpkg.dialog_box import DialogBox
class Choose(Configs): class Choose(Configs): # pylint: disable=[R0902]
"""Choose packages with dialog utility and -S, --search flag.""" """Choose packages with dialog utility and -S, --search flag."""
def __init__(self, repository: str): def __init__(self, repository: str):
@ -23,8 +23,9 @@ class Choose(Configs):
self.height: int = 10 self.height: int = 10
self.width: int = 70 self.width: int = 70
self.list_height: int = 0 self.list_height: int = 0
self.ordered: bool = True
def packages(self, data: dict, packages: list, method: str) -> list: def packages(self, data: dict, packages: list, method: str, ordered: bool = True) -> list:
"""Call methods to choosing packages via dialog tool. """Call methods to choosing packages via dialog tool.
Args: Args:
@ -38,6 +39,7 @@ class Choose(Configs):
Raises: Raises:
SystemExit: Exit code 0. SystemExit: Exit code 0.
""" """
self.ordered: bool = ordered
if self.dialog: if self.dialog:
title: str = f' Choose packages you want to {method} ' title: str = f' Choose packages you want to {method} '
@ -74,7 +76,10 @@ class Choose(Configs):
def choose_for_upgraded(self, data: dict, packages: list) -> None: def choose_for_upgraded(self, data: dict, packages: list) -> None:
"""Choose packages that they will going to upgrade.""" """Choose packages that they will going to upgrade."""
for package in sorted(packages): if self.ordered:
packages: list = sorted(packages)
for package in packages:
inst_package: str = self.utils.is_package_installed(package) inst_package: str = self.utils.is_package_installed(package)
inst_package_version: str = self.utils.split_package(inst_package)['version'] inst_package_version: str = self.utils.split_package(inst_package)['version']

View file

@ -450,6 +450,7 @@ class Menu(Configs): # pylint: disable=[R0902]
command: str = Menu.upgrade.__name__ command: str = Menu.upgrade.__name__
removed: list = [] removed: list = []
added: list = [] added: list = []
ordered: bool = True
if len(self.args) == 1: if len(self.args) == 1:
@ -475,13 +476,14 @@ class Menu(Configs): # pylint: disable=[R0902]
remove = RemovePackages(removed, self.flags) remove = RemovePackages(removed, self.flags)
remove.remove(upgrade=True) remove.remove(upgrade=True)
# New packages added to the repository are pushed to the front of # If new packages are added to the repository, the sorted list will be disabled
# the list to be installed first. # and the new packages will be pushed to the front of the list to be installed first.
if added: if added:
packages = [pkg for pkg in packages if not pkg.endswith('_Added.')] packages = [pkg for pkg in packages if not pkg.endswith('_Added.')]
packages: list = added.extend(packages) packages: list = added + packages
ordered: bool = False
packages: list = self.choose.packages(self.data, packages, command) packages: list = self.choose.packages(self.data, packages, command, ordered)
if not packages: if not packages:
print('\nEverything is up-to-date!\n') print('\nEverything is up-to-date!\n')