diff --git a/slpkg/views/views.py b/slpkg/views/views.py index 3785f99c..89d10868 100644 --- a/slpkg/views/views.py +++ b/slpkg/views/views.py @@ -41,64 +41,20 @@ class ViewMessage(Configs): self.option_for_yes: bool = self.utils.is_option( ['-y', '--yes'], flags) - def view_packages(self, package: str, mode: str) -> None: - size: str = str() - color: str = self.endc - repository: str = self.repository - - if mode == 'remove': - installed = self.utils.is_package_installed(package) - pkg: list = self.utils.split_binary_pkg(installed) - version: str = pkg[1] - repo_tag: str = pkg[4] - size: str = self.utils.get_file_size(Path(self.log_packages, installed)) - repository = repo_tag.lower().replace('_', '') - - elif self.is_binary: - version: str = self.data[package][0] - # size: str = self.utils.convert_file_sizes(int(self.data[package][4])) <- It's going to replace with this - size: str = self.utils.convert_file_sizes( - int(''.join(re.findall(r'\d+', self.data[package][4])))) - else: - version: str = self.data[package][2] - - # Default highlight colors for all modes - if mode == 'remove': - color: str = self.red - if mode in ['install', 'download']: - color: str = self.cyan - if mode == 'build': - color: str = self.yellow - if mode == 'upgrade': - color: str = self.violet - package: str = self.build_package_and_version(package) - - if mode == 'install': - # Change the colors for install mode - if self.utils.is_package_installed(package): - color: str = self.grey - if self.upgrade.is_package_upgradeable(package): - color: str = self.violet - if self.utils.is_package_installed(package) and self.option_for_reinstall: - color: str = self.violet - package: str = self.build_package_and_version(package) - - self.ascii.draw_view_package(package, version, size, color, repository) - def build_packages(self, slackbuilds: list, dependencies: list) -> None: """ View packages for build only. """ mode = 'build' self.ascii.draw_package_title_box('The following packages will be build:', 'slpkg build packages') for sbo in slackbuilds: - self.view_packages(sbo, mode=mode) + self.view_build_package(sbo) if dependencies: self.ascii.draw_middle_line() self.ascii.draw_dependency_line() for sbo in dependencies: - self.view_packages(sbo, mode=mode) + self.view_build_package(sbo) self.summary(slackbuilds, dependencies, option=mode) @@ -111,14 +67,14 @@ class ViewMessage(Configs): self.ascii.draw_package_title_box('The following packages will be installed or upgraded:', title) for pkg in packages: - self.view_packages(pkg, mode) + self.view_install_upgrade_package(pkg, mode) if dependencies: self.ascii.draw_middle_line() self.ascii.draw_dependency_line() for pkg in dependencies: - self.view_packages(pkg, mode) + self.view_install_upgrade_package(pkg, mode) self.summary(packages, dependencies, option=mode) @@ -130,7 +86,7 @@ class ViewMessage(Configs): 'slpkg download packages') for sbo in slackbuilds: - self.view_packages(sbo, mode) + self.view_download_package(sbo) self.summary(slackbuilds, dependencies=[], option=mode) @@ -140,17 +96,83 @@ class ViewMessage(Configs): self.ascii.draw_package_title_box('The following packages will be removed:', 'slpkg remove packages') for pkg in packages: - self.view_packages(pkg, mode) + self.view_remove_package(pkg) if dependencies: self.ascii.draw_middle_line() self.ascii.draw_dependency_line() for pkg in dependencies: - self.view_packages(pkg, mode) + self.view_remove_package(pkg) self.summary(packages, dependencies, option=mode) + def view_build_package(self, package): + size: str = str() + color: str = self.yellow + + if self.is_binary: + version: str = self.data[package][0] + # size: str = self.utils.convert_file_sizes(int(self.data[package][4])) <- It's going to replace with this + size: str = self.utils.convert_file_sizes( + int(''.join(re.findall(r'\d+', self.data[package][4])))) + else: + version: str = self.data[package][2] + + self.ascii.draw_view_package(package, version, size, color, self.repository) + + def view_install_upgrade_package(self, package, mode): + size: str = str() + color: str = self.cyan + installed: str = self.utils.is_package_installed(package) + upgradable: bool = self.upgrade.is_package_upgradeable(package) + + if self.is_binary: + version: str = self.data[package][0] + # size: str = self.utils.convert_file_sizes(int(self.data[package][4])) <- It's going to replace with this + size: str = self.utils.convert_file_sizes( + int(''.join(re.findall(r'\d+', self.data[package][4])))) + else: + version: str = self.data[package][2] + + if mode == 'upgrade': + color: str = self.violet + package: str = self.build_package_and_version(package) + + if installed: + color: str = self.grey + if upgradable: + color: str = self.violet + if installed and self.option_for_reinstall: + color: str = self.violet + package: str = self.build_package_and_version(package) + + self.ascii.draw_view_package(package, version, size, color, self.repository) + + def view_download_package(self, package): + size: str = str() + color: str = self.cyan + + if self.is_binary: + version: str = self.data[package][0] + # size: str = self.utils.convert_file_sizes(int(self.data[package][4])) <- It's going to replace with this + size: str = self.utils.convert_file_sizes( + int(''.join(re.findall(r'\d+', self.data[package][4])))) + else: + version: str = self.data[package][2] + + self.ascii.draw_view_package(package, version, size, color, self.repository) + + def view_remove_package(self, package): + installed = self.utils.is_package_installed(package) + pkg: list = self.utils.split_binary_pkg(installed) + version: str = pkg[1] + repo_tag: str = pkg[4] + size: str = self.utils.get_file_size(Path(self.log_packages, installed)) + repository = repo_tag.lower().replace('_', '') + + self.ascii.draw_view_package(package, version, size, self.red, repository) + def logs_packages(self, dependencies: list) -> None: """ View the logging packages. """ print('The following logs will be removed:\n')