Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[report] Fix html formatting for Plugin section #3781

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading