Skip to content

Commit

Permalink
[report] Fix html formatting for Plugin section
Browse files Browse the repository at this point in the history
After moving from .format() to f-strings via
57d2134, the formatting for Plugin sections was
lost. This patch attempts to fix this while still
using f-strings.

Related: sosreport#3780

Signed-off-by: Jose Castillo <[email protected]>
  • Loading branch information
jcastill committed Sep 17, 2024
1 parent 8fab338 commit 5018d7c
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions sos/report/reporting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand All @@ -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 = []

Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -224,11 +228,9 @@ class HTMLReport(PlainTextReport):
ALERT = "<li>%s</li>"
NOTE = "<li>%s</li>"
PLUGLISTHEADER = "<h3>Loaded Plugins:</h3><table><tr>"
PLUGLISTITEM = '<td><a href="#{name}">{name}</a></td>\n'
PLUGLISTSEP = "</tr>\n<tr>"
PLUGLISTMAXITEMS = 5
PLUGLISTFOOTER = "</tr></table>"
PLUGINFORMAT = '<h2 id="{name}">Plugin <em>{name}</em></h2>'
PLUGDIVIDER = "<hr/>\n"

subsections = (
Expand All @@ -239,6 +241,12 @@ class HTMLReport(PlainTextReport):
(Note, NOTE, "<p>Notes:</p><ul>", "</ul>"),
)

def plugListHeader(self, name):
return f'<td><a href="#{name}">{name}</a></td>\n'

def pluginFormat(self, name):
return f'<h2 id="{name}">Plugin <em>{name}</em></h2>'


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

0 comments on commit 5018d7c

Please sign in to comment.