Updated for view mode

This commit is contained in:
Dimitris Zlatanidis 2023-01-03 15:47:40 +02:00
parent 302054a295
commit f7d04ed896

View file

@ -32,6 +32,10 @@ class ViewMessage:
def __init__(self, flags: list):
self.flags = flags
self.session = Session
self.utils = Utilities()
self.black = Blacklist()
self.dialog = DialogBox()
self.configs = Configs
self.colors = self.configs.colour
self.color = self.colors()
@ -40,61 +44,81 @@ class ViewMessage:
self.bgreen = f'{self.bold}{self.green}'
self.yellow = self.color['yellow']
self.cyan = self.color['cyan']
self.bcyan = f'{self.bold}{self.cyan}'
self.red = self.color['red']
self.grey = self.color['grey']
self.endc = self.color['endc']
self.session = Session
self.utils = Utilities()
self.black = Blacklist()
self.dialog = DialogBox()
self.installed_packages = []
self.columns, self.rows = shutil.get_terminal_size()
def title_box(self, message):
""" Drawing box title message. """
def draw_title_box(self, message):
""" Drawing title message. """
print(f'{self.bgreen}' + '' * (self.columns - 2) + '')
print(f'{self.endc} {message}' + ' ' * (self.columns - len(message) - 3) + f'{self.bgreen}')
print('' + '' * (self.columns - 2) + f'{self.endc}')
print('' + '' * (self.columns - 2) + f'{self.endc}')
print(f'{self.bgreen}{self.endc} Package:' + ' ' * 26 + 'Version:' + ' ' * 30 + f'Size{self.bgreen}{self.endc}')
def draw_middle_line(self):
""" Drawing a middle line. """
print(f'{self.bgreen}' + '' * 78 + f'{self.endc}')
def draw_dependency_line(self):
""" Drawing the dependencies line. """
print(f'{self.bgreen}{self.endc} Dependencies:' + ' ' * 63 + f'{self.bgreen}{self.endc}')
def view_packages(self, package, version):
""" Printing the main packages. """
print(f'{self.bgreen}{self.bcyan}{package}{self.endc}' + ' ' * (34 - len(package)) + f'{version}' + ' ' * (42 - len(version)) + f'{self.bgreen}{self.endc}')
def draw_bottom_line(self):
"""" Drawing the bottom line. """
print(f'{self.bold}{self.green}' + f'' * (self.columns - 2) + f'{self.endc}')
def build_packages(self, slackbuilds: list, dependencies: list):
""" View packages for build only. """
self.title_box('The following packages will be build:')
self.draw_title_box('The following packages will be build:')
for sbo in slackbuilds:
version = SBoQueries(sbo).version()
self._view_build(sbo, version)
self.view_packages(sbo, version)
if dependencies:
print(f'\n{self.bgreen}──{self.endc} Dependencies', f'{self.bgreen}{self.endc}' * (self.columns - 16))
self.draw_middle_line()
self.draw_dependency_line()
for sbo in dependencies:
version = SBoQueries(sbo).version()
self._view_build(sbo, version)
self.view_packages(sbo, version)
self._view_total(slackbuilds, dependencies, option='build')
def install_packages(self, slackbuilds: list, dependencies: list):
""" View packages for install. """
self.title_box('The following packages will be installed or upgraded:')
self.draw_title_box('The following packages will be installed or upgraded:')
for sbo in slackbuilds:
version = SBoQueries(sbo).version()
self._view_install(sbo, version)
self.view_packages(sbo, version)
if dependencies:
print(f'\n{self.bgreen}──{self.endc} Dependencies', f'{self.bgreen}{self.endc}' * (self.columns - 16))
self.draw_middle_line()
self.draw_dependency_line()
for sbo in dependencies:
version = SBoQueries(sbo).version()
self._view_install(sbo, version)
self.view_packages(sbo, version)
self._view_total(slackbuilds, dependencies, option='install')
def download_packages(self, slackbuilds: list):
""" View downloaded packages. """
self.title_box('The following packages will be downloaded:')
self.draw_title_box('The following packages will be downloaded:')
for sbo in slackbuilds:
version = SBoQueries(sbo).version()
self._view_download(sbo, version)
self.view_packages(sbo, version)
self.draw_bottom_line()
def remove_packages(self, packages: list) -> Any:
""" View remove packages. """
@ -116,13 +140,14 @@ class ViewMessage:
if deps and '--resolve-off' not in self.flags:
dependencies = self.choose_dependencies_for_remove(dependencies)
self.title_box('The following packages will be removed:')
self.draw_title_box('The following packages will be removed:')
for pkg in slackbuilds:
self._view_removed(pkg)
if deps and '--resolve-off' not in self.flags:
print('\nDependencies:')
self.draw_middle_line()
self.draw_dependency_line()
for pkg in dependencies:
self._view_removed(pkg)
@ -131,6 +156,18 @@ class ViewMessage:
return self.installed_packages, dependencies
def _view_removed(self, name: str):
""" View and creates list with packages for remove. """
installed = os.listdir(self.configs.log_packages)
if self.utils.is_installed(name):
for package in installed:
pkg = self.utils.split_installed_pkg(package)[0]
if pkg == name:
self.installed_packages.append(package)
version = self.utils.split_installed_pkg(package)[1]
self.view_packages(pkg, version)
def choose_dependencies_for_remove(self, dependencies: list) -> list:
""" Choose packages for remove using the dialog box. """
height = 10
@ -153,55 +190,6 @@ class ViewMessage:
os.system('clear')
return tags
def _view_download(self, sbo: str, version: str):
""" View packages for download only. """
if self.utils.is_installed(sbo):
print(f'[{self.yellow} download {self.endc}] -> '
f'{sbo}-{version}')
else:
print(f'[{self.cyan} download {self.endc}] -> '
f'{sbo}-{version}')
def _view_build(self, sbo: str, version: str):
""" View packages for build. """
if self.utils.is_installed(sbo):
print(f'[{self.yellow} build {self.endc}] -> '
f'{sbo}-{version}')
else:
print(f'[{self.cyan} build {self.endc}] -> '
f'{sbo}-{version}')
def _view_install(self, sbo: str, version: str):
""" View the packages for install or upgrade. """
installed = self.utils.is_installed(sbo)
install, set_color = 'install', self.cyan
if '--reinstall' in self.flags:
install, set_color = 'reinstall', self.red
elif installed and '--reinstall' not in self.flags:
install, set_color = 'upgrade', self.yellow
if installed:
print(f'[{set_color} {install} {self.endc}] -> '
f'{sbo}-{version} {set_color}'
f'({self.utils.split_installed_pkg(installed)[1]})'
f'{self.endc}')
else:
print(f'[{set_color} {install} {self.endc}] -> '
f'{sbo}-{version}')
def _view_removed(self, name: str):
""" View and creates list with packages for remove. """
installed = os.listdir(self.configs.log_packages)
if self.utils.is_installed(name):
for package in installed:
pkg = self.utils.split_installed_pkg(package)[0]
if pkg == name:
self.installed_packages.append(package)
print(f'[{self.red} delete {self.endc}] -> {package}')
def _view_total(self, slackbuilds: list, dependencies: list, option: str):
""" View the status of the packages action. """
slackbuilds.extend(dependencies)
@ -213,8 +201,7 @@ class ViewMessage:
else:
installed += 1
# Bottom line
print(f'{self.bold}{self.green}{self.endc}' * self.columns)
self.draw_bottom_line()
if option == 'install':
print(f'{self.grey}Total {installed} packages will be '