From b51dc1a55aa2a16ec56f56ae45516bf6657e8bf4 Mon Sep 17 00:00:00 2001 From: Pavla Kratochvilova Date: Thu, 16 Jan 2025 13:21:53 +0100 Subject: [PATCH] Print number of packages when reporting installation progress --- .../payload/dnf/transaction_progress.py | 26 ++++++++++++--- .../test_module_payload_dnf5_manager.py | 32 ++++++++++--------- 2 files changed, 38 insertions(+), 20 deletions(-) diff --git a/pyanaconda/modules/payloads/payload/dnf/transaction_progress.py b/pyanaconda/modules/payloads/payload/dnf/transaction_progress.py index da60b6dcb8f..22bc8416a3f 100644 --- a/pyanaconda/modules/payloads/payload/dnf/transaction_progress.py +++ b/pyanaconda/modules/payloads/payload/dnf/transaction_progress.py @@ -66,10 +66,26 @@ def __init__(self, queue): """ super().__init__() self._queue = queue - - def install_start(self, item, total=0): - log.debug("Installing - %s", item.get_package().to_string()) - self._queue.put(('install', item.get_package().to_string())) + self.installed_amount = 0 + self.installed_total = 0 + + def before_begin(self, total): + self.installed_total = total + log.debug("Starting the installation. Total packages: %s", total) + + def install_start(self, item, total): + package = item.get_package() + log.debug("Installing - %s", package.to_string()) + self.installed_amount += 1 + self._queue.put(( + 'install', + "{name}.{arch} ({amount}/{total})".format( + name=package.get_name(), + arch=package.get_arch(), + amount=self.installed_amount, + total=self.installed_total + ) + )) def install_progress(self, item, amount, total): log.debug("Installing - %s (%s/%s)", item.get_package().to_string(), amount, total) @@ -97,7 +113,7 @@ def script_start(self, item, nevra, type): # pylint: disable=redefined-builtin ), libdnf5.rpm.TransactionCallbacks.script_type_to_string(type) ) - self._queue.put(('configure', nevra.get_name())) + self._queue.put(('configure', "%s.%s" % (nevra.get_name(), nevra.get_arch()))) def after_complete(self, success): log.debug("Done - %s", success) diff --git a/tests/unit_tests/pyanaconda_tests/modules/payloads/payload/test_module_payload_dnf5_manager.py b/tests/unit_tests/pyanaconda_tests/modules/payloads/payload/test_module_payload_dnf5_manager.py index f443c0e1b8b..44fe9d5bc2e 100644 --- a/tests/unit_tests/pyanaconda_tests/modules/payloads/payload/test_module_payload_dnf5_manager.py +++ b/tests/unit_tests/pyanaconda_tests/modules/payloads/payload/test_module_payload_dnf5_manager.py @@ -500,15 +500,15 @@ def test_install_packages(self, run_transaction): self.dnf_manager.install_packages(calls.append) assert calls == [ - 'Installing p1-1.2-3.x86_64', - 'Configuring p1-1.2-3.x86_64', - 'Installing p2-1.2-3.x86_64', - 'Configuring p2-1.2-3.x86_64', - 'Installing p3-1.2-3.x86_64', - 'Configuring p3-1.2-3.x86_64', - 'Configuring p1-1.2-3.x86_64', - 'Configuring p2-1.2-3.x86_64', - 'Configuring p3-1.2-3.x86_64' + 'Installing p1.x86_64 (1/3)', + 'Configuring p1.x86_64', + 'Installing p2.x86_64 (2/3)', + 'Configuring p2.x86_64', + 'Installing p3.x86_64 (3/3)', + 'Configuring p3.x86_64', + 'Configuring p1.x86_64', + 'Configuring p2.x86_64', + 'Configuring p3.x86_64' ] def _get_transaction_item(self, name, action=libdnf5.transaction.TransactionItemAction_INSTALL): @@ -523,7 +523,8 @@ def _get_transaction_item(self, name, action=libdnf5.transaction.TransactionItem package.get_action.return_value = action nevra = Mock(spec=libdnf5.rpm.Nevra) - nevra.get_name.return_value = name + "-1.2-3.x86_64" + nevra.get_name.return_value = name + nevra.get_arch.return_value = "x86_64" item = Mock(spec=libdnf5.base.TransactionPackage) item.get_package.return_value = package @@ -537,17 +538,18 @@ def _install_packages(self, base, transaction, progress): try: transaction_items = list(map(self._get_transaction_item, ["p1", "p2", "p3"])) ts_total = len(transaction_items) - for ts_done, item in enumerate(transaction_items): - progress.install_start(item, ts_total) - progress.install_progress(item, ts_done, ts_total) + progress.before_begin(ts_total) + for item in transaction_items: + progress.install_start(item, 0) + progress.install_progress(item, 0, 0) progress.script_start( item, item.nevra, libdnf5.rpm.TransactionCallbacks.ScriptType_PRE_INSTALL ) - progress.install_progress(item, ts_done + 1, ts_total) + progress.install_progress(item, 0, 0) - for ts_done, item in enumerate(transaction_items): + for item in transaction_items: progress.script_start( item, item.nevra,