mirror of
https://github.com/pikvm/ustreamer.git
synced 2026-03-17 21:13:42 +00:00
refactoring
This commit is contained in:
@@ -33,7 +33,7 @@ max-line-length = 160
|
|||||||
|
|
||||||
[BASIC]
|
[BASIC]
|
||||||
# Good variable names which should always be accepted, separated by a comma
|
# Good variable names which should always be accepted, separated by a comma
|
||||||
good-names = _, __, x, y, ws, make-html-h, make-jpeg-h
|
good-names = _, __, x, y, ws, make-html-h, make-jpeg-h, make-ico-h
|
||||||
|
|
||||||
# Regular expression matching correct method names
|
# Regular expression matching correct method names
|
||||||
method-rgx = [a-z_][a-z0-9_]{2,50}$
|
method-rgx = [a-z_][a-z0-9_]{2,50}$
|
||||||
|
|||||||
@@ -26,26 +26,24 @@ import textwrap
|
|||||||
|
|
||||||
# =====
|
# =====
|
||||||
C_PREPEND = textwrap.dedent("""
|
C_PREPEND = textwrap.dedent("""
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
# #
|
# #
|
||||||
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
|
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
|
||||||
# #
|
# #
|
||||||
# Copyright (C) 2018-2022 Maxim Devaev <mdevaev@gmail.com> #
|
# Copyright (C) 2018-2022 Maxim Devaev <mdevaev@gmail.com> #
|
||||||
# #
|
# #
|
||||||
# This program is free software: you can redistribute it and/or modify #
|
# This program is free software: you can redistribute it and/or modify #
|
||||||
# it under the terms of the GNU General Public License as published by #
|
# it under the terms of the GNU General Public License as published by #
|
||||||
# the Free Software Foundation, either version 3 of the License, or #
|
# the Free Software Foundation, either version 3 of the License, or #
|
||||||
# (at your option) any later version. #
|
# (at your option) any later version. #
|
||||||
# #
|
# #
|
||||||
# This program is distributed in the hope that it will be useful, #
|
# This program is distributed in the hope that it will be useful, #
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
|
||||||
# GNU General Public License for more details. #
|
# GNU General Public License for more details. #
|
||||||
# #
|
# #
|
||||||
# You should have received a copy of the GNU General Public License #
|
# You should have received a copy of the GNU General Public License #
|
||||||
# along with this program. If not, see <https://www.gnu.org/licenses/>. #
|
# along with this program. If not, see <https://www.gnu.org/licenses/>. #
|
||||||
# #
|
# #
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
""").strip() + "\n"
|
||||||
|
|
||||||
""").strip() + "\n"
|
|
||||||
|
|||||||
@@ -36,8 +36,8 @@ def main() -> None:
|
|||||||
h_path = os.path.basename(c_path[:-2] + ".h")
|
h_path = os.path.basename(c_path[:-2] + ".h")
|
||||||
name = sys.argv[3]
|
name = sys.argv[3]
|
||||||
|
|
||||||
with open(html_path, "r") as html_file:
|
with open(html_path, "r") as file:
|
||||||
html = html_file.read()
|
html = file.read()
|
||||||
|
|
||||||
html = html.strip()
|
html = html.strip()
|
||||||
html = html.replace("\"", "\\\"")
|
html = html.replace("\"", "\\\"")
|
||||||
@@ -51,8 +51,8 @@ def main() -> None:
|
|||||||
text = f"{common.C_PREPEND}\n#include \"{h_path}\"\n\n\n"
|
text = f"{common.C_PREPEND}\n#include \"{h_path}\"\n\n\n"
|
||||||
text += f"const char *const US_HTML_{name}_PAGE = \" \\\n{html}\n\";\n"
|
text += f"const char *const US_HTML_{name}_PAGE = \" \\\n{html}\n\";\n"
|
||||||
|
|
||||||
with open(c_path, "w") as c_file:
|
with open(c_path, "w") as file:
|
||||||
c_file.write(text)
|
file.write(text)
|
||||||
|
|
||||||
|
|
||||||
# =====
|
# =====
|
||||||
|
|||||||
@@ -65,28 +65,28 @@ def main() -> None:
|
|||||||
h_path = os.path.basename(c_path[:-2]) + ".h"
|
h_path = os.path.basename(c_path[:-2]) + ".h"
|
||||||
name = sys.argv[3]
|
name = sys.argv[3]
|
||||||
|
|
||||||
with open(jpeg_path, "rb") as jpeg_file:
|
with open(jpeg_path, "rb") as file:
|
||||||
jpeg_data = jpeg_file.read()
|
data = file.read()
|
||||||
|
|
||||||
(width, height) = _get_jpeg_size(jpeg_data)
|
(width, height) = _get_jpeg_size(data)
|
||||||
|
|
||||||
jpeg_data_text = "{\n\t" + ",\n\t".join(
|
data_text = "{\n\t" + ",\n\t".join(
|
||||||
", ".join(
|
", ".join(
|
||||||
f"0x{ch:02X}"
|
f"0x{ch:02X}"
|
||||||
for ch in jpeg_data[index:index + 20]
|
for ch in data[index:index + 20]
|
||||||
)
|
)
|
||||||
for index in range(0, len(jpeg_data), 20)
|
for index in range(0, len(data), 20)
|
||||||
) + ",\n}"
|
) + ",\n}"
|
||||||
|
|
||||||
text = f"{common.C_PREPEND}\n"
|
text = f"{common.C_PREPEND}\n"
|
||||||
text += f"#include \"{h_path}\"\n\n\n"
|
text += f"#include \"{h_path}\"\n\n\n"
|
||||||
text += f"const unsigned US_{name}_JPEG_WIDTH = {width};\n"
|
text += f"const unsigned US_{name}_JPEG_WIDTH = {width};\n"
|
||||||
text += f"const unsigned US_{name}_JPEG_HEIGHT = {height};\n\n"
|
text += f"const unsigned US_{name}_JPEG_HEIGHT = {height};\n\n"
|
||||||
text += f"const size_t US_{name}_JPEG_DATA_SIZE = {len(jpeg_data)};\n"
|
text += f"const size_t US_{name}_JPEG_DATA_SIZE = {len(data)};\n"
|
||||||
text += f"const uint8_t US_{name}_JPEG_DATA[] = {jpeg_data_text};\n"
|
text += f"const uint8_t US_{name}_JPEG_DATA[] = {data_text};\n"
|
||||||
|
|
||||||
with open(c_path, "w") as c_file:
|
with open(c_path, "w") as file:
|
||||||
c_file.write(text)
|
file.write(text)
|
||||||
|
|
||||||
|
|
||||||
# =====
|
# =====
|
||||||
|
|||||||
Reference in New Issue
Block a user