mirror of
https://gitlab.com/dslackw/slpkg.git
synced 2025-01-29 20:34:22 +01:00
Updated for choose packages
This commit is contained in:
parent
66c3b3f649
commit
3779f1ce8b
1 changed files with 95 additions and 84 deletions
179
slpkg/main.py
179
slpkg/main.py
|
@ -42,7 +42,6 @@ class Menu(Configs):
|
|||
self.flags: list = []
|
||||
self.directory: Path = self.tmp_slpkg
|
||||
|
||||
self.dialogbox = DialogBox()
|
||||
self.utils = Utilities()
|
||||
self.usage = Usage()
|
||||
self.repos = Repositories()
|
||||
|
@ -305,6 +304,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)
|
||||
|
||||
logging.basicConfig(filename=LoggingConfig.log_file,
|
||||
filemode=LoggingConfig.filemode,
|
||||
|
@ -316,6 +316,13 @@ class Menu(Configs):
|
|||
f'{self.__class__.__init__.__name__}: '
|
||||
f'{args=}, {self.flags=}, {self.repository=}')
|
||||
|
||||
def load_database(self):
|
||||
if self.repository != '*':
|
||||
if self.is_binary:
|
||||
self.data: dict = BinQueries(self.repository).repository_data()
|
||||
else:
|
||||
self.data: dict = SBoQueries(self.repository).repository_data()
|
||||
|
||||
def check_for_repositories(self) -> None:
|
||||
""" Checks combination for binaries use repositories only and if repository exists. """
|
||||
except_options: list = [
|
||||
|
@ -331,13 +338,6 @@ class Menu(Configs):
|
|||
if not self.repos.repositories[self.repository]['enable']:
|
||||
self.usage.help_minimal(f"{self.prog_name}: repository '{self.repository}' is disabled")
|
||||
|
||||
def load_database(self):
|
||||
if self.repository != '*':
|
||||
if self.is_binary:
|
||||
self.data: dict = BinQueries(self.repository).repository_data()
|
||||
else:
|
||||
self.data: dict = SBoQueries(self.repository).repository_data()
|
||||
|
||||
def invalid_options(self) -> None:
|
||||
""" Checks for invalid options. """
|
||||
invalid, commands, repeat = [], [], []
|
||||
|
@ -452,72 +452,6 @@ class Menu(Configs):
|
|||
|
||||
return packages
|
||||
|
||||
def choose_packages(self, packages: list, method: str) -> list:
|
||||
""" Choose packages with dialog utility and -S, --search flag. """
|
||||
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(self.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 = self.data[package]['version']
|
||||
|
||||
if self.is_binary:
|
||||
bin_pkg: str = self.data[package]['package']
|
||||
repo_build_tag: str = self.utils.split_package(bin_pkg[:-4])['build']
|
||||
else:
|
||||
repo_location: str = self.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 = self.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, packages, title, height,
|
||||
width, list_height, choices)
|
||||
if code == 'cancel' or not packages:
|
||||
os.system('clear')
|
||||
raise SystemExit()
|
||||
|
||||
os.system('clear')
|
||||
|
||||
return packages
|
||||
|
||||
def update(self) -> None:
|
||||
if len(self.args) == 1:
|
||||
update = UpdateRepository(self.flags, self.repository)
|
||||
|
@ -535,7 +469,7 @@ class Menu(Configs):
|
|||
upgrade = Upgrade(self.repository, self.data)
|
||||
packages: list = list(upgrade.packages())
|
||||
|
||||
packages: list = self.choose_packages(packages, command)
|
||||
packages: list = self.choose.packages(self.data, packages, command)
|
||||
|
||||
if not packages:
|
||||
print('\nEverything is up-to-date!\n')
|
||||
|
@ -580,7 +514,7 @@ class Menu(Configs):
|
|||
packages: list = self.utils.case_insensitive_pattern_matching(packages, self.data)
|
||||
|
||||
if self.utils.is_option(self.flag_searches, self.flags):
|
||||
packages: list = self.choose_packages(packages, command)
|
||||
packages: list = self.choose.packages(self.data, packages, command)
|
||||
|
||||
self.check.package_exists_in_the_database(packages, self.data)
|
||||
self.check.is_package_unsupported(packages, self.data)
|
||||
|
@ -608,7 +542,7 @@ class Menu(Configs):
|
|||
packages: list = self.utils.case_insensitive_pattern_matching(packages, self.data)
|
||||
|
||||
if self.utils.is_option(self.flag_searches, self.flags):
|
||||
packages: list = self.choose_packages(packages, command)
|
||||
packages: list = self.choose.packages(self.data, packages, command)
|
||||
|
||||
self.check.package_exists_in_the_database(packages, self.data)
|
||||
|
||||
|
@ -634,7 +568,7 @@ class Menu(Configs):
|
|||
packages: list = self.utils.case_insensitive_pattern_matching(packages, self.data)
|
||||
|
||||
if self.utils.is_option(self.flag_searches, self.flags):
|
||||
packages: list = self.choose_packages(packages, command)
|
||||
packages: list = self.choose.packages(self.data, packages, command)
|
||||
|
||||
self.check.package_exists_in_the_database(packages, self.data)
|
||||
down_only = DownloadOnly(self.directory, self.flags, self.data, self.repository)
|
||||
|
@ -649,7 +583,7 @@ class Menu(Configs):
|
|||
packages: list = self.is_file_list_packages()
|
||||
|
||||
if self.utils.is_option(self.flag_searches, self.flags):
|
||||
packages: list = self.choose_packages(packages, command)
|
||||
packages: list = self.choose.packages(self.data, packages, command)
|
||||
|
||||
self.check.is_package_installed(packages)
|
||||
|
||||
|
@ -670,7 +604,7 @@ class Menu(Configs):
|
|||
packages: list = self.utils.case_insensitive_pattern_matching(packages, self.data)
|
||||
|
||||
if self.utils.is_option(self.flag_searches, self.flags):
|
||||
packages: list = self.choose_packages(packages, command)
|
||||
packages: list = self.choose.packages(self.data, packages, command)
|
||||
|
||||
find = FindInstalled(self.flags, packages)
|
||||
find.find()
|
||||
|
@ -689,7 +623,7 @@ class Menu(Configs):
|
|||
packages: list = self.utils.case_insensitive_pattern_matching(packages, self.data)
|
||||
|
||||
if self.utils.is_option(self.flag_searches, self.flags):
|
||||
packages: list = self.choose_packages(packages, command)
|
||||
packages: list = self.choose.packages(self.data, packages, command)
|
||||
|
||||
self.check.package_exists_in_the_database(packages, self.data)
|
||||
|
||||
|
@ -714,7 +648,7 @@ class Menu(Configs):
|
|||
packages: list = self.utils.case_insensitive_pattern_matching(packages, self.data)
|
||||
|
||||
if self.utils.is_option(self.flag_searches, self.flags):
|
||||
packages: list = self.choose_packages(packages, command)
|
||||
packages: list = self.choose.packages(self.data, packages, command)
|
||||
|
||||
pkgs = SearchPackage(self.flags, packages, self.repository)
|
||||
pkgs.search()
|
||||
|
@ -733,7 +667,7 @@ class Menu(Configs):
|
|||
packages: list = self.utils.case_insensitive_pattern_matching(packages, self.data)
|
||||
|
||||
if self.utils.is_option(self.flag_searches, self.flags):
|
||||
packages: list = self.choose_packages(packages, command)
|
||||
packages: list = self.choose.packages(self.data, packages, command)
|
||||
|
||||
self.check.package_exists_in_the_database(packages, self.data)
|
||||
|
||||
|
@ -754,7 +688,7 @@ class Menu(Configs):
|
|||
packages: list = self.utils.case_insensitive_pattern_matching(packages, self.data)
|
||||
|
||||
if self.utils.is_option(self.flag_searches, self.flags):
|
||||
packages: list = self.choose_packages(packages, command)
|
||||
packages: list = self.choose.packages(self.data, packages, command)
|
||||
|
||||
self.check.package_exists_in_the_database(packages, self.data)
|
||||
|
||||
|
@ -825,6 +759,83 @@ class SubMenu:
|
|||
self.usage.help_short(1)
|
||||
|
||||
|
||||
class ChoosePackages:
|
||||
|
||||
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:
|
||||
""" Choose packages with dialog utility and -S, --search flag. """
|
||||
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, packages, 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…
Add table
Reference in a new issue