123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- import os
- import re
- from file_processer import replace_file_by_path
- from utils.module_utils import get_modules_from_settings_file
- from utils.other_utils import unify_path_separator, get_excluded_dirs
- parse_included_files = set()
- def replace_action(project_dir: str, included_files: set, included_pattern: set, included_keywords: set):
- print("任务开始执行-------------------------------------------\n")
- modules = get_modules_from_settings_file(project_dir)
- result_paths = set()
- for module in modules:
- print("-------------------------------------------\n")
- module_dir = project_dir + os.path.sep + module.replace(":", os.path.sep)
- print(f"检测{module}模块:{module_dir}")
- for root, dirs, files in os.walk(module_dir):
- excluded_dirs = get_excluded_dirs()
- dirs[:] = [d for d in dirs if d not in excluded_dirs]
- for file in files:
- path = os.path.join(root, file)
- file_path = unify_path_separator(path)
- # 是否指定文件名称
- file_name = os.path.basename(file_path)
- if file_name in included_files:
- result_paths.add(file_path)
- # 是否指定正则表达式
- for keyword in included_pattern:
- pattern = re.compile(keyword)
- if pattern.search(file_path):
- result_paths.add(file_path)
- # 指定关键字
- for keyword in included_keywords:
- tmp = unify_path_separator(keyword)
- if tmp in file_path:
- result_paths.add(file_path)
- for path in result_paths:
- # 处理文件
- print(f"处理文件{path}")
- replace_file_by_path(path, lambda layout_name: {
- parse_included_files.add(layout_name)
- })
- if parse_included_files.__len__() != 0:
- print(f"处理遍历进来的布局文件{parse_included_files}")
- temp = parse_included_files.copy()
- parse_included_files.clear()
- replace_action(project_dir, temp, set(), set())
- if __name__ == '__main__':
- project_dir = 'D:\\workspace/android/hykb'
- included_files = set()
- included_pattern = set()
- included_keywords = set()
- # 首页
- # included_files.add("GameRecommendFragment.java")
- # included_files.add("fragment_game_recommend.xml")
- # included_files.add("item_jingxuan_gaosu.xml")
- # included_keywords.add('/com/xmcy/hykb/app/ui/gamerecommend/')
- # 首页精选
- # included_files.add("HomeIndexFragment.java")
- # included_pattern.add(r"item_homeindex_.*\.xml")
- # included_pattern.add(r"item_home_.*\.xml")
- # included_keywords.add('/com/xmcy/hykb/app/ui/homeindex/')
- # 首页精选负二楼
- # included_pattern.add(r"item_two_.*\.xml")
- # included_keywords.add('/com/xmcy/hykb/app/ui/gamerecommend/twoleveladapter/')
- # 分类-分类tab
- # included_files.add("XinQiFragment.java")
- # included_pattern.add(r"item_xinqi_.*\.xml")
- included_files.add("SettingActivity.java")
- included_files.add("TestActivity.java")
- included_files.add("DownloadInstallActivity.java")
- included_files.add("AccountSafeActivity.java")
- included_files.add("activity_account_safe.xml")
- included_files.add("account_safe_root_view.xml")
- included_files.add("activity_close_account.xml")
- included_files.add("activity_close_account_result.xml")
- included_files.add("activity_game_time_bind.xml")
- included_files.add("game_time_bind_root_view.xml")
- included_files.add("activity_phone_and_third_bind.xml")
- included_files.add("activity_download_install.xml")
- included_files.add("activity_net_permission_check.xml")
- included_files.add("activity_teen_mode_setting.xml")
- included_files.add("activity_modify_area.xml")
- included_files.add("item_modify_area.xml")
- included_files.add("activity_bind_phone.xml")
- included_files.add("activity_clip_image.xml")
- included_files.add("activity_clip_image.xml")
- included_files.add("dialog_modify_nick_name.xml")
- included_files.add("dialog_modify_signature.xml")
- included_files.add("activity_clip_square_image.xml")
- included_files.add("activity_clip_rectangle_image.xml")
- included_files.add("activity_clip_image.xml")
- included_files.add("activity_h5_webview.xml")
- included_files.add("activity_privacy_manager.xml")
- included_files.add("activity_person_info.xml")
- included_files.add("include_person_info_base.xml")
- included_files.add("include_person_info_form.xml")
- included_files.add("PersonInfoView.java")
- included_files.add("PersonInfoItemView.java")
- included_files.add("view_person_info.xml")
- included_files.add("include_navigate_back_and_title_white.xml")
- included_files.add("common_toolbar_2.xml")
- included_files.add("layout_teen_mode_setting.xml")
- included_files.add("layout_teen_mode_password.xml")
- included_files.add("layout_teen_mode_forget_pws.xml")
- included_files.add("btn_disable_22dp.xml")
- included_files.add("btn_enable_22dp.xml")
- included_files.add("bg_default_item_click_eb23c268.xml")
- included_files.add("SelectImageBottomDialog.java")
- included_files.add("dialog_select_image.xml")
- included_files.add("SplashActivity.java")
- included_files.add("SplashButton.java")
- included_files.add("GuideActivity.java")
- included_keywords.add('/com/xmcy/hykb/app/ui/setting/')
- included_keywords.add('/com/xmcy/hykb/app/ui/userinfo/')
- included_keywords.add('/com/xmcy/hykb/app/ui/accountsafe/')
- included_keywords.add('/com/xmcy/hykb/app/ui/teen_mode/')
- included_keywords.add('/com/xmcy/hykb/app/ui/netpermissioncheck/')
- # 开始处理
- replace_action(project_dir, included_files, included_pattern, included_keywords)
- print("任务结束-------------------------------------------\n")
|