Commit 88bcf7b3 authored by dovahkiin's avatar dovahkiin

初版

parent 90541376
./build/
./dist/
./vscode/
check_img.spec
# check_image # check_image
----2023年12月11日
打开文件check_img_config.txt
根据工程为flything或者awtk在文件第一行写上flything或者awtk
该文件读取方式为逐行读取,请保证文件行数为6,
以下描述将flything与awtk分开
flything:
第二行:写入图片文件夹路径,写到resources目录即可
第三行:写入需要用到切换主题或者中英的路径头(没有不写),如果有多个请使用|分割开来(注意路径,写resources后面的就行)
第四行:写入编写的代码的路径
第五行:如果代码中有用到%s的情况,请将可能的情况填入到该行,如果有多个请使用|分割开来。不使用|进行隔开的话,将默认逐个分开
第六行:屏蔽的检索,可以根据最后的结果以及代码中字符串的部分进行屏蔽
awtk:
第二行:写入图片文件夹路径,请写到x1目录,如果有多个请使用|分割开来
第三行:写入xml的路径,如果有多个请使用|分割开来
第四行:写入编写的代码的路径
第五行:如果代码中有用到%s的情况,请将可能的情况填入到该行,如果有多个请使用|分割开来。不使用|进行隔开的话,将默认逐个分开
第六行:屏蔽的检索,可以根据最后的结果以及代码中字符串的部分进行屏蔽
已知的问题:
会出现未调用的图片,无法解决,建议第六行屏蔽
如%02d这种格式化方法,没有添加对应的处理方法,建议手动查
会出现将字符串认为是图片的情况,无法解决,建议第六行屏蔽
------------------------代码里的路径是直接写出来的 可以直接处理---------------------------------------------------------------
import re
import os
def check_image_path(filename):
with open(filename, "r") as f:
content = f.read()
# 使用正则表达式来匹配图片路径
image_paths = re.findall(r"(.*?\.(jpg|jpeg|png|gif))", content)
# 检查图片是否存在
for image_path in image_paths:
if not os.path.exists(image_path):
print(f"图片 {image_path} 不存在")
if __name__ == "__main__":
filename = "test.c"
check_image_path(filename)
--------------------------------代码里的路径是用sprintf 拼的路径要做如下处理------------------------------------------------
import re
import os
def check_image_path(filename):
with open(filename, "r") as f:
content = f.read()
# 使用正则表达式来匹配图片路径
image_paths = re.findall(r"(.*?\.(jpg|jpeg|png|gif))", content)
# 检查图片是否存在
for image_path in image_paths:
# 使用正则表达式来匹配 %d
number = re.findall(r"\%d", image_path)[0]
# 使用 number 来格式化路径
image_path = image_path.replace("%d", str(number))
image_path = os.path.join(os.path.dirname(filename), image_path)
if not os.path.exists(image_path):
print(f"图片 {image_path} 不存在")
if __name__ == "__main__":
filename = "set_number_white_20.c"
check_image_path(filename)
---------------------------------一行里有2个路径的 要做分割处理-------------------------------------------
import re
import os
def check_image_path(filename):
with open(filename, "r") as f:
content = f.read()
# 使用正则表达式来匹配两个文件路径
image_paths = re.findall(r"(.*?\.(jpg|jpeg|png|gif))\s+(.*?\.(jpg|jpeg|png|gif))", content)
# 检查图片是否存在
for image_path in image_paths:
image_path = os.path.join(os.path.dirname(filename), image_path)
if not os.path.exists(image_path):
print(f"图片 {image_path} 不存在")
if __name__ == "__main__":
filename = "set_number_white_20.c"
check_image_path(filename)
import re
import os
def check_image_path(filename):
with open(filename, "r") as f:
content = f.read()
# 使用正则表达式来匹配图片路径
image_paths = re.findall(r"(.*?\.(jpg|jpeg|png|gif))", content)
# 检查图片是否存在
for image_path in image_paths:
if not os.path.exists(image_path):
print(f"图片 {image_path} 不存在")
if __name__ == "__main__":
filename = "test.c"
check_image_path(filename)
File added
import os
import re
awtk = 'awtk'
flything = 'flything'
xml_s = []
head_s = []
# 从配置文件中,读取信息
with open('./check_img_config.txt', encoding="utf-8") as f:
# 读取编译类型
compile_tyep = f.readline().lower()[:-1]
if not compile_tyep in ['flything', 'awtk']:
print(f"error:compile type:'{compile_tyep}' is mistake!!")
exit()
# 读取图片路径
pic_path = f.readline()[:-1]
pic_path = pic_path.split('|')
for pic_path_i in pic_path:
if not os.path.exists(pic_path_i):
print(f"error:image's path:'{pic_path}' is inexistence!!")
exit()
# 读取资源文件路径(awtk)
xml_or_path_head = f.readline()[:-1]
if compile_tyep == awtk:
xml_or_path_head = xml_or_path_head.split('|')
# 读取路径头
# 读取代码路径
codes_path = f.readline()[:-1]
if not os.path.exists(codes_path):
print(f"error:code's path:'{codes_path}' is inexistence!!")
exit()
# 读取%s的信息
format_info = f.readline()[:-1]
if '|' in format_info:
format_info = format_info.split('|')
else:
format_info = [i for i in format_info]
# 读取排除的信息
exclude_infos = [i for i in f.readline().split("|")]
def find_image(root_path, image_name):
# # 遍历指定路径及其子目录
# for root, dirs, files in os.walk(root_path):
# # 检查当前目录中文件列表
# if image_name in files:
# # 如果找到图片,返回完整路径
# return os.path.join(root, image_name)
# # 如果未找到,则返回None
# return None
if os.path.exists(root_path + image_name):
return True
else:
# print(root_path + image_name)
return None # 未找到文件,返回None
def check_image(image_path:str):
if '%d' in image_path:
for i in range(10):
check_image(image_path.replace('%d', f'{i}', 1))
return
elif '%s' in image_path:
for i in format_info:
check_image(image_path.replace('%s', f'{i}', 1))
return
elif '%u' in image_path:
for i in range(10):
check_image(image_path.replace('%u', f'{i}', 1))
return
flag_pic_inexistence_path = 0
for pic_path_i in pic_path:
if compile_tyep == awtk:
if not find_image(pic_path_i+'\\', image_path) and image_path not in exclude_infos:
# print(f"图片{image_path}不存在[{pic_path_i}]")
flag_pic_inexistence_path+=1
# else:
# print(f"图片 {image_path} 存在")
elif compile_tyep == flything:
if not find_image(pic_path_i, image_path) and image_path not in exclude_infos:
for head in head_s:
if find_image(pic_path_i, head+image_path):
continue
else:
print(f"图片{head+image_path}不存在")
# else:
# print(f"图片 {image_path} 存在")
if compile_tyep == awtk:
if flag_pic_inexistence_path == len(pic_path):
print(f"图片{image_path}不存在")
# 读取awtk文件的内容
if compile_tyep == 'awtk':
for xml_i in xml_or_path_head:
with open(xml_i, encoding='utf-8') as xml_f:
xml_data = xml_f.read()
# for xml_line in xml_data.split('<'):
ctl_name = re.findall('<.*?name="(.*?)"', xml_data)
if ctl_name:
xml_s+=ctl_name
elif compile_tyep == 'flything':
# 处理路径头
for path_i in xml_or_path_head.split('|'):
head_s.append(path_i)
pass
def check_code_to_imgs(code_file):
img_names = []
try:
with open(code_file, encoding='utf-8') as cf:
content = cf.read()
except:
with open(code_file, encoding='gbk') as cf:
content = cf.read()
# 使用正则表达式来匹配图片路径
# image_paths = re.findall(r"(.*?\.(jpg|jpeg|png|gif))", content)
# image_paths = re.findall('"(.*?)"', content)
for cont_line in content.split('\n'):
if not cont_line.strip() or cont_line.strip()[:2] == '//' or cont_line.strip()[0] == '#' or ("printf" in cont_line and "sprintf" not in cont_line) or "extern" in cont_line or cont_line.strip()[0] == '*' or cont_line.strip()[:4] == 'LOGD':
continue
image_paths = re.findall('"(.*?)"', cont_line)
if compile_tyep == awtk:
for str_image_or_ctl in image_paths:
if str_image_or_ctl in exclude_infos:
continue
if not str_image_or_ctl in xml_s:
# if str_image_or_ctl.strip()[:2] == '//':
img_names.append(str_image_or_ctl +".png")
elif compile_tyep == flything:
for str_image_or_ctl in image_paths:
if str_image_or_ctl in exclude_infos:
continue
img_names.append(str_image_or_ctl)
return img_names
# print(compile_tyep,pic_path,codes_path,format_info)
# 查找代码路径下所有的文件
if __name__ == '__main__':
for root, dirs, files in os.walk(codes_path):
# print(files)
# print(fles)
for file_item in files:
if os.path.splitext(file_item)[-1][1:] in ["cc", "c", "cpp", "h"]:
for img in check_code_to_imgs(root + '\\' + file_item):
check_image(img)
awtk
.\awtk-app\designer\user_apps\FS04_ARK1668E\design
.\awtk-app\designer\user_apps\FS04_ARK1668E\design\default\ui\home_page.xml
.\awtk-app\designer\user_apps\FS04_ARK1668E\src
abcdef
门开报警(指示车速大于3km/h时)车体在右侧报警界面|md5sum %s | awk \'{print $1}\' > %s
\ No newline at end of file
#include <stdio.h>
int main() {
char *image_path = "/path/to/image.png";
printf("图片路径:%s\n", image_path);
return 0;
}
----2023年12月11日
打开文件check_img_config.txt
根据工程为flything或者awtk在文件第一行写上flything或者awtk
该文件读取方式为逐行读取,请保证文件行数为6,
以下描述将flything与awtk分开
flything:
第二行:写入图片文件夹路径,写到resources目录即可
第三行:写入需要用到切换主题或者中英的路径头(没有不写),如果有多个请使用|分割开来(注意路径,写resources后面的就行)
第四行:写入编写的代码的路径
第五行:如果代码中有用到%s的情况,请将可能的情况填入到该行,如果有多个请使用|分割开来。不使用|进行隔开的话,将默认逐个分开
第六行:屏蔽的检索,可以根据最后的结果以及代码中字符串的部分进行屏蔽
awtk:
第二行:写入图片文件夹路径,请写到x1目录,如果有多个请使用|分割开来
第三行:写入xml的路径,如果有多个请使用|分割开来
第四行:写入编写的代码的路径
第五行:如果代码中有用到%s的情况,请将可能的情况填入到该行,如果有多个请使用|分割开来。不使用|进行隔开的话,将默认逐个分开
第六行:屏蔽的检索,可以根据最后的结果以及代码中字符串的部分进行屏蔽
已知的问题:
会出现未调用的图片,无法解决,建议第六行屏蔽
如%02d这种格式化方法,没有添加对应的处理方法,建议手动查
会出现将字符串认为是图片的情况,无法解决,建议第六行屏蔽
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment