mirror of
https://gitlab.com/dslackw/slpkg.git
synced 2024-12-27 09:58:10 +01:00
Updated methods
This commit is contained in:
parent
be51aaff12
commit
b3f7ead910
1 changed files with 64 additions and 68 deletions
|
@ -14,7 +14,7 @@ from slpkg.repositories import Repositories
|
|||
class RepoInfo(Configs): # pylint: disable=[R0902]
|
||||
|
||||
"""
|
||||
View repositories information.
|
||||
View information about repositories.
|
||||
"""
|
||||
|
||||
def __init__(self, flags: list, repository: str):
|
||||
|
@ -28,8 +28,7 @@ class RepoInfo(Configs): # pylint: disable=[R0902]
|
|||
self.columns, self.rows = shutil.get_terminal_size()
|
||||
self.name_alignment: int = self.columns - 61
|
||||
|
||||
if self.name_alignment < 1:
|
||||
self.name_alignment: int = 1
|
||||
self.name_alignment = max(self.name_alignment, 1)
|
||||
|
||||
self.enabled: int = 0
|
||||
self.total_packages: int = 0
|
||||
|
@ -39,8 +38,29 @@ class RepoInfo(Configs): # pylint: disable=[R0902]
|
|||
self.option_for_repository: bool = self.utils.is_option(
|
||||
('-o', '--repository'), flags)
|
||||
|
||||
def repo_information(self) -> dict:
|
||||
def info(self) -> None:
|
||||
""" Prints information about repositories.
|
||||
"""
|
||||
self.load_repo_data()
|
||||
|
||||
self.view_the_title()
|
||||
|
||||
if self.option_for_repository:
|
||||
self.view_the_repository_information()
|
||||
else:
|
||||
self.view_the_repositories_information()
|
||||
|
||||
def load_repo_data(self) -> None:
|
||||
""" Loads repository data.
|
||||
"""
|
||||
self.dates: dict = self.repo_information()
|
||||
if self.option_for_repository:
|
||||
self.repo_data: dict = self.load_data.load(self.repository)
|
||||
else:
|
||||
self.repo_data: dict = self.load_data.load('*')
|
||||
|
||||
def repo_information(self) -> dict:
|
||||
""" Loads repository information.
|
||||
|
||||
Returns:
|
||||
dict: Description
|
||||
|
@ -51,37 +71,6 @@ class RepoInfo(Configs): # pylint: disable=[R0902]
|
|||
return self.utils.read_json_file(repo_info_json)
|
||||
return {}
|
||||
|
||||
def info(self) -> None:
|
||||
""" Prints information about repositories.
|
||||
"""
|
||||
self.dates: dict = self.repo_information()
|
||||
if self.option_for_repository:
|
||||
self.repo_data: dict = self.load_data.load(self.repository)
|
||||
else:
|
||||
self.repo_data: dict = self.load_data.load('*')
|
||||
self.view_the_title()
|
||||
|
||||
if self.option_for_repository:
|
||||
self.view_the_repository_information()
|
||||
else:
|
||||
self.view_the_repositories_information()
|
||||
|
||||
def count_the_packages(self, repository: str) -> int:
|
||||
""" Counts the packages of repositories.
|
||||
|
||||
Args:
|
||||
repository (str): Repository name.
|
||||
|
||||
Returns:
|
||||
int: Numbers of packages.
|
||||
"""
|
||||
if self.option_for_repository:
|
||||
count: int = len(self.repo_data.keys())
|
||||
else:
|
||||
count: int = len(self.repo_data[repository].keys())
|
||||
self.total_packages += count
|
||||
return count
|
||||
|
||||
def view_the_title(self) -> None:
|
||||
""" Prints the title.
|
||||
"""
|
||||
|
@ -95,59 +84,66 @@ class RepoInfo(Configs): # pylint: disable=[R0902]
|
|||
|
||||
def view_the_repository_information(self) -> None:
|
||||
""" Prints the repository information.
|
||||
"""
|
||||
date: str = 'None'
|
||||
count: int = 0
|
||||
color: str = self.red
|
||||
status: str = 'Disabled'
|
||||
# """
|
||||
args: dict = {
|
||||
'repo': self.repository,
|
||||
'date': 'None',
|
||||
'count': 0,
|
||||
'color': self.red,
|
||||
'status': 'Disable'
|
||||
}
|
||||
|
||||
if self.dates.get(self.repository):
|
||||
date: str = self.dates[self.repository].get('last_updated', 'None')
|
||||
args['date']: str = self.dates[self.repository].get('last_updated', 'None')
|
||||
|
||||
if self.repos.repositories[self.repository]['enable']:
|
||||
status: str = 'Enabled'
|
||||
color: str = self.green
|
||||
count: int = self.count_the_packages(self.repository)
|
||||
self.enabled += 1
|
||||
args['status'] = 'Enabled'
|
||||
args['color'] = self.green
|
||||
args['count'] = len(self.repo_data)
|
||||
|
||||
self.view_the_line_information(self.repository, status, date, count, color)
|
||||
self.view_summary_of_repository()
|
||||
self.view_the_line_information(args)
|
||||
self.view_summary_of_all_repositories()
|
||||
|
||||
def view_the_repositories_information(self) -> None:
|
||||
""" Prints the repositories information.
|
||||
"""
|
||||
for repo, item in self.repos.repositories.items():
|
||||
date: str = 'None'
|
||||
count: int = 0
|
||||
color: str = self.red
|
||||
status: str = 'Disabled'
|
||||
args: dict = {}
|
||||
for repo, conf in self.repos.repositories.items():
|
||||
args: dict = {
|
||||
'repo': repo,
|
||||
'date': 'None',
|
||||
'count': 0,
|
||||
'color': self.red,
|
||||
'status': 'Disable'
|
||||
}
|
||||
|
||||
if self.dates.get(repo):
|
||||
date: str = self.dates[repo].get('last_updated', 'None')
|
||||
args['date']: str = self.dates[repo].get('last_updated', 'None')
|
||||
|
||||
if item['enable']:
|
||||
if conf['enable']:
|
||||
self.enabled += 1
|
||||
status: str = 'Enabled'
|
||||
color: str = self.green
|
||||
count: int = self.count_the_packages(repo)
|
||||
args['status'] = 'Enabled'
|
||||
args['color'] = self.green
|
||||
args['count'] = len(self.repo_data[repo])
|
||||
|
||||
self.view_the_line_information(repo, status, date, count, color)
|
||||
self.view_the_line_information(args)
|
||||
self.view_summary_of_all_repositories()
|
||||
|
||||
def view_the_line_information(self, repository: str, status: str, date: str, count: int, color: str) -> None: # pylint: disable=[R0913]
|
||||
""" Prints the row of information.
|
||||
def view_the_line_information(self, args: dict) -> None:
|
||||
"""Prints the row of information.
|
||||
|
||||
Args:
|
||||
repository (str): Repository name.
|
||||
status (str): Enable or disable.
|
||||
date (str): The date of the repository updated.
|
||||
count (int): Number of packages.
|
||||
color (str): Color of the repository name.
|
||||
args (dict): Arguments for print.
|
||||
"""
|
||||
repository: str = args['repo']
|
||||
repo_color: str = self.cyan
|
||||
if repository == self.repos.default_repository:
|
||||
if args['repo'] == self.repos.default_repository:
|
||||
repo_color: str = self.byellow
|
||||
repository: str = f'{repository} (default)'
|
||||
repository: str = f"{args['repo']} (default)"
|
||||
|
||||
print(f"{repo_color}{repository:<{self.name_alignment}}{self.endc}{color}{status:<14}{self.endc}{date:<34}"
|
||||
f"{self.yellow}{count:>12}{self.endc}")
|
||||
print(f"{repo_color}{repository:<{self.name_alignment}}{self.endc}{args['color']}{args['status']:<14}"
|
||||
f"{self.endc}{args['date']:<34}{self.yellow}{args['count']:>12}{self.endc}")
|
||||
|
||||
def view_summary_of_repository(self) -> None:
|
||||
""" Prints the repository summary.
|
||||
|
|
Loading…
Reference in a new issue