From fd154a053eb2b6240e2b0889acd922b5ac43212e Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Tue, 13 Nov 2018 21:11:52 +0100 Subject: Add 500 error page with generator Base structure copied from `404.html`. Python script based on the `generate_homebrew_formula.py` script in the main DomeKey repository. The filename comes from the Apache server configuration. Generate the 500 page because we can't rely on dependencies. This gets the CSS and logo and includes them inline in the HTML page. Thanks to this answer for explaining how to get a byte string from a file to send to the base64 encoder: https://stackoverflow.com/questions/45482272/typeerror-a-bytes-like-object-is-required-not-str-python-2-to-3/45482834#45482834 --- scripts/generate_500.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100755 scripts/generate_500.py (limited to 'scripts/generate_500.py') diff --git a/scripts/generate_500.py b/scripts/generate_500.py new file mode 100755 index 0000000..a415a39 --- /dev/null +++ b/scripts/generate_500.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python3 + +from base64 import b64encode +from string import Template +import os + + +script_dir = os.path.dirname(__file__) + +template = '' +css = '' +logo = '' + +with open(os.path.join(script_dir, '../internal_error.in.html'), 'r') as template: + template = template.read() + +with open(os.path.join(script_dir, '../assets/styles.css'), 'r') as f: + css = f.read() + +with open(os.path.join(script_dir, '../assets/logo.svg'), 'r') as f: + logo = b64encode(f.read().encode('utf-8')) + +template = Template(template) +html = template.substitute( + CSS=css, + LOGO_DATA=logo, +) + +print(html, end='') -- cgit v1.2.3