Updated for dialog

This commit is contained in:
Dimitris Zlatanidis 2023-05-25 22:20:10 +03:00
parent 7d379b228f
commit 3879958d08
5 changed files with 77 additions and 85 deletions

View file

@ -164,7 +164,7 @@ class Packages(Configs):
self.slackware_command: str = self.reinstall self.slackware_command: str = self.reinstall
def choose_package_dependencies(self) -> None: def choose_package_dependencies(self) -> None:
if self.dependencies: if self.dependencies and self.dialog:
height: int = 10 height: int = 10
width: int = 70 width: int = 70
list_height: int = 0 list_height: int = 0
@ -186,7 +186,6 @@ class Packages(Configs):
choices.extend([(package, repo_ver, status, help_text)]) choices.extend([(package, repo_ver, status, help_text)])
text: str = f'There are {len(choices)} dependencies:' text: str = f'There are {len(choices)} dependencies:'
code, self.dependencies = self.dialogbox.checklist( code, self.dependencies = self.dialogbox.checklist(text, title, height, width, list_height, choices)
text, self.dependencies, title, height, width, list_height, choices)
os.system('clear') os.system('clear')

View file

@ -22,44 +22,34 @@ class DialogBox(Configs):
self.d = Dialog(dialog="dialog") self.d = Dialog(dialog="dialog")
self.d.set_background_title(f'{self.prog_name} {Version().version} - Software Package Manager') self.d.set_background_title(f'{self.prog_name} {Version().version} - Software Package Manager')
def checklist(self, text: str, packages: list, title: str, height: int, width: int, def checklist(self, text: str, title: str, height: int, width: int,
list_height: int, choices: list) -> Tuple[bool, list]: list_height: int, choices: list) -> Tuple[bool, list]:
""" Display a checklist box. """ """ Display a checklist box. """
if self.dialog: self.more_kwargs.update(
self.more_kwargs.update( {"item_help": True}
{"item_help": True} )
)
code, tags = self.d.checklist(text=text, choices=choices, title=title, height=height, width=width, code, tags = self.d.checklist(text=text, choices=choices, title=title, height=height, width=width,
list_height=list_height, help_status=True, **self.more_kwargs) list_height=list_height, help_status=True, **self.more_kwargs)
else:
code: bool = False
tags: list = packages
return code, tags return code, tags
def mixedform(self, text: str, title: str, elements: list, height: int, width: int) -> Tuple[bool, list]: def mixedform(self, text: str, title: str, elements: list, height: int, width: int) -> Tuple[bool, list]:
""" Display a mixedform box. """ """ Display a mixedform box. """
if self.dialog: self.more_kwargs.update(
self.more_kwargs.update( {"item_help": True,
{"item_help": True, "help_tags": True}
"help_tags": True} )
) code, tags = self.d.mixedform(text=text, title=title, elements=elements, # type: ignore
code, tags = self.d.mixedform(text=text, title=title, elements=elements, # type: ignore height=height, width=width, help_button=True,
height=height, width=width, help_button=True, help_status=True, **self.more_kwargs)
help_status=True, **self.more_kwargs)
else:
code: bool = False
tags: list = elements
return code, tags return code, tags
def msgbox(self, text: str, height: int, width: int) -> None: def msgbox(self, text: str, height: int, width: int) -> None:
""" Display a message box. """ """ Display a message box. """
if self.dialog: self.d.msgbox(text, height, width)
self.d.msgbox(text, height, width)
def textbox(self, text: Union[str, Path], height: int, width: int) -> None: def textbox(self, text: Union[str, Path], height: int, width: int) -> None:
""" Display a text box. """ """ Display a text box. """
if self.dialog: self.d.textbox(text, height, width)
self.d.textbox(text, height, width)

View file

