From f9a1711117bf94a6a1f77a81093b47031ebabe57 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Fri, 26 May 2023 19:55:10 +0300 Subject: [PATCH] Updated for choose packages --- slpkg/choose_packages.py | 88 ++++++++++++++++++++++++++++++++++++++++ slpkg/main.py | 84 +------------------------------------- 2 files changed, 90 insertions(+), 82 deletions(-) create mode 100644 slpkg/choose_packages.py diff --git a/slpkg/choose_packages.py b/slpkg/choose_packages.py new file mode 100644 index 00000000..f2c1b0e4 --- /dev/null +++ b/slpkg/choose_packages.py @@ -0,0 +1,88 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- + +import os + +from slpkg.configs import Configs +from slpkg.utilities import Utilities +from slpkg.dialog_box import DialogBox + + +class Choose(Configs): + """ Choose packages with dialog utility and -S, --search flag. """ + + def __init__(self, repository: str): + super(Configs, self).__init__() + self.repository: str = repository + + self.utils = Utilities() + self.dialogbox = DialogBox() + + self.is_binary: bool = self.utils.is_binary_repo(repository) + + def packages(self, data: dict, packages: list, method: str) -> list: + if self.dialog: + height: int = 10 + width: int = 70 + list_height: int = 0 + choices: list = [] + title: str = f' Choose packages you want to {method} ' + + repo_packages: list = list(data.keys()) + + if method in ['remove', 'find']: + installed: list = list(self.utils.installed_packages.values()) + + for package in installed: + package_name: str = self.utils.split_package(package)['name'] + package_version: str = self.utils.split_package(package)['version'] + + for pkg in packages: + if pkg in package or pkg == '*': + choices.extend([(package_name, package_version, False, f'Package: {package}')]) + + elif method == 'upgrade': + for pkg in packages: + for package in repo_packages: + + if pkg == package: + inst_pkg: str = self.utils.is_package_installed(package) + inst_package_version: str = self.utils.split_package(inst_pkg)['version'] + inst_package_build: str = self.utils.split_package(inst_pkg)['build'] + repo_ver: str = data[package]['version'] + + if self.is_binary: + bin_pkg: str = data[package]['package'] + repo_build_tag: str = self.utils.split_package(bin_pkg[:-4])['build'] + else: + repo_location: str = data[package]['location'] + repo_build_tag: str = self.utils.read_slackbuild_build_tag( + package, repo_location, self.repository + ) + + choices.extend( + [(package, f'{inst_package_version} -> {repo_ver}', True, + f'Installed: {package}-{inst_package_version} Build: {inst_package_build} -> ' + f'Available: {repo_ver} Build: {repo_build_tag}')] + ) + else: + for pkg in packages: + for package in repo_packages: + + if pkg in package or pkg == '*': + version: str = data[package]['version'] + choices.extend([(package, version, False, f'Package: {package}-{version} ' + f'> {self.repository}')]) + + if not choices: + return packages + + text: str = f'There are {len(choices)} packages:' + code, packages = self.dialogbox.checklist(text, title, height, width, list_height, choices) + if code == 'cancel' or not packages: + os.system('clear') + raise SystemExit() + + os.system('clear') + + return packages diff --git a/slpkg/main.py b/slpkg/main.py index 06e1703b..29e67225 100644 --- a/slpkg/main.py +++ b/slpkg/main.py @@ -1,7 +1,6 @@ #!/usr/bin/python3 # -*- coding: utf-8 -*- -import os import sys import logging from pathlib import Path @@ -16,8 +15,8 @@ from slpkg.utilities import Utilities from slpkg.cleanings import Cleanings from slpkg.search import SearchPackage from slpkg.views.cli_menu import Usage -from slpkg.dialog_box import DialogBox from slpkg.views.version import Version +from slpkg.choose_packages import Choose from slpkg.views.asciibox import AsciiBox from slpkg.sbos.queries import SBoQueries from slpkg.views.help_commands import Help @@ -303,7 +302,7 @@ class Menu(Configs): self.is_binary: bool = self.utils.is_binary_repo(self.repository) self.check = Check(self.repository) - self.choose = ChoosePackages(self.repository) + self.choose = Choose(self.repository) logging.basicConfig(filename=LoggingConfig.log_file, filemode=LoggingConfig.filemode, @@ -758,85 +757,6 @@ class SubMenu: self.usage.help_short(1) -class ChoosePackages(Configs): - """ Choose packages with dialog utility and -S, --search flag. """ - - def __init__(self, repository: str): - self.repository: str = repository - - self.utils = Utilities() - self.dialogbox = DialogBox() - - self.is_binary: bool = self.utils.is_binary_repo(repository) - - def packages(self, data: dict, packages: list, method: str) -> list: - if self.dialog: - height: int = 10 - width: int = 70 - list_height: int = 0 - choices: list = [] - title: str = f' Choose packages you want to {method} ' - - repo_packages: list = list(data.keys()) - - if method in ['remove', 'find']: - installed: list = list(self.utils.installed_packages.values()) - - for package in installed: - package_name: str = self.utils.split_package(package)['name'] - package_version: str = self.utils.split_package(package)['version'] - - for pkg in packages: - if pkg in package or pkg == '*': - choices.extend([(package_name, package_version, False, f'Package: {package}')]) - - elif method == 'upgrade': - for pkg in packages: - for package in repo_packages: - - if pkg == package: - inst_pkg: str = self.utils.is_package_installed(package) - inst_package_version: str = self.utils.split_package(inst_pkg)['version'] - inst_package_build: str = self.utils.split_package(inst_pkg)['build'] - repo_ver: str = data[package]['version'] - - if self.is_binary: - bin_pkg: str = data[package]['package'] - repo_build_tag: str = self.utils.split_package(bin_pkg[:-4])['build'] - else: - repo_location: str = data[package]['location'] - repo_build_tag: str = self.utils.read_slackbuild_build_tag( - package, repo_location, self.repository - ) - - choices.extend( - [(package, f'{inst_package_version} -> {repo_ver}', True, - f'Installed: {package}-{inst_package_version} Build: {inst_package_build} -> ' - f'Available: {repo_ver} Build: {repo_build_tag}')] - ) - else: - for pkg in packages: - for package in repo_packages: - - if pkg in package or pkg == '*': - version: str = data[package]['version'] - choices.extend([(package, version, False, f'Package: {package}-{version} ' - f'> {self.repository}')]) - - if not choices: - return packages - - text: str = f'There are {len(choices)} packages:' - code, packages = self.dialogbox.checklist(text, title, height, width, list_height, choices) - if code == 'cancel' or not packages: - os.system('clear') - raise SystemExit() - - os.system('clear') - - return packages - - def main() -> None: args: list = sys.argv args.pop(0)