slpkg/slpkg/tracking.py

93 lines
3.2 KiB
Python
Raw Normal View History

2022-12-23 19:17:06 +01:00
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from slpkg.configs import Configs
2023-01-04 11:15:10 +01:00
from slpkg.views.ascii import Ascii
2023-01-27 22:45:36 +01:00
from slpkg.utilities import Utilities
2023-03-28 19:50:59 +02:00
from slpkg.sbos.queries import SBoQueries
from slpkg.binaries.queries import BinQueries
2022-12-23 19:17:06 +01:00
2023-03-28 19:50:59 +02:00
class Tracking(Configs):
2022-12-23 19:17:06 +01:00
""" Tracking of the package dependencies. """
2023-01-17 20:03:01 +01:00
def __init__(self, flags: list):
2023-04-08 18:57:26 +02:00
__slots__ = 'flags'
2023-01-17 00:04:20 +01:00
super(Configs, self).__init__()
2023-03-01 12:03:53 +01:00
self.flags: list = flags
2023-03-01 17:03:35 +01:00
2023-01-04 11:15:10 +01:00
self.ascii = Ascii()
2023-03-01 17:03:35 +01:00
self.color = self.colour()
2023-03-28 19:50:59 +02:00
self.utils = Utilities()
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
self.vl: str = self.ascii.vertical_line
self.cyan: str = self.color['cyan']
self.grey: str = self.color['grey']
self.yellow: str = self.color['yellow']
self.endc: str = self.color['endc']
2023-03-01 17:03:35 +01:00
self.flag_pkg_version: list = ['-p', '--pkg-version']
2022-12-23 19:17:06 +01:00
2023-04-08 22:28:22 +02:00
self.repo_for_binaries: bool = self.utils.is_option(['-B', '--bin-repo='], self.flags)
2023-03-28 19:50:59 +02:00
def packages(self, packages: list, repo: str) -> None:
2022-12-23 19:17:06 +01:00
""" Prints the packages dependencies. """
2023-04-01 11:59:05 +02:00
print(f"The list below shows the packages '{', '.join([p for p in packages])}' with dependencies:\n")
2023-04-08 11:31:44 +02:00
sbo_repo_dict: dict = {}
bin_repo_dict: dict = {}
2022-12-23 19:17:06 +01:00
2023-04-01 11:53:31 +02:00
packages: list = self.utils.apply_package_pattern(self.flags, packages, repo)
2023-04-08 11:31:44 +02:00
2023-04-08 22:28:22 +02:00
if self.repo_for_binaries:
2023-04-08 11:31:44 +02:00
bin_repo_dict: dict = BinQueries(repo).repository_data()
else:
2023-04-08 22:10:10 +02:00
sbo_repo_dict: dict = SBoQueries().repository_data()
2023-04-01 11:27:53 +02:00
2023-03-01 12:03:53 +01:00
char: str = f' {self.llc}{self.hl}'
sp: str = ' ' * 4
2023-03-30 17:17:10 +02:00
2023-01-17 00:06:04 +01:00
for package in packages:
2023-01-17 20:03:01 +01:00
pkg = f'{self.yellow}{package}{self.endc}'
2023-03-28 19:50:59 +02:00
if self.utils.is_option(self.flag_pkg_version, self.flags):
2023-04-08 22:28:22 +02:00
if self.repo_for_binaries:
2023-04-07 21:01:11 +02:00
version: str = bin_repo_dict[package][0]
2023-04-08 11:31:44 +02:00
else:
version: str = sbo_repo_dict[package][2]
2023-03-28 19:50:59 +02:00
2023-03-31 21:16:51 +02:00
pkg = f'{self.yellow}{package} {version}{self.endc}'
2023-03-28 19:50:59 +02:00
2023-04-08 22:28:22 +02:00
if self.repo_for_binaries:
2023-04-08 11:38:46 +02:00
requires: list = bin_repo_dict[package][6].split()
2023-03-28 19:50:59 +02:00
else:
2023-04-08 11:38:46 +02:00
requires: list = sbo_repo_dict[package][7].split()
2023-01-17 20:03:01 +01:00
2023-03-01 12:03:53 +01:00
how_many: int = len(requires)
2022-12-23 19:17:06 +01:00
2023-01-17 20:03:01 +01:00
print(pkg)
2023-01-17 19:32:44 +01:00
print(char, end='')
2023-01-17 20:03:01 +01:00
2023-03-30 17:17:10 +02:00
if not requires:
print(f' {self.cyan}No dependencies{self.endc}')
else:
for i, req in enumerate(requires, start=1):
require: str = f'{self.cyan}{req}{self.endc}'
if self.utils.is_option(self.flag_pkg_version, self.flags):
2023-03-28 19:50:59 +02:00
2023-04-08 22:28:22 +02:00
if self.repo_for_binaries:
2023-04-07 21:01:11 +02:00
version: str = f" {self.yellow}{bin_repo_dict[req][0]}{self.endc}"
2023-04-08 11:31:44 +02:00
else:
version: str = f" {self.yellow}{sbo_repo_dict[req][2]}{self.endc}"
2023-03-28 19:50:59 +02:00
2023-03-30 17:17:10 +02:00
require: str = f'{self.cyan}{req}{self.endc}{version}'
2023-01-17 20:03:01 +01:00
2023-03-30 17:17:10 +02:00
if i == 1:
print(f' {require}')
else:
print(f'{sp}{require}')
2023-01-17 20:03:01 +01:00
2023-01-04 11:15:10 +01:00
print(f'\n{self.grey}{how_many} dependencies for {package}{self.endc}\n')