From df64fd36d7fefe39a96fea3f41e35785bebd37ec Mon Sep 17 00:00:00 2001 From: Marek Blaha Date: Wed, 2 Dec 2020 16:33:26 +0100 Subject: [PATCH 1/2] Log scriptlets output also for API users (RhBug:1847340) Messages logged into /var/log/dnf.rpm.log are now the same for both command line and API usage. https://bugzilla.redhat.com/show_bug.cgi?id=1847340 --- dnf/cli/output.py | 7 +------ dnf/yum/rpmtrans.py | 9 ++++++++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/dnf/cli/output.py b/dnf/cli/output.py index 51d6829ca6..86260661fc 100644 --- a/dnf/cli/output.py +++ b/dnf/cli/output.py @@ -2151,12 +2151,7 @@ def error(self, message): pass def scriptout(self, msgs): - """Print messages originating from a package script. - - :param msgs: the messages coming from the script - """ - if msgs: - self.rpm_logger.info(ucd(msgs)) + pass def _makefmt(self, percent, ts_done, ts_total, progress=True, pkgname=None, wid1=15): diff --git a/dnf/yum/rpmtrans.py b/dnf/yum/rpmtrans.py index 447639a476..d6c549d2ed 100644 --- a/dnf/yum/rpmtrans.py +++ b/dnf/yum/rpmtrans.py @@ -113,7 +113,10 @@ def progress(self, package, action, ti_done, ti_total, ts_done, ts_total): pass def scriptout(self, msgs): - """msgs is the messages that were output (if any).""" + """Hook for reporting an rpm scriptlet output. + + :param msgs: the scriptlet output + """ pass def error(self, message): @@ -156,6 +159,10 @@ def filelog(self, package, action): msg = '%s: %s' % (action_str, package) self.rpm_logger.log(dnf.logging.SUBDEBUG, msg) + def scriptout(self, msgs): + if msgs: + self.rpm_logger.info(ucd(msgs)) + class RPMTransaction(object): def __init__(self, base, test=False, displays=()): From ee6ffcf640180b2b08d2db50b4b81d2bdefb1f2f Mon Sep 17 00:00:00 2001 From: Marek Blaha Date: Thu, 3 Dec 2020 10:08:09 +0100 Subject: [PATCH 2/2] Straighten inheritance of *Display classes --- dnf/cli/output.py | 15 +++------------ dnf/yum/rpmtrans.py | 2 +- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/dnf/cli/output.py b/dnf/cli/output.py index 86260661fc..de188ffbd1 100644 --- a/dnf/cli/output.py +++ b/dnf/cli/output.py @@ -37,7 +37,7 @@ from dnf.cli.format import format_number, format_time from dnf.i18n import _, C_, P_, ucd, fill_exact_width, textwrap_fill, exact_width, select_short_long from dnf.pycomp import xrange, basestring, long, unicode, sys_maxsize -from dnf.yum.rpmtrans import LoggingTransactionDisplay +from dnf.yum.rpmtrans import TransactionDisplay from dnf.db.history import MergedTransactionWrapper import dnf.base import dnf.callback @@ -2071,7 +2071,7 @@ def short_id(id): return self.output.userconfirm() -class CliTransactionDisplay(LoggingTransactionDisplay): +class CliTransactionDisplay(TransactionDisplay): """A YUM specific callback class for RPM operations.""" width = property(lambda self: dnf.cli.term._term_width()) @@ -2093,7 +2093,7 @@ def progress(self, package, action, ti_done, ti_total, ts_done, ts_total): :param package: the package involved in the event :param action: the type of action that is taking place. Valid values are given by - :func:`rpmtrans.LoggingTransactionDisplay.action.keys()` + :func:`rpmtrans.TransactionDisplay.action.keys()` :param ti_done: a number representing the amount of work already done in the current transaction :param ti_total: a number representing the total amount of work @@ -2144,15 +2144,6 @@ def _out_progress(self, ti_done, ti_total, ts_done, ts_total, if ti_done == ti_total: print(" ") - def filelog(self, package, action): - pass - - def error(self, message): - pass - - def scriptout(self, msgs): - pass - def _makefmt(self, percent, ts_done, ts_total, progress=True, pkgname=None, wid1=15): l = len(str(ts_total)) diff --git a/dnf/yum/rpmtrans.py b/dnf/yum/rpmtrans.py index d6c549d2ed..51fa921d3e 100644 --- a/dnf/yum/rpmtrans.py +++ b/dnf/yum/rpmtrans.py @@ -143,7 +143,7 @@ def error(self, message): dnf.util._terminal_messenger('print', message, sys.stderr) -class LoggingTransactionDisplay(ErrorTransactionDisplay): +class LoggingTransactionDisplay(TransactionDisplay): ''' Base class for a RPMTransaction display callback class '''