diff options
author | Teddy Wing | 2018-11-13 21:11:52 +0100 |
---|---|---|
committer | Teddy Wing | 2018-11-13 21:11:52 +0100 |
commit | fd154a053eb2b6240e2b0889acd922b5ac43212e (patch) | |
tree | a43c3c985dd6221aab72812ffdef1272575d02ee /scripts/generate_500.py | |
parent | a6a184968cbae23371254b57e4a3e3bc4d0e2b4d (diff) | |
download | dome-key-web-fd154a053eb2b6240e2b0889acd922b5ac43212e.tar.bz2 |
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
Diffstat (limited to 'scripts/generate_500.py')
-rwxr-xr-x | scripts/generate_500.py | 29 |
1 files changed, 29 insertions, 0 deletions
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='') |