Skip to content

Commit

Permalink
Adding support for custom title in HTML report
Browse files Browse the repository at this point in the history
  • Loading branch information
ALLARD Antoine committed May 23, 2023
1 parent 97b9c9e commit ffa3c23
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
7 changes: 6 additions & 1 deletion ValgrindCI/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ def main():
parser.add_argument(
"--output-dir", help="directory where the HTML report will be generated"
)
parser.add_argument(
"--html-report-title",
default="ValgrindCI Report",
help="the title of the generated HTML report"
)
parser.add_argument(
"--summary",
default=False,
Expand Down Expand Up @@ -102,7 +107,7 @@ def main():
if args.output_dir:
renderer = HTMLRenderer(data)
renderer.set_source_dir(args.source_dir)
renderer.render(args.output_dir, args.lines_before, args.lines_after)
renderer.render(args.html_report_title, args.output_dir, args.lines_before, args.lines_after)

if args.number_of_errors:
print("{} errors.".format(errors_total))
Expand Down
4 changes: 2 additions & 2 deletions ValgrindCI/data/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
<html lang="en">

<head>
<title>Valgrind report</title>
<title>{{ title }}</title>
<link href='valgrind.css' rel='stylesheet' type='text/css'>
</head>

<body>
<div class="global">
<div class="header">
<h1>ValgrindCI Report</h1>
<h1>{{ title }}</h1>
<p><b>{{ num_errors }}</b> errors</p>
</div>
<table>
Expand Down
6 changes: 4 additions & 2 deletions ValgrindCI/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def set_source_dir(self, source_dir: Optional[str]) -> None:
else:
self._source_dir = None

def render(self, output_dir: str, lines_before: int, lines_after: int) -> None:
def render(self, report_title: str, output_dir: str, lines_before: int, lines_after: int) -> None:
if not os.path.exists(output_dir):
os.makedirs(output_dir)
shutil.copy(
Expand Down Expand Up @@ -88,7 +88,9 @@ def render(self, output_dir: str, lines_before: int, lines_after: int) -> None:
with open(os.path.join(output_dir, "index.html"), "w") as f:
f.write(
self._index_tmpl.render(
source_list=summary, num_errors=total_num_errors
title=report_title,
source_list=summary,
num_errors=total_num_errors
)
)

Expand Down

0 comments on commit ffa3c23

Please sign in to comment.