mirror of
https://gitlab.com/dslackw/slpkg.git
synced 2024-12-26 09:58:31 +01:00
Updated for choose packages
This commit is contained in:
parent
e8e828e47c
commit
f9a1711117
2 changed files with 90 additions and 82 deletions
88
slpkg/choose_packages.py
Normal file
88
slpkg/choose_packages.py
Normal file
|
@ -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
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue