f-strings

This commit is contained in:
Devaev Maxim 2019-06-28 06:27:46 +03:00
parent 724c6e118f
commit 2ed3c4815b
3 changed files with 11 additions and 12 deletions

View File

@ -25,8 +25,7 @@ import textwrap
# =====
def get_prepend() -> str:
return textwrap.dedent("""
C_PREPEND = textwrap.dedent("""
/*****************************************************************************
# #
# uStreamer - Lightweight and fast MJPG-HTTP streamer. #

View File

@ -29,7 +29,7 @@ import common
# =====
def main() -> None:
assert len(sys.argv) == 4, "%s <file.html> <file.h> <name>" % (sys.argv[0])
assert len(sys.argv) == 4, f"{sys.argv[0]} <file.html> <file.h> <name>"
html_path = sys.argv[1]
header_path = sys.argv[2]
name = sys.argv[3]
@ -42,11 +42,11 @@ def main() -> None:
text = text.replace("%VERSION%", "\" VERSION \"")
text = textwrap.indent(text, "\t", (lambda line: True))
text = "\n".join(
("%s \\" if line.strip() else "%s\\") % (line)
(f"{line} \\" if line.strip() else f"{line}\\")
for line in text.split("\n")
)
text = "const char HTML_%s_PAGE[] = \" \\\n%s\n\";\n" % (name, text)
text = common.get_prepend() + "\n#include \"../../config.h\"\n\n\n" + text
text = f"const char HTML_{name}_PAGE[] = \" \\\n{text}\n\";\n"
text = f"{common.C_PREPEND}\n#include \"../../config.h\"\n\n\n{text}"
with open(header_path, "w") as header_file:
header_file.write(text)

View File

@ -60,7 +60,7 @@ def _get_jpeg_size(data: bytes) -> Tuple[int, int]:
# =====
def main() -> None:
assert len(sys.argv) == 4, "%s <file.jpeg> <file.h> <name>" % (sys.argv[0])
assert len(sys.argv) == 4, f"{sys.argv[0]} <file.jpeg> <file.h> <name>"
jpeg_path = sys.argv[1]
header_path = sys.argv[2]
name = sys.argv[3]
@ -74,13 +74,13 @@ def main() -> None:
for ch in jpeg_data:
if len(rows[-1]) > 20:
rows.append([])
rows[-1].append("0x%.2X" % (ch))
rows[-1].append(f"0x{ch:02X}")
text = ",\n\t".join(", ".join(row) for row in rows)
text = "const unsigned char %s_JPEG_DATA[] = {\n\t%s\n};\n" % (name, text)
text = "const unsigned %s_JPEG_HEIGHT = %d;\n\n" % (name, height) + text
text = "const unsigned %s_JPEG_WIDTH = %d;\n" % (name, width) + text
text = common.get_prepend() + "\n\n" + text
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}"
with open(header_path, "w") as header_file:
header_file.write(text)