123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- import os
- from utils.include_utils import auto_parse_include
- from utils.other_utils import get_file_suffix, extract_codes_colors, replace_old_color, update_themes, \
- replace_res_utils, bg_white_radius10, bg_btn_ffffff_10dp, add_xml_res_auto, \
- add_import_R, bg_homeindex_item_10, unify_path_separator, \
- get_included_suffix, get_excluded_files, update_deprecated, bg_btn_white_topr10, \
- bg_btn_white_topr12, bg_btn_white_topr16, replace_xml_imageview, replace_xml_textview, \
- replace_system_bar, delete_xml_remark, replace_icon, replace_background, hykb_dimens
- def replace_file_by_path(file_path: str, auto_include_callback=None):
-
- file_path = unify_path_separator(file_path)
- if not os.path.isfile(file_path):
- print(f"{file_path} 不是一个文件")
- return
-
- suffix = get_file_suffix(file_path)
- if suffix not in get_included_suffix():
- print(f"忽略{suffix}格式文件")
- return
-
- file_name = os.path.basename(file_path)
- if file_name in get_excluded_files():
- print(f"{file_name} 是忽略文件")
- return
- print(f"处理文件:{file_path}")
- with open(file_path, 'r', encoding='utf-8') as f:
- text = f.read()
- text = text.replace("\"#ffffffff\"", "\"#ffffff\"")
- text = text.replace("\"#FFFFFFFF\"", "\"#ffffff\"")
-
- auto_parse_include(text, suffix, auto_include_callback)
-
- text = update_deprecated(text)
-
- text = extract_codes_colors(text, suffix)
-
- text = replace_old_color(text)
-
- text = update_themes(text)
-
- text = delete_xml_remark(text)
-
- text = hykb_dimens(text)
- text = bg_white_radius10(text)
- text = bg_homeindex_item_10(text)
- text = bg_btn_ffffff_10dp(text)
-
-
- text = bg_btn_white_topr10(text)
- text = bg_btn_white_topr12(text)
- text = bg_btn_white_topr16(text)
- text = replace_xml_imageview(text)
- text = replace_xml_textview(text)
- text = replace_icon(text)
- text = replace_background(text)
-
- text = text.replace("green_brandDark", "green_brand")
- text = text.replace("green_brand_brand", "green_brand")
- text = text.replace("green_brand_brandDark", "green_brand")
- text = text.replace("green_brandDark", "green_brand")
- text = text.replace("green_brand_08", "green_brand_7")
- text = text.replace("green_brand_brand_word", "green_word")
- text = text.replace("green_brand_word", "green_word")
- text = text.replace("green_brand_hover", "green_hover")
- text = text.replace("green_brand_line", "green_line")
- text = text.replace("green_brand_e0fce7", "green_e0fce7")
- text = text.replace("bg_light_00", "transparent")
- text = text.replace("font_color_ff131715", "black_h1")
- text = text.replace("green_brand_bg", "green_bg")
- text = text.replace("color_ff131715", "black_h1")
- text = text.replace("color_green_", "green_brand_")
-
-
-
-
-
-
- text = add_xml_res_auto(text)
-
- text = replace_res_utils(text, suffix)
-
- text = add_import_R(text, suffix)
-
-
-
-
- text = text.replace("color_333333", "black_h2")
- text = text.replace("color_999999", "black_h4")
-
- text = replace_system_bar(text)
-
- with open(file_path, 'w', encoding='utf-8') as f:
- f.write(text)
|