refactoring

This commit is contained in:
Devaev Maxim
2019-07-10 07:08:29 +03:00
parent c3c15b16bf
commit 87de066369
3 changed files with 714 additions and 679 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -35,18 +35,19 @@ def main() -> None:
name = sys.argv[3] name = sys.argv[3]
with open(html_path, "r") as html_file: with open(html_path, "r") as html_file:
text = html_file.read() html = html_file.read()
text = text.strip() html = html.strip()
text = text.replace("\"", "\\\"") html = html.replace("\"", "\\\"")
text = text.replace("%VERSION%", "\" VERSION \"") html = html.replace("%VERSION%", "\" VERSION \"")
text = textwrap.indent(text, "\t", (lambda line: True)) html = textwrap.indent(html, "\t", (lambda line: True))
text = "\n".join( html = "\n".join(
(f"{line} \\" if line.strip() else f"{line}\\") (f"{line} \\" if line.strip() else f"{line}\\")
for line in text.split("\n") for line in html.split("\n")
) )
text = f"const char HTML_{name}_PAGE[] = \" \\\n{text}\n\";\n"
text = f"{common.C_PREPEND}\n#include \"../../config.h\"\n\n\n{text}" text = f"{common.C_PREPEND}\n#include \"../../config.h\"\n\n\n"
text += f"const char HTML_{name}_PAGE[] = \" \\\n{html}\n\";\n"
with open(header_path, "w") as header_file: with open(header_path, "w") as header_file:
header_file.write(text) header_file.write(text)

View File

@@ -70,17 +70,18 @@ def main() -> None:
(width, height) = _get_jpeg_size(jpeg_data) (width, height) = _get_jpeg_size(jpeg_data)
rows: List[List[str]] = [[]] jpeg_data_text = "{\n\t" + ",\n\t".join(
for ch in jpeg_data: ", ".join(
if len(rows[-1]) > 20: f"0x{ch:02X}"
rows.append([]) for ch in jpeg_data[index:index + 20]
rows[-1].append(f"0x{ch:02X}") )
for index in range(0, len(jpeg_data), 20)
) + ",\n}"
text = ",\n\t".join(", ".join(row) for row in rows) text = f"{common.C_PREPEND}\n\n"
text = f"const unsigned char {name}_JPEG_DATA[] = {{\n\t{text}\n}};\n" text += f"const unsigned {name}_JPEG_WIDTH = {width};\n"
text = f"const unsigned {name}_JPEG_HEIGHT = {height};\n\n{text}" text += f"const unsigned {name}_JPEG_HEIGHT = {height};\n\n"
text = f"const unsigned {name}_JPEG_WIDTH = {width};\n{text}" text += f"const unsigned char {name}_JPEG_DATA[] = {jpeg_data_text};\n"
text = f"{common.C_PREPEND}\n\n{text}"
with open(header_path, "w") as header_file: with open(header_path, "w") as header_file:
header_file.write(text) header_file.write(text)