From 4bae8bc64a365a7cb95a8b3ab4d0a064e4a2721e Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Fri, 22 Dec 2023 15:38:29 +0000 Subject: [PATCH] Fix location of template.html and add --refresh --- build.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/build.py b/build.py index e6236fd..0bf02b2 100755 --- a/build.py +++ b/build.py @@ -50,10 +50,10 @@ def download_bugs(state: str) -> list[Bug]: return all_bugs -def get_all_bugs() -> list[Bug]: +def get_all_bugs(refresh: bool = False) -> list[Bug]: """Get all bugs.""" filename = config.get("output", "cache") - if os.path.exists(filename): + if not refresh and os.path.exists(filename): with open(filename) as fh: return typing.cast(list[Bug], json.load(fh)) @@ -104,12 +104,16 @@ def count_open_bugs(bug_reports: list[Bug]) -> list[tuple[str, int]]: def main() -> None: """Grab bug reports and generate chart.""" - bug_reports = get_all_bugs() + refresh = len(sys.argv) > 1 and sys.argv[1] == "--refresh" + bug_reports = get_all_bugs(refresh) open_bugs_over_time = count_open_bugs(bug_reports) json_data = json.dumps(open_bugs_over_time) - template_html = open("template.html").read() + script_dir = os.path.dirname(os.path.abspath(__file__)) + template_path = os.path.join(script_dir, "template.html") + with open(template_path, "r") as fh: + template_html = fh.read() dest = config.get("output", "dest") with open(dest, "w") as out: out.write(template_html.replace("jsonData = []", "jsonData = " + json_data))