diff --git a/slpkg/views/views.py b/slpkg/views/views.py index c8967415..2f1e564f 100644 --- a/slpkg/views/views.py +++ b/slpkg/views/views.py @@ -42,6 +42,7 @@ class View(Configs): # pylint: disable=[R0902] self.download_only = None self.summary_message: str = '' + self.mode = None self.option_for_reinstall: bool = self.utils.is_option( ('-r', '--reinstall'), flags) @@ -56,13 +57,13 @@ class View(Configs): # pylint: disable=[R0902] slackbuilds (list): Slackbuilds for build. dependencies (list): Dependencies for build. """ - mode: str = 'build' + self.mode: str = 'build' self.ascii.draw_package_title('The following packages will be build:', 'slpkg build packages') for slackbuild in slackbuilds: self.draw_build_package(slackbuild) - self.summary(slackbuild, mode) + self.summary(slackbuild) if dependencies: self.ascii.draw_middle_line() @@ -70,7 +71,7 @@ class View(Configs): # pylint: disable=[R0902] for dependency in dependencies: self.draw_build_package(dependency) - self.summary(dependency, mode) + self.summary(dependency) self.ascii.draw_bottom_line() self.set_summary_for_build(slackbuilds + dependencies) @@ -84,6 +85,7 @@ class View(Configs): # pylint: disable=[R0902] dependencies (list): Dependencies for install. mode (str): Type of mode. """ + self.mode: str = mode title: str = 'slpkg install packages' if mode == 'upgrade': title: str = 'slpkg upgrade packages' @@ -91,7 +93,7 @@ class View(Configs): # pylint: disable=[R0902] for package in packages: self.draw_install_upgrade_package(package) - self.summary(package, mode) + self.summary(package) if dependencies: self.ascii.draw_middle_line() @@ -99,17 +101,12 @@ class View(Configs): # pylint: disable=[R0902] for dependency in dependencies: self.draw_install_upgrade_package(dependency) - self.summary(dependency, mode) + self.summary(dependency) self.ascii.draw_bottom_line() self.set_summary_for_install_and_upgrade(self.sum_install, self.sum_upgrade, self.sum_size_comp, self.sum_size_uncomp) print(self.summary_message) - if mode == 'upgrade': - print(f'{self.grey}Note: Packages with custom versions may not be recognized.{self.endc}') - if self.upgrade_log_file.is_file(): - print(f'{self.red}{self.ascii.failed} Some packages failed, ' - f'check the /var/log/slpkg/upgrade.log file.{self.endc}') def download_packages(self, packages: list, directory: Path) -> None: """ View packages for download method. @@ -118,14 +115,14 @@ class View(Configs): # pylint: disable=[R0902] packages (list): Packages name for download. directory (Path): Path to download. """ - mode: str = 'download' + self.mode: str = 'download' self.download_only: Path = directory self.ascii.draw_package_title('The following packages will be downloaded:', 'slpkg download packages') for package in packages: self.draw_download_package(package) - self.summary(package, mode) + self.summary(package) self.ascii.draw_bottom_line() self.set_summary_for_download(packages, self.sum_size_comp) @@ -138,12 +135,12 @@ class View(Configs): # pylint: disable=[R0902] packages (list): List of packages. dependencies (list): List of dependencies. """ - mode: str = 'remove' + self.mode: str = 'remove' self.ascii.draw_package_title('The following packages will be removed:', 'slpkg remove packages') for package in packages: self.draw_remove_package(package) - self.summary(package, mode) + self.summary(package) if dependencies: self.ascii.draw_middle_line() @@ -151,7 +148,7 @@ class View(Configs): # pylint: disable=[R0902] for dependency in dependencies: self.draw_remove_package(dependency) - self.summary(dependency, mode) + self.summary(dependency) self.ascii.draw_bottom_line() self.set_summary_for_remove(self.sum_remove, self.sum_size_remove) @@ -229,7 +226,7 @@ class View(Configs): # pylint: disable=[R0902] self.ascii.draw_package_line(package, version, size, self.red, repository) - def summary(self, package: str, method: str) -> None: + def summary(self, package: str) -> None: """ Counts packages per method. Args: @@ -242,11 +239,11 @@ class View(Configs): # pylint: disable=[R0902] self.sum_size_comp += float(self.data[package]['size_comp']) * 1024 self.sum_size_uncomp += float(self.data[package]['size_uncomp']) * 1024 - if installed and method == 'remove': + if installed and self.mode == 'remove': self.sum_size_remove += self.utils.count_file_size(package) upgradeable: bool = False - if method != 'remove': + if self.mode != 'remove': upgradeable: bool = self.upgrade.is_package_upgradeable(installed) if not installed: @@ -255,7 +252,7 @@ class View(Configs): # pylint: disable=[R0902] self.sum_upgrade += 1 elif upgradeable: self.sum_upgrade += 1 - elif installed and method == 'remove': + elif installed and self.mode == 'remove': self.sum_remove += 1 def set_summary_for_build(self, packages: list) -> None: @@ -277,6 +274,8 @@ class View(Configs): # pylint: disable=[R0902] size_comp (int): Counts of compressed sizes. size_uncomp (int): Counts of uncompressed sizes. """ + custom_message: str = '' + upgrade_message: str = '' split_message: str = '\n' if self.columns > 80: split_message: str = '' @@ -284,7 +283,12 @@ class View(Configs): # pylint: disable=[R0902] f'will be upgraded, while a total ') total_sizes: str = (f'{self.utils.convert_file_sizes(size_comp)} will be downloaded and ' f'{self.utils.convert_file_sizes(size_uncomp)} will be installed.{self.endc}') - self.summary_message: str = f'{total_packages}{split_message}{total_sizes}' + if self.mode == 'upgrade': + custom_message: str = f'\n{self.grey}Note: Packages with custom versions may not be recognized.{self.endc}' + if self.upgrade_log_file.is_file(): + upgrade_message: str = (f'\n{self.red}{self.ascii.failed} Some versions failed, ' + f'check the /var/log/slpkg/upgrade.log file.{self.endc}') + self.summary_message: str = f'{total_packages}{split_message}{total_sizes}{custom_message}{upgrade_message}' def set_summary_for_remove(self, remove: int, size_rmv: int) -> None: """ Sets summary for removes.