richardphibel / rpms / dnf

Forked from rpms/dnf 2 years ago
Clone

Blame SOURCES/0003-Post-transaction-summary-is-logged-for-API-users-RhBug-1855158.patch

476404
From 9ed390d08a9f2b66f4e352532fa526fc64e329d4 Mon Sep 17 00:00:00 2001
476404
From: Marek Blaha <mblaha@redhat.com>
476404
Date: Tue, 28 Jul 2020 09:50:10 +0200
476404
Subject: [PATCH 1/3] Remove unused loops attribute from
476404
 DepSolveProgressCallBack
476404
476404
---
476404
 dnf/cli/output.py | 5 -----
476404
 1 file changed, 5 deletions(-)
476404
476404
diff --git a/dnf/cli/output.py b/dnf/cli/output.py
476404
index de188ffbd1..44d5f8b89f 100644
476404
--- a/dnf/cli/output.py
476404
+++ b/dnf/cli/output.py
476404
@@ -1987,10 +1987,6 @@ def historyInfoCmdPkgsAltered(self, old, pats=[]):
476404
 class DepSolveProgressCallBack(dnf.callback.Depsolve):
476404
     """Provides text output callback functions for Dependency Solver callback."""
476404
 
476404
-    def __init__(self):
476404
-        """requires yum-cli log and errorlog functions as arguments"""
476404
-        self.loops = 0
476404
-
476404
     def pkg_added(self, pkg, mode):
476404
         """Print information about a package being added to the
476404
         transaction set.
476404
@@ -2037,7 +2033,6 @@ def start(self):
476404
         process.
476404
         """
476404
         logger.debug(_('--> Starting dependency resolution'))
476404
-        self.loops += 1
476404
 
476404
     def end(self):
476404
         """Output a message stating that dependency resolution has finished."""
476404
476404
From 0ee646f4965c597f2832ed3df9d9f0e6546dcc54 Mon Sep 17 00:00:00 2001
476404
From: Marek Blaha <mblaha@redhat.com>
476404
Date: Wed, 21 Oct 2020 11:47:43 +0200
476404
Subject: [PATCH 2/3] Remove unused parameter of _make_lists()
476404
476404
---
476404
 dnf/cli/output.py | 7 ++++---
476404
 1 file changed, 4 insertions(+), 3 deletions(-)
476404
476404
diff --git a/dnf/cli/output.py b/dnf/cli/output.py
476404
index 44d5f8b89f..af8a968770 100644
476404
--- a/dnf/cli/output.py
476404
+++ b/dnf/cli/output.py
476404
@@ -52,7 +52,8 @@
476404
 
476404
 logger = logging.getLogger('dnf')
476404
 
