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]
with open(html_path, "r") as html_file:
text = html_file.read()
html = html_file.read()
text = text.strip()
text = text.replace("\"", "\\\"")
text = text.replace("%VERSION%", "\" VERSION \"")
text = textwrap.indent(text, "\t", (lambda line: True))
text = "\n".join(
html = html.strip()
html = html.replace("\"", "\\\"")
html = html.replace("%VERSION%", "\" VERSION \"")
html = textwrap.indent(html, "\t", (lambda line: True))
html = "\n".join(
(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:
header_file.write(text)

View File

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