mirror of
https://github.com/pikvm/ustreamer.git
synced 2026-02-18 02:55:46 +00:00
refactoring
This commit is contained in:
parent
d154a3d1c1
commit
01de2caa97
@ -33,7 +33,7 @@ max-line-length = 160
|
||||
|
||||
[BASIC]
|
||||
# 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
|
||||
method-rgx = [a-z_][a-z0-9_]{2,50}$
|
||||
|
||||
@ -26,26 +26,24 @@ import textwrap
|
||||
|
||||
# =====
|
||||
C_PREPEND = textwrap.dedent("""
|
||||
/*****************************************************************************
|
||||
# #
|
||||
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
|
||||
# #
|
||||
# Copyright (C) 2018-2022 Maxim Devaev <mdevaev@gmail.com> #
|
||||
# #
|
||||
# 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 #
|
||||
# the Free Software Foundation, either version 3 of the License, or #
|
||||
# (at your option) any later version. #
|
||||
# #
|
||||
# This program is distributed in the hope that it will be useful, #
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
|
||||
# GNU General Public License for more details. #
|
||||
# #
|
||||
# You should have received a copy of the GNU General Public License #
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>. #
|
||||
# #
|
||||
*****************************************************************************/
|
||||
|
||||
|
||||
""").strip() + "\n"
|
||||
/*****************************************************************************
|
||||
# #
|
||||
# uStreamer - Lightweight and fast MJPEG-HTTP streamer. #
|
||||
# #
|
||||
# Copyright (C) 2018-2022 Maxim Devaev <mdevaev@gmail.com> #
|
||||
# #
|
||||
# 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 #
|
||||
# the Free Software Foundation, either version 3 of the License, or #
|
||||
# (at your option) any later version. #
|
||||
# #
|
||||
# This program is distributed in the hope that it will be useful, #
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
|
||||
# GNU General Public License for more details. #
|
||||
# #
|
||||
# You should have received a copy of the GNU General Public License #
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>. #
|
||||
# #
|
||||
*****************************************************************************/
|
||||
""").strip() + "\n"
|
||||
|
||||
@ -36,8 +36,8 @@ def main() -> None:
|
||||
h_path = os.path.basename(c_path[:-2] + ".h")
|
||||
name = sys.argv[3]
|
||||
|
||||
with open(html_path, "r") as html_file:
|
||||
html = html_file.read()
|
||||
with open(html_path, "r") as file:
|
||||
html = file.read()
|
||||
|
||||
html = html.strip()
|
||||
html = html.replace("\"", "\\\"")
|
||||
@ -51,8 +51,8 @@ def main() -> None:
|
||||
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"
|
||||
|
||||
with open(c_path, "w") as c_file:
|
||||
c_file.write(text)
|
||||
with open(c_path, "w") as file:
|
||||
file.write(text)
|
||||
|
||||
|
||||
# =====
|
||||
|
||||
@ -65,28 +65,28 @@ def main() -> None:
|
||||
h_path = os.path.basename(c_path[:-2]) + ".h"
|
||||
name = sys.argv[3]
|
||||
|
||||
with open(jpeg_path, "rb") as jpeg_file:
|
||||
jpeg_data = jpeg_file.read()
|
||||
with open(jpeg_path, "rb") as file:
|
||||
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(
|
||||
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}"
|
||||
|
||||
text = f"{common.C_PREPEND}\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_HEIGHT = {height};\n\n"
|
||||
text += f"const size_t US_{name}_JPEG_DATA_SIZE = {len(jpeg_data)};\n"
|
||||
text += f"const uint8_t US_{name}_JPEG_DATA[] = {jpeg_data_text};\n"
|
||||
text += f"const size_t US_{name}_JPEG_DATA_SIZE = {len(data)};\n"
|
||||
text += f"const uint8_t US_{name}_JPEG_DATA[] = {data_text};\n"
|
||||
|
||||
with open(c_path, "w") as c_file:
|
||||
c_file.write(text)
|
||||
with open(c_path, "w") as file:
|
||||
file.write(text)
|
||||
|
||||
|
||||
# =====
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user