476404
-def _make_lists(transaction, goal):
476404
+
476404
+def _make_lists(transaction):
476404
     b = dnf.util.Bunch({
476404
         'downgraded': [],
476404
         'erased': [],
476404
@@ -1101,7 +1102,7 @@ def list_transaction(self, transaction, total_width=None):
476404
             # in order to display module changes when RPM transaction is empty
476404
             transaction = []
476404
 
476404
-        list_bunch = _make_lists(transaction, self.base._goal)
476404
+        list_bunch = _make_lists(transaction)
476404
         pkglist_lines = []
476404
         data = {'n' : {}, 'v' : {}, 'r' : {}}
476404
         a_wid = 0 # Arch can't get "that big" ... so always use the max.
476404
@@ -1488,7 +1489,7 @@ def _tsi_or_pkg_nevra_cmp(item1, item2):
476404
             return (item1.arch > item2.arch) - (item1.arch < item2.arch)
476404
 
476404
         out = ''
476404
-        list_bunch = _make_lists(transaction, self.base._goal)
476404
+        list_bunch = _make_lists(transaction)
476404
 
476404
         skipped_conflicts, skipped_broken = self._skipped_packages(
476404
             report_problems=False, transaction=transaction)
476404
476404
From 865b7183453684de6a25e77fddf5a2d11fbffba8 Mon Sep 17 00:00:00 2001
476404
From: Marek Blaha <mblaha@redhat.com>
476404
Date: Wed, 21 Oct 2020 17:59:46 +0200
476404
Subject: [PATCH 3/3] Post transaction summary is logged for API users
476404
 (RhBug:1855158)
476404
476404
Post transaction summary is always logged into /var/log/dnf.log.
476404
When transaction is called from cli, the summary is also printed to
476404
stdout in columns (as previously).
476404
476404
= changelog =
476404
msg:           Packages installed/removed via DNF API are logged into dnf.log
476404
type:          enhancement
476404
resolves:      https://bugzilla.redhat.com/show_bug.cgi?id=1855158
476404
---
476404
 dnf/base.py       |  46 ++++++++++++-
476404
 dnf/cli/cli.py    |   8 ++-
476404
 dnf/cli/output.py | 167 ++++++++--------------------------------------
476404
 dnf/util.py       | 102 +++++++++++++++++++++++++++-
476404
 4 files changed, 177 insertions(+), 146 deletions(-)
476404
476404
diff --git a/dnf/base.py b/dnf/base.py
476404
index 075e74265a..c0d7712605 100644
476404
--- a/dnf/base.py
476404
+++ b/dnf/base.py
476404
@@ -28,12 +28,12 @@
476404
 import dnf
476404
 import libdnf.transaction
476404
 
476404
+from copy import deepcopy
476404
 from dnf.comps import CompsQuery
476404
 from dnf.i18n import _, P_, ucd
476404
 from dnf.util import _parse_specs
476404
 from dnf.db.history import SwdbInterface
476404
 from dnf.yum import misc
476404
-from functools import reduce
476404
 try:
476404
     from collections.abc import Sequence
476404
 except ImportError:
476404
@@ -549,7 +549,7 @@ def _ts(self):
476404
         if self.conf.ignorearch:
476404
             self._rpm_probfilter.add(rpm.RPMPROB_FILTER_IGNOREARCH)
476404
 
476404
-        probfilter = reduce(operator.or_, self._rpm_probfilter, 0)
476404
+        probfilter = functools.reduce(operator.or_, self._rpm_probfilter, 0)
476404
         self._priv_ts.setProbFilter(probfilter)
476404
         return self._priv_ts
476404
 
476404
@@ -890,6 +890,15 @@ def do_transaction(self, display=()):
476404
         self._plugins.unload_removed_plugins(self.transaction)
476404
         self._plugins.run_transaction()
476404
 
476404
+        # log post transaction summary
476404
+        def _pto_callback(action, tsis):
476404
+            msgs = []
476404
+            for tsi in tsis:
476404
+                msgs.append('{}: {}'.format(action, str(tsi)))
476404
+            return msgs
476404
+        for msg in dnf.util._post_transaction_output(self, self.transaction, _pto_callback):
476404
+            logger.debug(msg)
476404
+
476404
         return tid
476404
 
476404
     def _trans_error_summary(self, errstring):
476404
@@ -1311,7 +1320,7 @@ def _do_package_lists(self, pkgnarrow='all', patterns=None, showdups=None,
476404
         if patterns is None or len(patterns) == 0:
476404
             return list_fn(None)
476404
         yghs = map(list_fn, patterns)
476404
-        return reduce(lambda a, b: a.merge_lists(b), yghs)
476404
+        return functools.reduce(lambda a, b: a.merge_lists(b), yghs)
476404
 
476404
     def _list_pattern(self, pkgnarrow, pattern, showdups, ignore_case,
476404
                       reponame=None):
476404
@@ -2579,6 +2588,37 @@ def setup_loggers(self):
476404
         """
476404
         self._logging._setup_from_dnf_conf(self.conf, file_loggers_only=True)
476404
 
476404
+    def _skipped_packages(self, report_problems, transaction):
476404
+        """returns set of conflicting packages and set of packages with broken dependency that would
476404
+        be additionally installed when --best and --allowerasing"""
476404
+        if self._goal.actions & (hawkey.INSTALL | hawkey.UPGRADE | hawkey.UPGRADE_ALL):
476404
+            best = True
476404
+        else:
476404
+            best = False
476404
+        ng = deepcopy(self._goal)
476404
+        params = {"allow_uninstall": self._allow_erasing,
476404
+                  "force_best": best,
476404
+                  "ignore_weak": True}
476404
+        ret = ng.run(**params)
476404
+        if not ret and report_problems:
476404
+            msg = dnf.util._format_resolve_problems(ng.problem_rules())
476404
+            logger.warning(msg)
476404
+        problem_conflicts = set(ng.problem_conflicts(available=True))
476404
+        problem_dependency = set(ng.problem_broken_dependency(available=True)) - problem_conflicts
476404
+
476404
+        def _nevra(item):
476404
+            return hawkey.NEVRA(name=item.name, epoch=item.epoch, version=item.version,
476404
+                                release=item.release, arch=item.arch)
476404
+
476404
+        # Sometimes, pkg is not in transaction item, therefore, comparing by nevra
476404
+        transaction_nevras = [_nevra(tsi) for tsi in transaction]
476404
+        skipped_conflicts = set(
476404
+            [pkg for pkg in problem_conflicts if _nevra(pkg) not in transaction_nevras])
476404
+        skipped_dependency = set(
476404
+            [pkg for pkg in problem_dependency if _nevra(pkg) not in transaction_nevras])
476404
+
476404
+        return skipped_conflicts, skipped_dependency
476404
+
476404
 
476404
 def _msg_installed(pkg):
476404
     name = ucd(pkg)
476404
diff --git a/dnf/cli/cli.py b/dnf/cli/cli.py
476404
index 0bc2c119d0..334000362c 100644
476404
--- a/dnf/cli/cli.py
476404
+++ b/dnf/cli/cli.py
476404
@@ -252,8 +252,12 @@ def do_transaction(self, display=()):
476404
             trans = None
476404
 
476404
         if trans:
476404
-            msg = self.output.post_transaction_output(trans)
476404
-            logger.info(msg)
476404
+            # the post transaction summary is already written to log during
476404
+            # Base.do_transaction() so here only print the messages to the
476404
+            # user arranged in columns
476404
+            print()
476404
+            print('\n'.join(self.output.post_transaction_output(trans)))
476404
+            print()
476404
             for tsi in trans:
476404
                 if tsi.state == libdnf.transaction.TransactionItemState_ERROR:
476404
                     raise dnf.exceptions.Error(_('Transaction failed'))
476404
diff --git a/dnf/cli/output.py b/dnf/cli/output.py
476404
index af8a968770..6d729b63ba 100644
476404
--- a/dnf/cli/output.py
476404
+++ b/dnf/cli/output.py
476404
@@ -21,9 +21,7 @@
476404
 from __future__ import print_function
476404
 from __future__ import unicode_literals
476404
 
476404
-from copy import deepcopy
476404
 import fnmatch
476404
-import functools
476404
 import hawkey
476404
 import itertools
476404
 import libdnf.transaction
476404
@@ -53,51 +51,6 @@
476404
 logger = logging.getLogger('dnf')
476404
 
476404
 
476404
-def _make_lists(transaction):
476404
-    b = dnf.util.Bunch({
476404
-        'downgraded': [],
476404
-        'erased': [],
476404
-        'erased_clean': [],
476404
-        'erased_dep': [],
476404
-        'installed': [],
476404
-        'installed_group': [],
476404
-        'installed_dep': [],
476404
-        'installed_weak': [],
476404
-        'reinstalled': [],
476404
-        'upgraded': [],
476404
-        'failed': [],
476404
-    })
476404
-
476404
-    for tsi in transaction:
476404
-        if tsi.state == libdnf.transaction.TransactionItemState_ERROR:
476404
-            b.failed.append(tsi)
476404
-        elif tsi.action == libdnf.transaction.TransactionItemAction_DOWNGRADE:
476404
-            b.downgraded.append(tsi)
476404
-        elif tsi.action == libdnf.transaction.TransactionItemAction_INSTALL:
476404
-            if tsi.reason == libdnf.transaction.TransactionItemReason_GROUP:
476404
-                b.installed_group.append(tsi)
476404
-            elif tsi.reason == libdnf.transaction.TransactionItemReason_DEPENDENCY:
476404
-                b.installed_dep.append(tsi)
476404
-            elif tsi.reason == libdnf.transaction.TransactionItemReason_WEAK_DEPENDENCY:
476404
-                b.installed_weak.append(tsi)
476404
-            else:
476404
-                # TransactionItemReason_USER
476404
-                b.installed.append(tsi)
476404
-        elif tsi.action == libdnf.transaction.TransactionItemAction_REINSTALL:
476404
-            b.reinstalled.append(tsi)
476404
-        elif tsi.action == libdnf.transaction.TransactionItemAction_REMOVE:
476404
-            if tsi.reason == libdnf.transaction.TransactionItemReason_CLEAN:
476404
-                b.erased_clean.append(tsi)
476404
-            elif tsi.reason == libdnf.transaction.TransactionItemReason_DEPENDENCY:
476404
-                b.erased_dep.append(tsi)
476404
-            else:
476404
-                b.erased.append(tsi)
476404
-        elif tsi.action == libdnf.transaction.TransactionItemAction_UPGRADE:
476404
-            b.upgraded.append(tsi)
476404
-
476404
-    return b
476404
-
476404
-
476404
 def _spread_in_columns(cols_count, label, lst):
476404
     left = itertools.chain((label,), itertools.repeat(''))
476404
     lst_length = len(lst)
476404
@@ -1057,37 +1010,6 @@ def list_group_transaction(self, comps, history, diff):
476404
             out[0:0] = self._banner(col_data, (_('Group'), _('Packages'), '', ''))
476404
         return '\n'.join(out)
476404
 
476404
-    def _skipped_packages(self, report_problems, transaction):
476404
-        """returns set of conflicting packages and set of packages with broken dependency that would
476404
-        be additionally installed when --best and --allowerasing"""
476404
-        if self.base._goal.actions & (hawkey.INSTALL | hawkey.UPGRADE | hawkey.UPGRADE_ALL):
476404
-            best = True
476404
-        else:
476404
-            best = False
476404
-        ng = deepcopy(self.base._goal)
476404
-        params = {"allow_uninstall": self.base._allow_erasing,
476404
-                  "force_best": best,
476404
-                  "ignore_weak": True}
476404
-        ret = ng.run(**params)
476404
-        if not ret and report_problems:
476404
-            msg = dnf.util._format_resolve_problems(ng.problem_rules())
476404
-            logger.warning(msg)
476404
-        problem_conflicts = set(ng.problem_conflicts(available=True))
476404
-        problem_dependency = set(ng.problem_broken_dependency(available=True)) - problem_conflicts
476404
-
476404
-        def _nevra(item):
476404
-            return hawkey.NEVRA(name=item.name, epoch=item.epoch, version=item.version,
476404
-                                release=item.release, arch=item.arch)
476404
-
476404
-        # Sometimes, pkg is not in transaction item, therefore, comparing by nevra
476404
-        transaction_nevras = [_nevra(tsi) for tsi in transaction]
476404
-        skipped_conflicts = set(
476404
-            [pkg for pkg in problem_conflicts if _nevra(pkg) not in transaction_nevras])
476404
-        skipped_dependency = set(
476404
-            [pkg for pkg in problem_dependency if _nevra(pkg) not in transaction_nevras])
476404
-
476404
-        return skipped_conflicts, skipped_dependency
476404
-
476404
     def list_transaction(self, transaction, total_width=None):
476404
         """Return a string representation of the transaction in an
476404
         easy-to-read format.
476404
@@ -1102,7 +1024,7 @@ def list_transaction(self, transaction, total_width=None):
476404
             # in order to display module changes when RPM transaction is empty
476404
             transaction = []
476404
 
476404
-        list_bunch = _make_lists(transaction)
476404
+        list_bunch = dnf.util._make_lists(transaction)
476404
         pkglist_lines = []
476404
         data = {'n' : {}, 'v' : {}, 'r' : {}}
476404
         a_wid = 0 # Arch can't get "that big" ... so always use the max.
476404
@@ -1271,7 +1193,7 @@ def format_line(group):
476404
         # show skipped conflicting packages
476404
         if not self.conf.best and self.base._goal.actions & forward_actions:
476404
             lines = []
476404
-            skipped_conflicts, skipped_broken = self._skipped_packages(
476404
+            skipped_conflicts, skipped_broken = self.base._skipped_packages(
476404
                 report_problems=True, transaction=transaction)
476404
             skipped_broken = dict((str(pkg), pkg) for pkg in skipped_broken)
476404
             for pkg in sorted(skipped_conflicts):
476404
@@ -1436,13 +1358,8 @@ def format_line(group):
476404
                                   max_msg_count, count, msg_pkgs))
476404
         return ''.join(out)
476404
 
476404
-    def post_transaction_output(self, transaction):
476404
-        """Returns a human-readable summary of the results of the
476404
-        transaction.
476404
 
476404
-        :return: a string containing a human-readable summary of the
476404
-           results of the transaction
476404
-        """
476404
+    def _pto_callback(self, action, tsis):
476404
         #  Works a bit like calcColumns, but we never overflow a column we just
476404
         # have a dynamic number of columns.
476404
         def _fits_in_cols(msgs, num):
476404
@@ -1472,61 +1389,33 @@ def _fits_in_cols(msgs, num):
476404
                 col_lens[col] *= -1
476404
             return col_lens
476404
 
476404
-        def _tsi_or_pkg_nevra_cmp(item1, item2):
476404
-            """Compares two transaction items or packages by nevra.
476404
-               Used as a fallback when tsi does not contain package object.
476404
-            """
476404
-            ret = (item1.name > item2.name) - (item1.name < item2.name)
476404
-            if ret != 0:
476404
-                return ret
476404
-            nevra1 = hawkey.NEVRA(name=item1.name, epoch=item1.epoch, version=item1.version,
476404
-                                  release=item1.release, arch=item1.arch)
476404
-            nevra2 = hawkey.NEVRA(name=item2.name, epoch=item2.epoch, version=item2.version,
476404
-                                  release=item2.release, arch=item2.arch)
476404
-            ret = nevra1.evr_cmp(nevra2, self.sack)
476404
-            if ret != 0:
476404
-                return ret
476404
-            return (item1.arch > item2.arch) - (item1.arch < item2.arch)
476404
-
476404
-        out = ''
476404
-        list_bunch = _make_lists(transaction)
476404
-
476404
-        skipped_conflicts, skipped_broken = self._skipped_packages(
476404
-            report_problems=False, transaction=transaction)
476404
-        skipped = skipped_conflicts.union(skipped_broken)
476404
-
476404
-        for (action, tsis) in [(_('Upgraded'), list_bunch.upgraded),
476404
-                               (_('Downgraded'), list_bunch.downgraded),
476404
-                               (_('Installed'), list_bunch.installed +
476404
-                                list_bunch.installed_group +
476404
-                                list_bunch.installed_weak +
476404
-                                list_bunch.installed_dep),
476404
-                               (_('Reinstalled'), list_bunch.reinstalled),
476404
-                               (_('Skipped'), skipped),
476404
-                               (_('Removed'), list_bunch.erased +
476404
-                                   list_bunch.erased_dep +
476404
-                                   list_bunch.erased_clean),
476404
-                               (_('Failed'), list_bunch.failed)]:
476404
-            if not tsis:
476404
-                continue
476404
-            msgs = []
476404
-            out += '\n%s:\n' % action
476404
-            for tsi in sorted(tsis, key=functools.cmp_to_key(_tsi_or_pkg_nevra_cmp)):
476404
-                msgs.append(str(tsi))
476404
-            for num in (8, 7, 6, 5, 4, 3, 2):
476404
-                cols = _fits_in_cols(msgs, num)
476404
-                if cols:
476404
-                    break
476404
-            if not cols:
476404
-                cols = [-(self.term.columns - 2)]
476404
-            while msgs:
476404
-                current_msgs = msgs[:len(cols)]
476404
-                out += '  '
476404
-                out += self.fmtColumns(zip(current_msgs, cols), end=u'\n')
476404
-                msgs = msgs[len(cols):]
476404
-
476404
+        if not tsis:
476404
+            return ''
476404
+        out = []
476404
+        msgs = []
476404
+        out.append('{}:'.format(action))
476404
+        for tsi in tsis:
476404
+            msgs.append(str(tsi))
476404
+        for num in (8, 7, 6, 5, 4, 3, 2):
476404
+            cols = _fits_in_cols(msgs, num)
476404
+            if cols:
476404
+                break
476404
+        if not cols:
476404
+            cols = [-(self.term.columns - 2)]
476404
+        while msgs:
476404
+            current_msgs = msgs[:len(cols)]
476404
+            out.append('  {}'.format(self.fmtColumns(zip(current_msgs, cols))))
476404
+            msgs = msgs[len(cols):]
476404
         return out
476404
 
476404
+
476404
+    def post_transaction_output(self, transaction):
476404
+        """
476404
+        Return a human-readable summary of the transaction. Packages in sections
476404
+        are arranged to columns.
476404
+        """
476404
+        return dnf.util._post_transaction_output(self.base, transaction, self._pto_callback)
476404
+
476404
     def setup_progress_callbacks(self):
476404
         """Set up the progress callbacks and various
476404
            output bars based on debug level.
476404
diff --git a/dnf/util.py b/dnf/util.py
476404
index 8cf362706d..0beb04424d 100644
476404
--- a/dnf/util.py
476404
+++ b/dnf/util.py
476404
@@ -24,13 +24,14 @@
476404
 
476404
 from .pycomp import PY3, basestring
476404
 from dnf.i18n import _, ucd
476404
-from functools import reduce
476404
 import argparse
476404
 import dnf
476404
 import dnf.callback
476404
 import dnf.const
476404
 import dnf.pycomp
476404
 import errno
476404
+import functools
476404
+import hawkey
476404
 import itertools
476404
 import locale
476404
 import logging
476404
@@ -41,6 +42,7 @@
476404
 import tempfile
476404
 import time
476404
 import libdnf.repo
476404
+import libdnf.transaction
476404
 
476404
 logger = logging.getLogger('dnf')
476404
 
476404
@@ -195,7 +197,7 @@ def group_by_filter(fn, iterable):
476404
     def splitter(acc, item):
476404
         acc[not bool(fn(item))].append(item)
476404
         return acc
476404
-    return reduce(splitter, iterable, ([], []))
476404
+    return functools.reduce(splitter, iterable, ([], []))
476404
 
476404
 def insert_if(item, iterable, condition):
476404
     """Insert an item into an iterable by a condition."""
476404
@@ -504,3 +506,99 @@ def __setattr__(self, what, val):
476404
         def setter(item):
476404
             setattr(item, what, val)
476404
         return list(map(setter, self))
476404
+
476404
+
476404
+def _make_lists(transaction):
476404
+    b = Bunch({
476404
+        'downgraded': [],
476404
+        'erased': [],
476404
+        'erased_clean': [],
476404
+        'erased_dep': [],
476404
+        'installed': [],
476404
+        'installed_group': [],
476404
+        'installed_dep': [],
476404
+        'installed_weak': [],
476404
+        'reinstalled': [],
476404
+        'upgraded': [],
476404
+        'failed': [],
476404
+    })
476404
+
476404
+    for tsi in transaction:
476404
+        if tsi.state == libdnf.transaction.TransactionItemState_ERROR:
476404
+            b.failed.append(tsi)
476404
+        elif tsi.action == libdnf.transaction.TransactionItemAction_DOWNGRADE:
476404
+            b.downgraded.append(tsi)
476404
+        elif tsi.action == libdnf.transaction.TransactionItemAction_INSTALL:
476404
+            if tsi.reason == libdnf.transaction.TransactionItemReason_GROUP:
476404
+                b.installed_group.append(tsi)
476404
+            elif tsi.reason == libdnf.transaction.TransactionItemReason_DEPENDENCY:
476404
+                b.installed_dep.append(tsi)
476404
+            elif tsi.reason == libdnf.transaction.TransactionItemReason_WEAK_DEPENDENCY:
476404
+                b.installed_weak.append(tsi)
476404
+            else:
476404
+                # TransactionItemReason_USER
476404
+                b.installed.append(tsi)
476404
+        elif tsi.action == libdnf.transaction.TransactionItemAction_REINSTALL:
476404
+            b.reinstalled.append(tsi)
476404
+        elif tsi.action == libdnf.transaction.TransactionItemAction_REMOVE:
476404
+            if tsi.reason == libdnf.transaction.TransactionItemReason_CLEAN:
476404
+                b.erased_clean.append(tsi)
476404
+            elif tsi.reason == libdnf.transaction.TransactionItemReason_DEPENDENCY:
476404
+                b.erased_dep.append(tsi)
476404
+            else:
476404
+                b.erased.append(tsi)
476404
+        elif tsi.action == libdnf.transaction.TransactionItemAction_UPGRADE:
476404
+            b.upgraded.append(tsi)
476404
+
476404
+    return b
476404
+
476404
+
476404
+def _post_transaction_output(base, transaction, action_callback):
476404
+    """Returns a human-readable summary of the results of the
476404
+    transaction.
476404
+
476404
+    :param action_callback: function generating output for specific action. It
476404
+       takes two parameters - action as a string and list of affected packages for
476404
+       this action
476404
+    :return: a list of lines containing a human-readable summary of the
476404
+       results of the transaction
476404
+    """
476404
+    def _tsi_or_pkg_nevra_cmp(item1, item2):
476404
+        """Compares two transaction items or packages by nevra.
476404
+           Used as a fallback when tsi does not contain package object.
476404
+        """
476404
+        ret = (item1.name > item2.name) - (item1.name < item2.name)
476404
+        if ret != 0:
476404
+            return ret
476404
+        nevra1 = hawkey.NEVRA(name=item1.name, epoch=item1.epoch, version=item1.version,
476404
+                              release=item1.release, arch=item1.arch)
476404
+        nevra2 = hawkey.NEVRA(name=item2.name, epoch=item2.epoch, version=item2.version,
476404
+                              release=item2.release, arch=item2.arch)
476404
+        ret = nevra1.evr_cmp(nevra2, base.sack)
476404
+        if ret != 0:
476404
+            return ret
476404
+        return (item1.arch > item2.arch) - (item1.arch < item2.arch)
476404
+
476404
+    list_bunch = dnf.util._make_lists(transaction)
476404
+
476404
+    skipped_conflicts, skipped_broken = base._skipped_packages(
476404
+        report_problems=False, transaction=transaction)
476404
+    skipped = skipped_conflicts.union(skipped_broken)
476404
+
476404
+    out = []
476404
+    for (action, tsis) in [(_('Upgraded'), list_bunch.upgraded),
476404
+                           (_('Downgraded'), list_bunch.downgraded),
476404
+                           (_('Installed'), list_bunch.installed +
476404
+                            list_bunch.installed_group +
476404
+                            list_bunch.installed_weak +
476404
+                            list_bunch.installed_dep),
476404
+                           (_('Reinstalled'), list_bunch.reinstalled),
476404
+                           (_('Skipped'), skipped),
476404
+                           (_('Removed'), list_bunch.erased +
476404
+                               list_bunch.erased_dep +
476404
+                               list_bunch.erased_clean),
476404
+                           (_('Failed'), list_bunch.failed)]:
476404
+        out.extend(action_callback(
476404
+            action, sorted(tsis, key=functools.cmp_to_key(_tsi_or_pkg_nevra_cmp))))
476404
+
476404
+    return out