2022-12-23 19:17:06 +01:00
|
|
|
#!/usr/bin/python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2024-04-22 16:29:32 +02:00
|
|
|
# mypy: disable-error-code="no-redef"
|
|
|
|
|
2022-12-23 19:17:06 +01:00
|
|
|
from slpkg.configs import Configs
|
2023-01-27 22:45:36 +01:00
|
|
|
from slpkg.utilities import Utilities
|
2023-05-13 15:41:36 +02:00
|
|
|
from slpkg.views.asciibox import AsciiBox
|
2023-11-28 21:06:22 +01:00
|
|
|
from slpkg.sbos.dependencies import Requires
|
|
|
|
from slpkg.binaries.required import Required
|
2024-03-14 20:45:09 +01:00
|
|
|
from slpkg.repositories import Repositories
|
2022-12-23 19:17:06 +01:00
|
|
|
|
|
|
|
|
2023-04-24 21:19:05 +02:00
|
|
|
class Tracking(Configs):
|
2022-12-23 19:17:06 +01:00
|
|
|
""" Tracking of the package dependencies. """
|
|
|
|
|
2023-05-08 21:43:32 +02:00
|
|
|
def __init__(self, data: dict, packages: list, flags: list, repository: str):
|
2023-01-17 00:04:20 +01:00
|
|
|
super(Configs, self).__init__()
|
2023-05-08 21:43:32 +02:00
|
|
|
self.data: dict = data
|
|
|
|
self.packages: list = packages
|
2023-03-01 12:03:53 +01:00
|
|
|
self.flags: list = flags
|
2024-03-14 20:45:09 +01:00
|
|
|
self.repository: str = repository
|
2023-03-01 17:03:35 +01:00
|
|
|
|
2023-05-13 15:41:36 +02:00
|
|
|
self.ascii = AsciiBox()
|
2023-03-28 19:50:59 +02:00
|
|
|
self.utils = Utilities()
|
2024-03-14 20:45:09 +01:00
|
|
|
self.repos = Repositories()
|
2023-03-01 17:03:35 +01:00
|
|
|
|
2023-03-01 12:03:53 +01:00
|
|
|
self.llc: str = self.ascii.lower_left_corner
|
|
|
|
self.hl: str = self.ascii.horizontal_line
|
2023-06-21 10:22:08 +02:00
|
|
|
self.package_version: str = ''
|
|
|
|
self.package_dependency_version: str = ''
|
2024-03-27 20:10:06 +01:00
|
|
|
self.package_requires: tuple = ()
|
2023-06-21 10:22:08 +02:00
|
|
|
self.package_line: str = ''
|
|
|
|
self.require_line: str = ''
|
2023-05-09 18:48:43 +02:00
|
|
|
self.count_requires: int = 0
|
2023-05-19 13:52:17 +02:00
|
|
|
self.require_length: int = 0
|
2022-12-23 19:17:06 +01:00
|
|
|
|
2023-04-10 17:08:33 +02:00
|
|
|
self.option_for_pkg_version: bool = self.utils.is_option(
|
2023-05-22 21:03:01 +02:00
|
|
|
('-p', '--pkg-version'), flags)
|
2023-04-08 22:30:44 +02:00
|
|
|
|
2023-05-08 21:43:32 +02:00
|
|
|
def package(self) -> None:
|
2023-05-09 17:16:29 +02:00
|
|
|
self.view_the_title()
|
2023-03-30 17:17:10 +02:00
|
|
|
|
2023-05-09 17:16:29 +02:00
|
|
|
for package in self.packages:
|
2023-05-09 18:48:43 +02:00
|
|
|
self.count_requires: int = 0
|
2023-05-09 17:16:29 +02:00
|
|
|
|
2023-05-09 18:45:53 +02:00
|
|
|
self.set_the_package_line(package)
|
2023-05-09 17:16:29 +02:00
|
|
|
self.set_package_requires(package)
|
2023-05-09 18:45:53 +02:00
|
|
|
self.view_the_main_package()
|
2023-05-09 17:16:29 +02:00
|
|
|
self.view_no_dependencies()
|
2023-01-17 20:03:01 +01:00
|
|
|
|
2023-05-09 18:52:41 +02:00
|
|
|
for require in self.package_requires:
|
2023-05-09 18:48:43 +02:00
|
|
|
self.count_requires += 1
|
2023-05-09 17:16:29 +02:00
|
|
|
|
2023-05-09 18:45:53 +02:00
|
|
|
self.set_the_package_require_line(require)
|
2023-11-28 19:54:42 +01:00
|
|
|
self.view_requires()
|
2023-05-08 21:43:32 +02:00
|
|
|
|
2023-05-09 18:48:43 +02:00
|
|
|
self.view_summary_of_tracking(package)
|
2023-05-08 21:43:32 +02:00
|
|
|
|
2023-05-09 18:48:43 +02:00
|
|
|
def view_the_title(self) -> None:
|
2024-04-22 16:29:32 +02:00
|
|
|
print("The list below shows the packages with dependencies:\n")
|
|
|
|
self.packages: list = self.utils.apply_package_pattern(self.data, self.packages)
|
2023-05-09 17:16:29 +02:00
|
|
|
|
2023-05-09 18:45:53 +02:00
|
|
|
def view_the_main_package(self) -> None:
|
|
|
|
print(self.package_line)
|
2023-05-09 17:16:29 +02:00
|
|
|
print(f"{'':>1}{self.llc}{self.hl}", end='')
|
2023-05-08 21:43:32 +02:00
|
|
|
|
2023-11-28 19:54:42 +01:00
|
|
|
def view_requires(self) -> None:
|
2023-05-09 18:52:41 +02:00
|
|
|
if self.count_requires == 1:
|
2023-05-09 18:45:53 +02:00
|
|
|
print(f"{'':>1}{self.require_line}")
|
2023-05-08 21:43:32 +02:00
|
|
|
else:
|
2023-05-09 18:45:53 +02:00
|
|
|
print(f"{'':>4}{self.require_line}")
|
2023-05-08 21:43:32 +02:00
|
|
|
|
2023-05-09 18:48:43 +02:00
|
|
|
def view_no_dependencies(self) -> None:
|
2023-05-09 17:16:29 +02:00
|
|
|
if not self.package_requires:
|
|
|
|
print(f"{'':>1}{self.cyan}No dependencies{self.endc}")
|
|
|
|
|
2023-05-09 18:45:53 +02:00
|
|
|
def set_the_package_line(self, package: str) -> None:
|
|
|
|
self.package_line: str = f'{self.yellow}{package}{self.endc}'
|
|
|
|
if self.option_for_pkg_version:
|
|
|
|
self.set_package_version(package)
|
|
|
|
self.package_line: str = f'{self.yellow}{package} {self.package_version}{self.endc}'
|
|
|
|
|
2023-05-09 18:48:43 +02:00
|
|
|
def set_the_package_require_line(self, require: str) -> None:
|
2023-05-09 18:45:53 +02:00
|
|
|
self.require_line: str = f'{self.cyan}{require}{self.endc}'
|
|
|
|
if self.option_for_pkg_version:
|
|
|
|
self.set_package_dependency_version(require)
|
2023-05-19 13:52:17 +02:00
|
|
|
self.require_line: str = (f'{self.cyan}{require:<{self.require_length}}{self.endc}'
|
2023-05-09 18:45:53 +02:00
|
|
|
f'{self.package_dependency_version}')
|
|
|
|
|
2023-05-09 18:48:43 +02:00
|
|
|
def set_package_dependency_version(self, require: str) -> None:
|
2023-05-08 21:43:32 +02:00
|
|
|
try:
|
2023-05-11 13:52:58 +02:00
|
|
|
self.package_dependency_version: str = f"{'':>1}(not included)"
|
|
|
|
if self.data.get(require):
|
|
|
|
self.package_dependency_version: str = f"{'':>1}{self.yellow}{self.data[require]['version']}{self.endc}"
|
2023-05-09 09:00:24 +02:00
|
|
|
except KeyError: # KeyError here because of the '%README%' as dependency
|
2023-06-21 10:22:08 +02:00
|
|
|
self.package_dependency_version: str = ''
|
2023-05-08 21:43:32 +02:00
|
|
|
|
2023-05-09 17:16:29 +02:00
|
|
|
def set_package_version(self, package: str) -> None:
|
2023-05-11 13:52:58 +02:00
|
|
|
self.package_version: str = self.data[package]['version']
|
2023-05-08 21:43:32 +02:00
|
|
|
|
2023-05-09 18:48:43 +02:00
|
|
|
def set_package_requires(self, package: str) -> None:
|
2024-03-14 20:45:09 +01:00
|
|
|
if self.repository not in [self.repos.sbo_repo_name, self.repos.ponce_repo_name]:
|
2024-03-18 23:07:12 +01:00
|
|
|
self.package_requires: tuple = Required(self.data, package, self.flags).resolve()
|
2023-11-28 21:06:22 +01:00
|
|
|
else:
|
2024-03-18 23:07:12 +01:00
|
|
|
self.package_requires: tuple = Requires(self.data, package, self.flags).resolve()
|
2023-05-19 16:24:02 +02:00
|
|
|
if self.package_requires:
|
|
|
|
self.require_length: int = max(len(name) for name in self.package_requires)
|
2023-05-09 17:16:29 +02:00
|
|
|
|
2023-05-09 18:48:43 +02:00
|
|
|
def view_summary_of_tracking(self, package: str) -> None:
|
|
|
|
print(f'\n{self.grey}{self.count_requires} dependencies for {package}{self.endc}\n')
|