Skip to content

Commit 288ed88

Browse files
add option for html output (#213)
* add option for html output * format * make executable * add shebang * modify where check is * another move of checks * format --------- Co-authored-by: Cameron Bateman <cameron.bateman@metoffice.gov.uk>
1 parent 14a253c commit 288ed88

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

gh_review_project/cr_deadline.py

100644100755
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/env python3
12
# -----------------------------------------------------------------------------
23
# (C) Crown copyright Met Office. All rights reserved.
34
# The file LICENCE, distributed with this code, contains details of the terms

gh_review_project/finish_milestone.py

100644100755
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/env python3
12
# -----------------------------------------------------------------------------
23
# (C) Crown copyright Met Office. All rights reserved.
34
# The file LICENCE, distributed with this code, contains details of the terms

gh_review_project/set_milestone.py

100644100755
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/env python3
12
# -----------------------------------------------------------------------------
23
# (C) Crown copyright Met Office. All rights reserved.
34
# The file LICENCE, distributed with this code, contains details of the terms

gh_review_project/workload.py

100644100755
Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/env python3
12
# -----------------------------------------------------------------------------
23
# (C) Crown copyright Met Office. All rights reserved.
34
# The file LICENCE, distributed with this code, contains details of the terms
@@ -144,21 +145,31 @@ def build_table(data: ProjectData, reviewer_list: list, repos: list) -> PrettyTa
144145
return table
145146

146147

147-
def print_table(title: str, table: PrettyTable, sortTotal: bool) -> None:
148+
def print_table(
149+
title: str, table: PrettyTable, sortTotal: bool, html_output: str = ""
150+
) -> None:
148151
"""
149152
Print a pretty table and its title.
150153
151154
title: str Title of table to be printed first
152155
table: PrettyTable table to be printed
153156
"""
154-
print(title)
155-
# table.set_style(TableStyle.MARKDOWN) #requires newer version
157+
156158
table.align["Reviewer"] = "l"
157159

158160
if sortTotal:
159161
table.sortby = "Total"
160162

161-
print(table)
163+
if not html_output:
164+
print(title)
165+
print(table)
166+
return
167+
168+
table.format = True
169+
html_table = table.get_html_string()
170+
with open(html_output, "a") as f:
171+
f.write(f"<h1>{title}</h1>")
172+
f.write(html_table)
162173

163174

164175
def parse_args():
@@ -192,6 +203,12 @@ def parse_args():
192203
help="Filepath to test data for either capture the project status, "
193204
"or use as input data.",
194205
)
206+
parser.add_argument(
207+
"--html",
208+
default="",
209+
help="html file to output table contents to. If not set, an ascii formatted "
210+
"table will be outputted to stdout",
211+
)
195212

196213
args = parser.parse_args()
197214

@@ -236,8 +253,17 @@ def main(total: bool, test: bool, capture_project: bool, file: Path):
236253
tables["LFRic"] = build_table(data, reviewers, repo_list)
237254

238255
# Print tables
256+
# Check html path is valid
257+
if args.html:
258+
html_path = Path(args.html)
259+
if html_path.is_dir():
260+
raise ValueError("--html option cannot be a directory")
261+
html_dir = html_path.parent
262+
html_dir.mkdir(parents=True, exist_ok=True)
263+
html_path.unlink(missing_ok=True)
264+
239265
for name, table in tables.items():
240-
print_table(name, table, total)
266+
print_table(name, table, total, args.html)
241267

242268

243269
if __name__ == "__main__":

0 commit comments

Comments
 (0)