From fa6afad083ffc19438603f43d17785f5741505b4 Mon Sep 17 00:00:00 2001 From: Jaroslav Rohel Date: Mon, 16 Dec 2019 12:52:41 +0100 Subject: [PATCH 1/2] Sort packages in transaction output by nevra (RhBug:1773436) --- dnf/cli/output.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dnf/cli/output.py b/dnf/cli/output.py index 2ff41b6255..1d3eb1e94a 100644 --- a/dnf/cli/output.py +++ b/dnf/cli/output.py @@ -1147,7 +1147,7 @@ def _add_line(lines, data, a_wid, po, obsoletes=[]): for i in tsi._item.getReplacedBy(): replaces.setdefault(i, set()).add(tsi) - for tsi in pkglist: + for tsi in sorted(pkglist, key=lambda x: x.pkg): if tsi.action not in dnf.transaction.FORWARD_ACTIONS + [libdnf.transaction.TransactionItemAction_REMOVE]: continue From 0779b458ca30e895b72bcfb2d513c13b12f605df Mon Sep 17 00:00:00 2001 From: Jaroslav Rohel Date: Mon, 16 Dec 2019 14:53:00 +0100 Subject: [PATCH 2/2] Sort packages in post transaction output by nevra --- dnf/cli/output.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/dnf/cli/output.py b/dnf/cli/output.py index 1d3eb1e94a..5dc0af6f4b 100644 --- a/dnf/cli/output.py +++ b/dnf/cli/output.py @@ -23,6 +23,7 @@ from copy import deepcopy import fnmatch +import functools import hawkey import itertools import libdnf.transaction @@ -1449,11 +1450,26 @@ def _fits_in_cols(msgs, num): col_lens[col] *= -1 return col_lens + def _tsi_or_pkg_nevra_cmp(item1, item2): + """Compares two transaction items or packages by nevra. + Used as a fallback when tsi does not contain package object. + """ + ret = (item1.name > item2.name) - (item1.name < item2.name) + if ret != 0: + return ret + nevra1 = hawkey.NEVRA(name=item1.name, epoch=item1.epoch, version=item1.version, + release=item1.release, arch=item1.arch) + nevra2 = hawkey.NEVRA(name=item2.name, epoch=item2.epoch, version=item2.version, + release=item2.release, arch=item2.arch) + ret = nevra1.evr_cmp(nevra2, self.sack) + if ret != 0: + return ret + return (item1.arch > item2.arch) - (item1.arch < item2.arch) + out = '' list_bunch = _make_lists(transaction, self.base._goal) skipped_conflicts, skipped_broken = self._skipped_packages(report_problems=False) skipped = skipped_conflicts.union(skipped_broken) - skipped = sorted(set([str(pkg) for pkg in skipped])) for (action, tsis) in [(_('Upgraded'), list_bunch.upgraded), (_('Downgraded'), list_bunch.downgraded), @@ -1471,7 +1487,7 @@ def _fits_in_cols(msgs, num): continue msgs = [] out += '\n%s:\n' % action - for tsi in tsis: + for tsi in sorted(tsis, key=functools.cmp_to_key(_tsi_or_pkg_nevra_cmp)): msgs.append(str(tsi)) for num in (8, 7, 6, 5, 4, 3, 2): cols = _fits_in_cols(msgs, num)