123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- 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_background, hykb_dimens, replace_back_icon, \
- replace_arrow_icon
- 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()
-
- 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 = 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_arrow_icon(text)
- text = replace_back_icon(text)
- text = replace_background(text)
-
- text = add_xml_res_auto(text)
-
- text = replace_res_utils(text, suffix)
-
- text = add_import_R(text, suffix)
-
-
-
-
-
- text = replace_system_bar(text)
-
- with open(file_path, 'w', encoding='utf-8') as f:
- f.write(text)
|