@ -322,7 +322,7 @@ class Menu(Configs):
self.data: dict = BinQueries(self.repository).repository_data() self.data: dict = BinQueries(self.repository).repository_data()
else: else:
self.data: dict = SBoQueries(self.repository).repository_data() self.data: dict = SBoQueries(self.repository).repository_data()
print(f'{self.yellow}{self.ascii.done}{self.endc}\n') print(f'{self.yellow}{self.ascii.done}{self.endc}')
def check_for_repositories(self) -> None: def check_for_repositories(self) -> None:
""" Checks combination for binaries use repositories only and if repository exists. """ """ Checks combination for binaries use repositories only and if repository exists. """
@ -642,15 +642,14 @@ class Menu(Configs):
command: str = Menu.search.__name__ command: str = Menu.search.__name__
if len(self.args) >= 2: if len(self.args) >= 2:
self.load_database()
self.check.is_database_empty() self.check.is_database_empty()
packages: list = self.is_file_list_packages() packages: list = self.is_file_list_packages()
if self.utils.is_option(self.flag_no_cases, self.flags) or not self.case_sensitive: if self.utils.is_option(self.flag_no_cases, self.flags) or not self.case_sensitive:
self.load_database()
packages: list = self.utils.case_insensitive_pattern_matching(packages, self.data) packages: list = self.utils.case_insensitive_pattern_matching(packages, self.data)
if self.utils.is_option(self.flag_searches, self.flags): if self.utils.is_option(self.flag_searches, self.flags):
self.load_database()
packages: list = self.choose.packages(self.data, packages, command) packages: list = self.choose.packages(self.data, packages, command)
pkgs = SearchPackage(self.flags, packages, self.repository) pkgs = SearchPackage(self.flags, packages, self.repository)
@ -762,7 +761,7 @@ class SubMenu:
self.usage.help_short(1) self.usage.help_short(1)
class ChoosePackages: class ChoosePackages(Configs):
""" 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):
@ -774,67 +773,69 @@ class ChoosePackages:
self.is_binary: bool = self.utils.is_binary_repo(repository) self.is_binary: bool = self.utils.is_binary_repo(repository)
def packages(self, data: dict, packages: list, method: str) -> list: def packages(self, data: dict, packages: list, method: str) -> list:
height: int = 10 if self.dialog:
width: int = 70 height: int = 10
list_height: int = 0 width: int = 70
choices: list = [] list_height: int = 0
title: str = f' Choose packages you want to {method} ' choices: list = []
title: str = f' Choose packages you want to {method} '
repo_packages: list = list(data.keys()) repo_packages: list = list(data.keys())
if method in ['remove', 'find']: if method in ['remove', 'find']:
installed: list = list(self.utils.installed_packages.values()) installed: list = list(self.utils.installed_packages.values())
for package in installed: for package in installed:
package_name: str = self.utils.split_package(package)['name'] package_name: str = self.utils.split_package(package)['name']
package_version: str = self.utils.split_package(package)['version'] 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 pkg in packages:
if pkg in package or pkg == '*': for package in repo_packages:
choices.extend([(package_name, package_version, False, f'Package: {package}')])
elif method == 'upgrade': if pkg == package:
for pkg in packages: inst_pkg: str = self.utils.is_package_installed(package)
for package in repo_packages: 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 pkg == package: if self.is_binary:
inst_pkg: str = self.utils.is_package_installed(package) bin_pkg: str = data[package]['package']
inst_package_version: str = self.utils.split_package(inst_pkg)['version'] repo_build_tag: str = self.utils.split_package(bin_pkg[:-4])['build']
inst_package_build: str = self.utils.split_package(inst_pkg)['build'] else:
repo_ver: str = data[package]['version'] repo_location: str = data[package]['location']
repo_build_tag: str = self.utils.read_slackbuild_build_tag(
package, repo_location, self.repository
)
if self.is_binary: choices.extend(
bin_pkg: str = data[package]['package'] [(package, f'{inst_package_version} -> {repo_ver}', True,
repo_build_tag: str = self.utils.split_package(bin_pkg[:-4])['build'] f'Installed: {package}-{inst_package_version} Build: {inst_package_build} -> '
else: f'Available: {repo_ver} Build: {repo_build_tag}')]
repo_location: str = data[package]['location']
repo_build_tag: str = self.utils.read_slackbuild_build_tag(
package, repo_location, self.repository
) )
else:
for pkg in packages:
for package in repo_packages:
choices.extend([(package, f'{inst_package_version} -> {repo_ver}', True, if pkg in package or pkg == '*':
f'Installed: {package}-{inst_package_version} Build: {inst_package_build} -> ' version: str = data[package]['version']
f'Available: {repo_ver} Build: {repo_build_tag}')]) choices.extend([(package, version, False, f'Package: {package}-{version} '
else: f'> {self.repository}')])
for pkg in packages:
for package in repo_packages:
if pkg in package or pkg == '*': if not choices:
version: str = data[package]['version'] return packages
choices.extend([(package, version, False, f'Package: {package}-{version} '
f'> {self.repository}')])
if not choices: text: str = f'There are {len(choices)} packages:'
return packages code, packages = self.dialogbox.checklist(text, title, height, width, list_height, choices)
if code == 'cancel' or not packages:
os.system('clear')
raise SystemExit()
text: str = f'There are {len(choices)} packages:'
code, packages = self.dialogbox.checklist(text, packages, title, height,
width, list_height, choices)
if code == 'cancel' or not packages:
os.system('clear') os.system('clear')
raise SystemExit()
os.system('clear')
return packages return packages

View file

@ -148,7 +148,7 @@ class RemovePackages(Configs):
self.session.commit() self.session.commit()
def choose_dependencies_for_remove(self) -> None: def choose_dependencies_for_remove(self) -> None:
if self.dependencies: if self.dependencies and self.dialog:
height: int = 10 height: int = 10
width: int = 70 width: int = 70
list_height: int = 0 list_height: int = 0
@ -161,6 +161,5 @@ class RemovePackages(Configs):
choices.extend([(package, installed_version, True, f'Package: {installed_package}')]) choices.extend([(package, installed_version, True, f'Package: {installed_package}')])
text: str = f'There are {len(choices)} dependencies:' text: str = f'There are {len(choices)} dependencies:'
code, self.dependencies = self.dialogbox.checklist(text, self.dependencies, title, height, code, self.dependencies = self.dialogbox.checklist(text, title, height, width, list_height, choices)
width, list_height, choices)
os.system('clear') os.system('clear')

View file

@ -17,6 +17,7 @@ from slpkg.utilities import Utilities
from slpkg.dialog_box import DialogBox from slpkg.dialog_box import DialogBox
from slpkg.downloader import Downloader from slpkg.downloader import Downloader
from slpkg.error_messages import Errors from slpkg.error_messages import Errors
from slpkg.views.asciibox import AsciiBox
from slpkg.views.views import ViewMessage from slpkg.views.views import ViewMessage
from slpkg.logging_deps import LoggingDeps from slpkg.logging_deps import LoggingDeps
from slpkg.repositories import Repositories from slpkg.repositories import Repositories
@ -46,6 +47,7 @@ class Slackbuilds(Configs):
self.view_message = ViewMessage(flags, repository, data) self.view_message = ViewMessage(flags, repository, data)
self.check_md5 = Md5sum(flags) self.check_md5 = Md5sum(flags)
self.download = Downloader(flags) self.download = Downloader(flags)
self.ascii = AsciiBox()
self.sources: dict = {} self.sources: dict = {}
self.install_order: list = [] self.install_order: list = []
@ -99,11 +101,13 @@ class Slackbuilds(Configs):
def creating_dependencies_list(self) -> None: def creating_dependencies_list(self) -> None:
if not self.option_for_resolve_off: if not self.option_for_resolve_off:
print('\rResolving dependencies, please wait... ', end='')
for slackbuild in self.slackbuilds: for slackbuild in self.slackbuilds:
dependencies: tuple = Requires(self.data, slackbuild).resolve() dependencies: tuple = Requires(self.data, slackbuild).resolve()
for dependency in dependencies: for dependency in dependencies:
self.dependencies.append(dependency) self.dependencies.append(dependency)
print(f'{self.yellow}{self.ascii.done}{self.endc}')
def remove_duplicate_from_dependencies_list(self) -> None: def remove_duplicate_from_dependencies_list(self) -> None:
self.dependencies: list = list(OrderedDict.fromkeys(self.dependencies)) self.dependencies: list = list(OrderedDict.fromkeys(self.dependencies))
@ -254,7 +258,7 @@ class Slackbuilds(Configs):
os.environ['MAKEFLAGS'] = f'-j {cpu_count()}' os.environ['MAKEFLAGS'] = f'-j {cpu_count()}'
def choose_package_dependencies(self) -> None: def choose_package_dependencies(self) -> None:
if self.dependencies: if self.dependencies and self.dialog:
height: int = 10 height: int = 10
width: int = 70 width: int = 70
list_height: int = 0 list_height: int = 0
@ -279,7 +283,6 @@ class Slackbuilds(Configs):
) )
text: str = f'There are {len(choices)} dependencies:' text: str = f'There are {len(choices)} dependencies:'
code, self.dependencies = self.dialogbox.checklist( code, self.dependencies = self.dialogbox.checklist(text, title, height, width, list_height, choices)
text, self.dependencies, title, height, width, list_height, choices)
os.system('clear') os.system('clear')