All checks were successful
ci/woodpecker/push/check_format Pipeline was successful
89 lines
2.8 KiB
Python
89 lines
2.8 KiB
Python
"""
|
|
Copyright (c) 2024 Elaina <2901432375@qq.com>
|
|
Copyright (c) 2024 zhbaor <zhbaor@zhaozuohong.vip>
|
|
|
|
This file is part of mower-ng (https://git.zhaozuohong.vip/mower-ng/mower-ng).
|
|
|
|
Mower-ng is free software: you may copy, redistribute and/or modify it
|
|
under the terms of the GNU General Public License as published by the
|
|
Free Software Foundation, version 3 or later.
|
|
|
|
This file 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 <http://www.gnu.org/licenses/>.
|
|
"""
|
|
|
|
from pathlib import Path
|
|
|
|
from mower.utils.recognize.data import color, template_matching, template_matching_score
|
|
|
|
res_path_name = "mower/resources/"
|
|
res_path = Path(res_path_name)
|
|
|
|
data = "from typing import Literal\n\nRes = Literal[\n"
|
|
references = {}
|
|
|
|
for i in sorted(res_path.glob("**/*"), key=lambda x: x.as_posix()):
|
|
if not i.is_file():
|
|
continue
|
|
res_name = i.as_posix()
|
|
res_name = res_name.replace(res_path_name, "")
|
|
res_name = res_name.replace(".png", "")
|
|
data += f' "{res_name}",\n'
|
|
references[res_name] = []
|
|
|
|
data += "]\n"
|
|
|
|
with open("mower/utils/typealias/res.py", "w", encoding="utf-8") as f:
|
|
f.write(data)
|
|
|
|
for py_file in sorted(Path("mower").glob("**/*.py"), key=lambda x: x.as_posix()):
|
|
posix_path = py_file.as_posix()
|
|
if posix_path in [
|
|
"mower/utils/typealias/res.py",
|
|
"mower/utils/recognize/data.py",
|
|
]:
|
|
continue
|
|
with py_file.open("r", encoding="utf-8") as f:
|
|
content = f.read()
|
|
for name, matches in references.items():
|
|
if f'"{name}"' in content:
|
|
matches.append(posix_path)
|
|
|
|
for name, matches in references.items():
|
|
if len(matches) > 0:
|
|
print(name)
|
|
for m in matches:
|
|
print(f" {m}")
|
|
for name, matches in references.items():
|
|
if len(matches) == 0:
|
|
print(f"[WARN]{name}")
|
|
if name in color:
|
|
print(" - in color")
|
|
if name in template_matching:
|
|
print(" - in template_matching")
|
|
if name in template_matching_score:
|
|
print(" - in template_matching_score")
|
|
|
|
|
|
def print_dict(data):
|
|
data = list(data.items())
|
|
data.sort(key=lambda x: x[0])
|
|
result = "{\n"
|
|
for key, value in data:
|
|
result += f' "{key}": {value},\n'
|
|
result += "}\n"
|
|
return result
|
|
|
|
|
|
with open("mower/utils/recognize/data.py", "w", encoding="utf-8") as f:
|
|
f.write("color = ")
|
|
f.write(print_dict(color))
|
|
f.write("\ntemplate_matching = ")
|
|
f.write(print_dict(template_matching))
|
|
f.write("\ntemplate_matching_score = ")
|
|
f.write(print_dict(template_matching_score))
|