mirror of
https://github.com/pikvm/ustreamer.git
synced 2026-03-18 05:23:43 +00:00
f-strings
This commit is contained in:
@@ -25,8 +25,7 @@ import textwrap
|
|||||||
|
|
||||||
|
|
||||||
# =====
|
# =====
|
||||||
def get_prepend() -> str:
|
C_PREPEND = textwrap.dedent("""
|
||||||
return textwrap.dedent("""
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
# #
|
# #
|
||||||
# uStreamer - Lightweight and fast MJPG-HTTP streamer. #
|
# uStreamer - Lightweight and fast MJPG-HTTP streamer. #
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ import common
|
|||||||
|
|
||||||
# =====
|
# =====
|
||||||
def main() -> None:
|
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]
|
html_path = sys.argv[1]
|
||||||
header_path = sys.argv[2]
|
header_path = sys.argv[2]
|
||||||
name = sys.argv[3]
|
name = sys.argv[3]
|
||||||
@@ -42,11 +42,11 @@ def main() -> None:
|
|||||||
text = text.replace("%VERSION%", "\" VERSION \"")
|
text = text.replace("%VERSION%", "\" VERSION \"")
|
||||||
text = textwrap.indent(text, "\t", (lambda line: True))
|
text = textwrap.indent(text, "\t", (lambda line: True))
|
||||||
text = "\n".join(
|
text = "\n".join(
|
||||||
("%s \\" if line.strip() else "%s\\") % (line)
|
(f"{line} \\" if line.strip() else f"{line}\\")
|
||||||
for line in text.split("\n")
|
for line in text.split("\n")
|
||||||
)
|
)
|
||||||
text = "const char HTML_%s_PAGE[] = \" \\\n%s\n\";\n" % (name, text)
|
text = f"const char HTML_{name}_PAGE[] = \" \\\n{text}\n\";\n"
|
||||||
text = common.get_prepend() + "\n#include \"../../config.h\"\n\n\n" + text
|
text = f"{common.C_PREPEND}\n#include \"../../config.h\"\n\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)
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ def _get_jpeg_size(data: bytes) -> Tuple[int, int]:
|
|||||||
|
|
||||||
# =====
|
# =====
|
||||||
def main() -> None:
|
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]
|
jpeg_path = sys.argv[1]
|
||||||
header_path = sys.argv[2]
|
header_path = sys.argv[2]
|
||||||
name = sys.argv[3]
|
name = sys.argv[3]
|
||||||
@@ -74,13 +74,13 @@ def main() -> None:
|
|||||||
for ch in jpeg_data:
|
for ch in jpeg_data:
|
||||||
if len(rows[-1]) > 20:
|
if len(rows[-1]) > 20:
|
||||||
rows.append([])
|
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 = ",\n\t".join(", ".join(row) for row in rows)
|
||||||
text = "const unsigned char %s_JPEG_DATA[] = {\n\t%s\n};\n" % (name, text)
|
text = f"const unsigned char {name}_JPEG_DATA[] = {{\n\t{text}\n}};\n"
|
||||||
text = "const unsigned %s_JPEG_HEIGHT = %d;\n\n" % (name, height) + text
|
text = f"const unsigned {name}_JPEG_HEIGHT = {height};\n\n{text}"
|
||||||
text = "const unsigned %s_JPEG_WIDTH = %d;\n" % (name, width) + text
|
text = f"const unsigned {name}_JPEG_WIDTH = {width};\n{text}"
|
||||||
text = common.get_prepend() + "\n\n" + text
|
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)
|
||||||
|
|||||||
Reference in New Issue
Block a user