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]
|
class RepoInfo(Configs): # pylint: disable=[R0902]
|
||||||
|
|
||||||
"""
|
"""
|
||||||
View repositories information.
|
View information about repositories.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, flags: list, repository: str):
|
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.columns, self.rows = shutil.get_terminal_size()
|
||||||
self.name_alignment: int = self.columns - 61
|
self.name_alignment: int = self.columns - 61
|
||||||
|
|
||||||
if self.name_alignment < 1:
|
self.name_alignment = max(self.name_alignment, 1)
|
||||||
self.name_alignment: int = 1
|
|
||||||
|
|
||||||
self.enabled: int = 0
|
self.enabled: int = 0
|
||||||
self.total_packages: 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(
|
self.option_for_repository: bool = self.utils.is_option(
|
||||||
('-o', '--repository'), flags)
|
('-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.
|
""" 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:
|
Returns:
|
||||||
dict: Description
|
dict: Description
|
||||||
|
@ -51,37 +71,6 @@ class RepoInfo(Configs): # pylint: disable=[R0902]
|
||||||
return self.utils.read_json_file(repo_info_json)
|
return self.utils.read_json_file(repo_info_json)
|
||||||
return {}
|
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:
|
def view_the_title(self) -> None:
|
||||||
""" Prints the title.
|
""" Prints the title.
|
||||||
"""
|
"""
|
||||||
|
@ -95,59 +84,66 @@ class RepoInfo(Configs): # pylint: disable=[R0902]
|
||||||
|
|
||||||
def view_the_repository_information(self) -> None:
|
def view_the_repository_information(self) -> None:
|
||||||
""" Prints the repository information.
|
""" Prints the repository information.
|
||||||
"""
|
# """
|
||||||
date: str = 'None'
|
args: dict = {
|
||||||
count: int = 0
|
'repo': self.repository,
|
||||||
color: str = self.red
|
'date': 'None',
|
||||||
status: str = 'Disabled'
|
'count': 0,
|
||||||
|
'color': self.red,
|
||||||
|
'status': 'Disable'
|
||||||
|
}
|
||||||
|
|
||||||
if self.dates.get(self.repository):
|
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']:
|
if self.repos.repositories[self.repository]['enable']:
|
||||||
status: str = 'Enabled'
|
self.enabled += 1
|
||||||
color: str = self.green
|
args['status'] = 'Enabled'
|
||||||
count: int = self.count_the_packages(self.repository)
|
args['color'] = self.green
|
||||||
|
args['count'] = len(self.repo_data)
|
||||||
|
|
||||||
self.view_the_line_information(self.repository, status, date, count, color)
|
self.view_the_line_information(args)
|
||||||
self.view_summary_of_repository()
|
self.view_summary_of_all_repositories()
|
||||||
|
|
||||||
def view_the_repositories_information(self) -> None:
|
def view_the_repositories_information(self) -> None:
|
||||||
""" Prints the repositories information.
|
""" Prints the repositories information.
|
||||||
"""
|
"""
|
||||||
for repo, item in self.repos.repositories.items():
|
args: dict = {}
|
||||||
date: str = 'None'
|
for repo, conf in self.repos.repositories.items():
|
||||||
count: int = 0
|
args: dict = {
|
||||||
color: str = self.red
|
'repo': repo,
|
||||||
status: str = 'Disabled'
|
'date': 'None',
|
||||||
|
'count': 0,
|
||||||
|
'color': self.red,
|
||||||
|
'status': 'Disable'
|
||||||
|
}
|
||||||
|
|
||||||
if self.dates.get(repo):
|
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
|
self.enabled += 1
|
||||||
status: str = 'Enabled'
|
args['status'] = 'Enabled'
|
||||||
color: str = self.green
|
args['color'] = self.green
|
||||||
count: int = self.count_the_packages(repo)
|
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()
|
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]
|
def view_the_line_information(self, args: dict) -> None:
|
||||||
""" Prints the row of information.
|
"""Prints the row of information.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
repository (str): Repository name.
|
args (dict): Arguments for print.
|
||||||
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.
|
|
||||||
"""
|
"""
|
||||||
|
repository: str = args['repo']
|
||||||
repo_color: str = self.cyan
|
repo_color: str = self.cyan
|
||||||
if repository == self.repos.default_repository:
|
if args['repo'] == self.repos.default_repository:
|
||||||
repo_color: str = self.byellow
|
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}"
|
print(f"{repo_color}{repository:<{self.name_alignment}}{self.endc}{args['color']}{args['status']:<14}"
|
||||||
f"{self.yellow}{count:>12}{self.endc}")
|
f"{self.endc}{args['date']:<34}{self.yellow}{args['count']:>12}{self.endc}")
|
||||||
|
|
||||||
def view_summary_of_repository(self) -> None:
|
def view_summary_of_repository(self) -> None:
|
||||||
""" Prints the repository summary.
|
""" Prints the repository summary.
|
||||||
|
|
Loading…
Reference in a new issue