Skip to content

Commit

Permalink
Print number of packages when reporting installation progress
Browse files Browse the repository at this point in the history
  • Loading branch information
pkratoch committed Jan 16, 2025
1 parent 66d3152 commit b51dc1a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 20 deletions.
26 changes: 21 additions & 5 deletions pyanaconda/modules/payloads/payload/dnf/transaction_progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
Expand All @@ -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,
Expand Down

0 comments on commit b51dc1a

Please sign in to comment.