mirror of
https://gitlab.com/dslackw/slpkg.git
synced 2024-11-17 07:48:18 +01:00
Improved code quality
This commit is contained in:
parent
3b3492f838
commit
d7ad6932a5
1 changed files with 58 additions and 7 deletions
|
@ -10,11 +10,15 @@ from slpkg.utilities import Utilities
|
|||
from slpkg.repositories import Repositories
|
||||
|
||||
|
||||
class ViewPackage(Configs):
|
||||
""" View the repository packages. """
|
||||
class ViewPackage(Configs): # pylint: disable=[R0902]
|
||||
|
||||
"""
|
||||
View the packages information.
|
||||
"""
|
||||
|
||||
def __init__(self, flags: list, repository: str):
|
||||
super(Configs, self).__init__()
|
||||
|
||||
self.flags: list = flags
|
||||
self.repository: str = repository
|
||||
|
||||
|
@ -36,7 +40,12 @@ class ViewPackage(Configs):
|
|||
('-p', '--pkg-version'), flags)
|
||||
|
||||
def slackbuild(self, data: dict, slackbuilds: list) -> None:
|
||||
""" View slackbuild packages information. """
|
||||
"""View slackbuilds information.
|
||||
|
||||
Args:
|
||||
data (dict): Repository data.
|
||||
slackbuilds (list): List of slackbuilds.
|
||||
"""
|
||||
print()
|
||||
repo: dict = {
|
||||
self.repos.sbo_repo_name: self.repos.sbo_repo_tar_suffix,
|
||||
|
@ -48,7 +57,7 @@ class ViewPackage(Configs):
|
|||
for sbo in slackbuilds:
|
||||
for name, item in data.items():
|
||||
|
||||
if sbo == name or sbo == '*':
|
||||
if sbo in [name, '*']:
|
||||
path_file: Path = Path(self.repos.repositories[self.repository]['path'],
|
||||
item['location'], name, 'README')
|
||||
path_info: Path = Path(self.repos.repositories[self.repository]['path'],
|
||||
|
@ -64,15 +73,29 @@ class ViewPackage(Configs):
|
|||
self.view_slackbuild_package(name, item)
|
||||
|
||||
def read_the_readme_file(self, path_file: Path) -> None:
|
||||
""" Reads the README file.
|
||||
|
||||
Args:
|
||||
path_file (Path): Path to the file.
|
||||
"""
|
||||
self.readme: list = self.utils.read_text_file(path_file)
|
||||
|
||||
def read_the_info_file(self, path_info: Path) -> None:
|
||||
""" reads the .info file.
|
||||
|
||||
Args:
|
||||
path_info (Path): Path to the file.
|
||||
"""
|
||||
self.info_file: list = self.utils.read_text_file(path_info)
|
||||
|
||||
def assign_the_sbo_mirror(self) -> None:
|
||||
""" Assign the url for the PACKAGES.TXT file.
|
||||
"""
|
||||
self.mirror: str = self.repos.repositories[self.repository]['mirror_packages']
|
||||
|
||||
def assign_the_info_file_variables(self) -> None:
|
||||
""" Assign data from the .info file.
|
||||
"""
|
||||
for line in self.info_file:
|
||||
if line.startswith('HOMEPAGE'):
|
||||
self.homepage: str = line[10:-2].strip()
|
||||
|
@ -82,9 +105,20 @@ class ViewPackage(Configs):
|
|||
self.email: str = line[7:-2].strip()
|
||||
|
||||
def assign_dependencies(self, item: dict) -> None:
|
||||
self.dependencies: str = (', '.join([f'{self.cyan}{pkg}' for pkg in item['requires']]))
|
||||
"""Assign the package dependencies.
|
||||
|
||||
Args:
|
||||
item (dict): Data value.
|
||||
"""
|
||||
self.dependencies: str = ', '.join([f'{self.cyan}{pkg}' for pkg in item['requires']])
|
||||
|
||||
def assign_dependencies_with_version(self, item: dict, data: dict) -> None:
|
||||
""" Assign dependencies with version.
|
||||
|
||||
Args:
|
||||
item (dict): Data value.
|
||||
data (dict): Repository data.
|
||||
"""
|
||||
if self.option_for_pkg_version:
|
||||
self.dependencies: str = (', '.join(
|
||||
[f"{self.cyan}{pkg}{self.endc}-{self.yellow}{data[pkg]['version']}"
|
||||
|
@ -92,6 +126,12 @@ class ViewPackage(Configs):
|
|||
if pkg in self.repository_packages]))
|
||||
|
||||
def view_slackbuild_package(self, name: str, item: dict) -> None:
|
||||
""" Prints slackbuild information.
|
||||
|
||||
Args:
|
||||
name (str): Slackbuild name.
|
||||
item (dict): Data value.
|
||||
"""
|
||||
space_align: str = ''
|
||||
print(f"{'Repository':<15}: {self.green}{self.repository}{self.endc}\n"
|
||||
f"{'Name':<15}: {self.green}{name}{self.endc}\n"
|
||||
|
@ -114,18 +154,29 @@ class ViewPackage(Configs):
|
|||
f"{'README':<15}: {self.cyan}{f'{space_align:>17}'.join(self.readme)}{self.endc}")
|
||||
|
||||
def package(self, data: dict, packages: list) -> None:
|
||||
""" View binary packages information. """
|
||||
""" View binary packages information.
|
||||
|
||||
Args:
|
||||
data (dict): Repository data.
|
||||
packages (list): List of packages.
|
||||
"""
|
||||
print()
|
||||
self.repository_packages: tuple = tuple(data.keys())
|
||||
for package in packages:
|
||||
for name, item in data.items():
|
||||
if package == name or package == '*':
|
||||
if package in [name, '*']:
|
||||
|
||||
self.assign_dependencies(item)
|
||||
self.assign_dependencies_with_version(item, data)
|
||||
self.view_binary_package(name, item)
|
||||
|
||||
def view_binary_package(self, name: str, item: dict) -> None:
|
||||
""" Print binary packages information.
|
||||
|
||||
Args:
|
||||
name (str): Package name.
|
||||
item (dict): Data values.
|
||||
"""
|
||||
print(f"{'Repository':<15}: {self.green}{self.repository}{self.endc}\n"
|
||||
f"{'Name':<15}: {self.green}{name}{self.endc}\n"
|
||||
f"{'Version':<15}: {self.green}{item['version']}{self.endc}\n"
|
||||
|
|
Loading…
Reference in a new issue