From 5018d7c3bc6348b5a6fc5aa62d93d04b93b59dd6 Mon Sep 17 00:00:00 2001 From: Jose Castillo Date: Tue, 17 Sep 2024 15:21:48 +0100 Subject: [PATCH] [report] Fix html formatting for Plugin section After moving from .format() to f-strings via 57d21346b, the formatting for Plugin sections was lost. This patch attempts to fix this while still using f-strings. Related: #3780 Signed-off-by: Jose Castillo --- sos/report/reporting.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/sos/report/reporting.py b/sos/report/reporting.py index d87f8d35b..9b99dec5b 100644 --- a/sos/report/reporting.py +++ b/sos/report/reporting.py @@ -136,11 +136,9 @@ class PlainTextReport: ALERT = " ! %s" NOTE = " * %s" PLUGLISTHEADER = "Loaded Plugins:" - PLUGLISTITEM = " {name}" PLUGLISTSEP = "\n" PLUGLISTMAXITEMS = 5 PLUGLISTFOOTER = "" - PLUGINFORMAT = "{name}" PLUGDIVIDER = "=" * 72 subsections = ( @@ -156,6 +154,12 @@ class PlainTextReport: def __init__(self, report_node): self.report_data = sorted(dict.items(report_node.data)) + def plugListHeader(self, name): + return f" {name}" + + def pluginFormat(self, name): + return f"{name}" + def unicode(self): self.line_buf = line_buf = [] @@ -168,7 +172,7 @@ def unicode(self): i = 0 plugcount = len(self.report_data) for section_name, _ in self.report_data: - line += f" {section_name}" + line += self.plugListHeader(section_name) i += 1 if (i % self.PLUGLISTMAXITEMS == 0) and (i < plugcount): line += self.PLUGLISTSEP @@ -177,7 +181,7 @@ def unicode(self): for section_name, section_contents in self.report_data: line_buf.append(self.PLUGDIVIDER) - line_buf.append(f"{section_name}") + line_buf.append(self.pluginFormat(section_name)) for type_, format_, header, footer in self.subsections: self.process_subsection(section_contents, type_.ADDS_TO, header, format_, footer) @@ -224,11 +228,9 @@ class HTMLReport(PlainTextReport): ALERT = "
  • %s
  • " NOTE = "
  • %s
  • " PLUGLISTHEADER = "

    Loaded Plugins:

    " - PLUGLISTITEM = '\n' PLUGLISTSEP = "\n" PLUGLISTMAXITEMS = 5 PLUGLISTFOOTER = "
    {name}
    " - PLUGINFORMAT = '

    Plugin {name}

    ' PLUGDIVIDER = "
    \n" subsections = ( @@ -239,6 +241,12 @@ class HTMLReport(PlainTextReport): (Note, NOTE, "

    Notes:

    "), ) + def plugListHeader(self, name): + return f'{name}\n' + + def pluginFormat(self, name): + return f'

    Plugin {name}

    ' + class JSONReport(PlainTextReport): """Will generate a JSON report from a top_level Report object"""