diff --git a/slpkg/binaries/install.py b/slpkg/binaries/install.py index f94611d9..6d3be84a 100644 --- a/slpkg/binaries/install.py +++ b/slpkg/binaries/install.py @@ -62,7 +62,7 @@ class Packages(Configs): def execute(self) -> None: self.dependencies() - self.view_message.install_packages(self.packages, self.mode, self.packages_requires) + self.view_message.install_packages(self.packages, self.packages_requires, self.mode) self.view_message.question() start: float = time.time() @@ -100,7 +100,9 @@ class Packages(Configs): for pkg in self.install_order: - if not self.skip_installed_package(pkg): + skip_package: str = self.skip_installed_package(pkg) + + if not skip_package: mirror: str = BinQueries(pkg, self.repo).mirror() location: str = BinQueries(pkg, self.repo).location() @@ -111,7 +113,7 @@ class Packages(Configs): self.utils.remove_file_if_exists(self.tmp_slpkg, package) else: - version: str = BinQueries(pkg).version() + version: str = self.utils.split_binary_pkg(skip_package)[1] self.view_message.view_skipping_packages(pkg, version) if pkg_urls: @@ -119,6 +121,14 @@ class Packages(Configs): down.download() print() + def skip_installed_package(self, package) -> str: + """ Skip installed package when the option --skip-installed is applied. """ + installed_package: str = self.utils.is_package_installed(package) + + if (installed_package and self.mode == 'upgrade' and not self.upgrade.is_package_upgradeable(package) + or self.mode == 'install' and not self.utils.is_option(self.flag_reinstall, self.flags)): + return installed_package + def checksum(self) -> None: """ Packages checksums. """ md5 = Md5sum(self.flags) @@ -129,7 +139,7 @@ class Packages(Configs): def install_packages(self) -> None: """ Install the packages. """ slack_command: str = self.installpkg - if self.utils.is_option(self.flag_reinstall, self.flags): + if self.utils.is_option(self.flag_reinstall, self.flags) or self.mode == 'upgrade': slack_command: str = self.reinstall message: str = f'{self.cyan}Installing{self.endc}' @@ -155,7 +165,7 @@ class Packages(Configs): if exist: self.session.query( LogsDependencies).filter( - LogsDependencies.name == name).repos_for_update( + LogsDependencies.name == name).update( {LogsDependencies.requires: ' '.join(requires)}) elif requires: @@ -163,11 +173,6 @@ class Packages(Configs): self.session.add(deps) self.session.commit() - def skip_installed_package(self, package) -> bool: - """ Skip installed package when the option --skip-installed is applied. """ - return (self.utils.is_package_installed(package) and not self.utils.is_option(self.flag_reinstall, self.flags) - or self.utils.is_option(self.flag_skip_installed, self.flags)) - def multi_process(self, command: str, filename: str, message: str) -> None: """ Starting multiprocessing install/upgrade process. """ if self.silent_mode and not self.utils.is_option(self.flag_no_silent, self.flags): diff --git a/slpkg/main.py b/slpkg/main.py index b90bc00c..4bcd857e 100644 --- a/slpkg/main.py +++ b/slpkg/main.py @@ -421,7 +421,6 @@ class Argparse(Configs): if pkg == package: - repo_ver: str = SBoQueries(package).version() inst_pkg: str = self.utils.is_package_installed(package) split_inst_pkg: list = self.utils.split_binary_pkg(inst_pkg) @@ -429,40 +428,20 @@ class Argparse(Configs): repo_ver: str = BinQueries(package, self.binary_repo).version() bin_pkg: str = BinQueries(package, self.binary_repo).package_bin() repo_build_tag: str = self.utils.split_binary_pkg(bin_pkg[:-4])[3] - else: + repo_ver: str = SBoQueries(package).version() repo_build_tag: str = self.utils.read_sbo_build_tag(package) choices += [(package, f'{split_inst_pkg[1]} -> {repo_ver}', True, f'Installed: {package}-{split_inst_pkg[1]} Build: {split_inst_pkg[3]} -> ' f'Available: {repo_ver} Build: {repo_build_tag}')] - else: - if self.utils.is_option(self.flag_binaries, self.flags): - pkg_repo: tuple = BinQueries('', self.binary_repo).all_package_name_with_repo() - - for pkg in packages: - for pr in pkg_repo: - - if pkg in pr[0] or pkg == '*': - repo_ver: str = BinQueries(pr[0], pr[1]).version() - help_repo_ver: str = f'-{repo_ver}' - repo: str = f'> {pr[1]}' - - if self.binary_repo == '*': - repo_ver: str = '' - help_repo_ver: str = '' - repo: str = '' - - choices += [(pr[0], repo_ver, False, f'Package: {pr[0]}{help_repo_ver} {repo}')] - - else: - for pkg in packages: - for package in repo_packages: - if pkg in package: - repo_ver: str = SBoQueries(package).version() - choices += [(package, repo_ver, False, f'Package: {package}-{repo_ver} ' - f'> {self.repos.sbo_enabled_repository}')] + for pkg in packages: + for package in repo_packages: + if pkg in package: + repo_ver: str = SBoQueries(package).version() + choices += [(package, repo_ver, False, f'Package: {package}-{repo_ver} ' + f'> {self.repos.sbo_enabled_repository}')] if not choices: return packages diff --git a/slpkg/sbos/slackbuild.py b/slpkg/sbos/slackbuild.py index 7284a8bf..fda14f49 100644 --- a/slpkg/sbos/slackbuild.py +++ b/slpkg/sbos/slackbuild.py @@ -128,7 +128,7 @@ class Slackbuilds(Configs): def view_before_build(self) -> None: """ View slackbuilds before proceed. """ if not self.mode == 'build': - self.view_message.install_packages(self.slackbuilds, self.mode, self.dependencies) + self.view_message.install_packages(self.slackbuilds, self.dependencies, self.mode) else: self.view_message.build_packages(self.slackbuilds, self.dependencies) @@ -242,7 +242,7 @@ class Slackbuilds(Configs): if exist: self.session.query( LogsDependencies).filter( - LogsDependencies.name == name).repos_for_update( + LogsDependencies.name == name).update( {LogsDependencies.requires: ' '.join(requires)}) elif requires: diff --git a/slpkg/upgrade.py b/slpkg/upgrade.py index 8fa98629..f5ff3a93 100644 --- a/slpkg/upgrade.py +++ b/slpkg/upgrade.py @@ -8,6 +8,7 @@ from slpkg.configs import Configs from slpkg.utilities import Utilities from slpkg.sbos.queries import SBoQueries from slpkg.sbos.dependencies import Requires +from slpkg.binaries.required import Required from slpkg.binaries.queries import BinQueries @@ -21,58 +22,35 @@ class Upgrade(Configs): self.utils = Utilities() self.flag_bin_repository: list = ['-B=', '--bin-repo='] + self.all_installed: list = self.utils.installed_packages def packages(self) -> Generator[str, None, None]: """ Compares version of packages and returns the maximum. """ - upgrade, requires = [], [] - - repo_packages: list = SBoQueries('').sbos() if self.utils.is_option(self.flag_bin_repository, self.flags): repo_packages: list = BinQueries('', self.repo).all_package_names() + else: + repo_packages: list = SBoQueries('').sbos() - installed: list = self.utils.installed_packages + for pkg in self.all_installed: + inst_package: str = self.utils.split_binary_pkg(pkg)[0] - for pkg in installed: - inst_pkg_name: str = self.utils.split_binary_pkg(pkg)[0] + if inst_package in repo_packages: - if inst_pkg_name in repo_packages: - - if self.is_package_upgradeable(inst_pkg_name): - - if not self.utils.is_option(self.flag_bin_repository, self.flags): - requires += Requires(inst_pkg_name).resolve() - - upgrade.append(inst_pkg_name) - - # Clean the packages if they are dependencies - for pkg in upgrade: - if pkg not in requires: - yield pkg + if self.is_package_upgradeable(inst_package): + yield inst_package def is_package_upgradeable(self, package: str) -> bool: """ Checks for installed and upgradeable packages. """ - installed_version: str = '0' - installed = self.utils.is_package_installed(package) - inst_build_tag: str = self.utils.split_binary_pkg(installed)[3] + inst_package: str = self.utils.is_package_installed(package) + inst_version: str = self.utils.split_binary_pkg(inst_package)[1] + inst_build: str = self.utils.split_binary_pkg(inst_package)[3] if self.utils.is_option(self.flag_bin_repository, self.flags): - repository_version = BinQueries(package, self.repo).version() repo_package: str = BinQueries(package, self.repo).package_bin() - repo_build_tag: str = self.utils.split_binary_pkg(repo_package)[3] + return parse(repo_package[:-4]) > parse(inst_package) + else: - repository_version: str = SBoQueries(package).version() - repo_build_tag: str = self.utils.read_sbo_build_tag(package) + repo_version: str = SBoQueries(package).version() + repo_build: str = self.utils.read_sbo_build_tag(package) - if not repo_build_tag: - repo_build_tag: str = '' - - if not inst_build_tag: - inst_build_tag: str = '' - - if not repository_version: - repository_version: str = '0' - - if installed: - installed_version: str = self.utils.split_binary_pkg(installed)[1] - - return parse(repository_version + repo_build_tag) > parse(installed_version + inst_build_tag) + return parse(repo_version + repo_build) > parse(inst_version + inst_build) diff --git a/slpkg/views/views.py b/slpkg/views/views.py index 9c83851b..89fb09e6 100644 --- a/slpkg/views/views.py +++ b/slpkg/views/views.py @@ -92,7 +92,7 @@ class ViewMessage(Configs): self.summary(slackbuilds, dependencies, option='build') - def install_packages(self, packages: list, mode: str, dependencies=None) -> None: + def install_packages(self, packages: list, dependencies: list, mode: str) -> None: """ View packages for install. """ if dependencies is None: dependencies: list = []