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

View file

@ -22,44 +22,34 @@ class DialogBox(Configs):
self.d = Dialog(dialog="dialog")
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]:
""" Display a checklist box. """
if self.dialog:
self.more_kwargs.update(
{"item_help": True}
)
self.more_kwargs.update(
{"item_help": True}
)
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)
else:
code: bool = False
tags: list = packages
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)
return code, tags
def mixedform(self, text: str, title: str, elements: list, height: int, width: int) -> Tuple[bool, list]:
""" Display a mixedform box. """
if self.dialog:
self.more_kwargs.update(
{"item_help": True,
"help_tags": True}
)
code, tags = self.d.mixedform(text=text, title=title, elements=elements, # type: ignore
height=height, width=width, help_button=True,
help_status=True, **self.more_kwargs)
else:
code: bool = False
tags: list = elements
self.more_kwargs.update(
{"item_help": True,
"help_tags": True}
)
code, tags = self.d.mixedform(text=text, title=title, elements=elements, # type: ignore
height=height, width=width, help_button=True,
help_status=True, **self.more_kwargs)
return code, tags
def msgbox(self, text: str, height: int, width: int) -> None:
""" 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:
""" 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()
else:
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:
""" Checks combination for binaries use repositories only and if repository exists. """
@ -642,15 +642,14 @@ class Menu(Configs):
command: str = Menu.search.__name__
if len(self.args) >= 2:
self.load_database()
self.check.is_database_empty()
packages: list = self.is_file_list_packages()
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)
if self.utils.is_option(self.flag_searches, self.flags):
self.load_database()
packages: list = self.choose.packages(self.data, packages, command)
pkgs = SearchPackage(self.flags, packages, self.repository)
@ -762,7 +761,7 @@ class SubMenu:
self.usage.help_short(1)
class ChoosePackages:
class ChoosePackages(Configs):
""" Choose packages with dialog utility and -S, --search flag. """
def __init__(self, repository: str):
@ -774,67 +773,69 @@ class ChoosePackages:
self.is_binary: bool = self.utils.is_binary_repo(repository)
def packages(self, data: dict, packages: list, method: str) -> list:
height: int = 10
width: int = 70
list_height: int = 0
choices: list = []
title: str = f' Choose packages you want to {method} '
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())
repo_packages: list = list(data.keys())
if method in ['remove', 'find']:
installed: list = list(self.utils.installed_packages.values())
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 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:
if pkg in package or pkg == '*':
choices.extend([(package_name, package_version, False, f'Package: {package}')])
for package in repo_packages:
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 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
)
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:
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 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
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()
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')
raise SystemExit()
os.system('clear')
return packages

View file

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

View file

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