diff --git a/slpkg/main.py b/slpkg/main.py index 19fdad61..7a8b51f8 100644 --- a/slpkg/main.py +++ b/slpkg/main.py @@ -447,17 +447,16 @@ class Menu(Configs): if len(self.args) == 1: - self.data: dict = self.utils.load_data(self.repository) - - upgrade = Upgrade(self.repository, self.data) - if self.utils.is_option((self.flag_check, self.flag_short_check), self.flags): + self.data: dict = self.utils.load_data(self.repository) + upgrade = Upgrade(self.repository, self.data) upgrade.check_packages() else: if self.repository == '*': self.repository = self.repos.default_repository - self.data: dict = self.utils.load_data(self.repository) + self.data: dict = self.utils.load_data(self.repository) + upgrade = Upgrade(self.repository, self.data) packages: list = list(upgrade.packages()) packages: list = self.choose.packages(self.data, packages, command) diff --git a/slpkg/upgrade.py b/slpkg/upgrade.py index 62ba07d2..3125c86a 100644 --- a/slpkg/upgrade.py +++ b/slpkg/upgrade.py @@ -41,17 +41,13 @@ class Upgrade(Configs): return False def check_packages(self) -> None: - title: str = f"{'packages':<19} {'Version':<15} {'Build':<6} {'Repository':<15} {'Build':<5} {'Repo':>14}" - print(len(title) * '=') - print(f'{self.bgreen}{title}{self.endc}') - print(len(title) * '=') - + found_packages: dict = {} if self.repository == '*': for repo in self.data.keys(): repo_tag: str = self.repos.repositories[repo]['repo_tag'] - installed_package: Generator = self.log_packages.glob(f'*{repo_tag}') + installed_packages: Generator = self.log_packages.glob(f'*{repo_tag}') - for installed in installed_package: + for installed in installed_packages: name: str = self.utils.split_package(installed.name)['name'] if self.data[repo].get(name): repo_package: str = self.data[repo].get(name).get('package')[:-4] @@ -63,15 +59,13 @@ class Upgrade(Configs): inst_version: str = self.utils.split_package(installed.name)['version'] inst_build: str = self.utils.split_package(installed.name)['build'] - if len(name) > 18: - name: str = f'{name[:15]}...' - if len(inst_version) > 15: - inst_version: str = f'{inst_version[:11]}...' - if len(repo_version) > 15: - repo_version: str = f'{repo_version[:11]}...' - - print(f"{name:<19} {inst_version:<15} {inst_build:<6} {repo_version:<15} " - f"{repo_build:<5} {repo:>14}") + found_packages[name]: dict = { + 'repo_version': repo_version, + 'repo_build': repo_build, + 'inst_version': inst_version, + 'inst_build': inst_build, + 'repo': repo + } else: repo_tag: str = self.repos.repositories[self.repository]['repo_tag'] @@ -89,20 +83,42 @@ class Upgrade(Configs): inst_version: str = self.utils.split_package(installed.name)['version'] inst_build: str = self.utils.split_package(installed.name)['build'] - if len(name) > 18: - name: str = f'{name[:15]}...' - if len(inst_version) > 15: - inst_version: str = f'{inst_version[:11]}...' - if len(repo_version) > 15: - repo_version: str = f'{repo_version[:11]}...' + found_packages[name]: dict = { + 'repo_version': repo_version, + 'repo_build': repo_build, + 'inst_version': inst_version, + 'inst_build': inst_build, + 'repo': self.repository + } - print(f"{name:<19} {inst_version:<15} {inst_build:<6} {repo_version:<15} " - f"{repo_build:<5} {self.repository:>14}") + if self.count_packages: + title: str = f"{'packages':<19} {'Version':<15} {'Build':<6} {'Repository':<15} {'Build':<5} {'Repo':>14}" + print(len(title) * '=') + print(f'{self.bgreen}{title}{self.endc}') + print(len(title) * '=') + for name, data in found_packages.items(): + repo_version: str = data['repo_version'] + repo_build: str = data['repo_build'] + inst_version: str = data['inst_version'] + inst_build: str = data['inst_build'] - count_repos: int = len(set(self.count_repos)) - repos_message: str = 'repository' - if count_repos > 1: - repos_message: str = 'repositories' - print(len(title) * '=') - print(f'{self.grey}Total packages for upgrade {self.count_packages} in {count_repos} ' - f'{repos_message}.{self.endc}\n') + if len(name) > 18: + name: str = f'{name[:15]}...' + if len(data['inst_version']) > 15: + inst_version: str = f"{data['inst_version'][:11]}..." + if len(data['repo_version']) > 15: + repo_version: str = f"{data['repo_version'][:11]}..." + + print(f"{name:<19} {inst_version:<15} {inst_build:<6} {repo_version:<15} " + f"{repo_build:<5} {data['repo']:>14}") + + count_repos: int = len(set(self.count_repos)) + repos_message: str = 'repository' + if count_repos > 1: + repos_message: str = 'repositories' + print(len(title) * '=') + print(f'{self.grey}Total packages for upgrade {self.count_packages} in {count_repos} ' + f'{repos_message}.{self.endc}\n') + else: + print('\nEverything is up-to-date!\n') + raise SystemExit(0)