custom_day_night.py 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. import os
  2. import re
  3. from file_processer import replace_file_by_path
  4. from utils.module_utils import get_modules_from_settings_file
  5. from utils.other_utils import unify_path_separator, get_excluded_dirs
  6. parse_included_files = set()
  7. def replace_action(project_dir: str, included_files: set, included_pattern: set, included_keywords: set):
  8. print("任务开始执行-------------------------------------------\n")
  9. modules = get_modules_from_settings_file(project_dir)
  10. result_paths = set()
  11. for module in modules:
  12. print("-------------------------------------------\n")
  13. module_dir = project_dir + os.path.sep + module.replace(":", os.path.sep)
  14. print(f"检测{module}模块:{module_dir}")
  15. for root, dirs, files in os.walk(module_dir):
  16. excluded_dirs = get_excluded_dirs()
  17. dirs[:] = [d for d in dirs if d not in excluded_dirs]
  18. for file in files:
  19. path = os.path.join(root, file)
  20. file_path = unify_path_separator(path)
  21. # 是否指定文件名称
  22. file_name = os.path.basename(file_path)
  23. if file_name in included_files:
  24. result_paths.add(file_path)
  25. # 是否指定正则表达式
  26. for keyword in included_pattern:
  27. pattern = re.compile(keyword)
  28. if pattern.search(file_path):
  29. result_paths.add(file_path)
  30. # 指定关键字
  31. for keyword in included_keywords:
  32. tmp = unify_path_separator(keyword)
  33. if tmp in file_path:
  34. result_paths.add(file_path)
  35. for path in result_paths:
  36. # 处理文件
  37. print(f"处理文件{path}")
  38. replace_file_by_path(path, lambda layout_name: {
  39. parse_included_files.add(layout_name)
  40. })
  41. if parse_included_files.__len__() != 0:
  42. print(f"处理遍历进来的布局文件{parse_included_files}")
  43. temp = parse_included_files.copy()
  44. parse_included_files.clear()
  45. replace_action(project_dir, temp, set(), set())
  46. if __name__ == '__main__':
  47. project_dir = 'D:\\workspace/android/hykb'
  48. included_files = set()
  49. included_pattern = set()
  50. included_keywords = set()
  51. # 首页
  52. # included_files.add("GameRecommendFragment.java")
  53. # included_files.add("fragment_game_recommend.xml")
  54. # included_files.add("item_jingxuan_gaosu.xml")
  55. # included_keywords.add('/com/xmcy/hykb/app/ui/gamerecommend/')
  56. # 首页精选
  57. # included_files.add("HomeIndexFragment.java")
  58. # included_pattern.add(r"item_homeindex_.*\.xml")
  59. # included_pattern.add(r"item_home_.*\.xml")
  60. # included_keywords.add('/com/xmcy/hykb/app/ui/homeindex/')
  61. # 首页精选负二楼
  62. # included_pattern.add(r"item_two_.*\.xml")
  63. # included_keywords.add('/com/xmcy/hykb/app/ui/gamerecommend/twoleveladapter/')
  64. # 分类-分类tab
  65. # included_files.add("XinQiFragment.java")
  66. # included_pattern.add(r"item_xinqi_.*\.xml")
  67. included_files.add("SettingActivity.java")
  68. included_files.add("TestActivity.java")
  69. included_files.add("DownloadInstallActivity.java")
  70. included_files.add("AccountSafeActivity.java")
  71. included_files.add("activity_account_safe.xml")
  72. included_files.add("account_safe_root_view.xml")
  73. included_files.add("activity_close_account.xml")
  74. included_files.add("activity_close_account_result.xml")
  75. included_files.add("activity_game_time_bind.xml")
  76. included_files.add("game_time_bind_root_view.xml")
  77. included_files.add("activity_phone_and_third_bind.xml")
  78. included_files.add("activity_download_install.xml")
  79. included_files.add("activity_net_permission_check.xml")
  80. included_files.add("activity_teen_mode_setting.xml")
  81. included_files.add("activity_modify_area.xml")
  82. included_files.add("item_modify_area.xml")
  83. included_files.add("activity_bind_phone.xml")
  84. included_files.add("activity_clip_image.xml")
  85. included_files.add("activity_clip_image.xml")
  86. included_files.add("dialog_modify_nick_name.xml")
  87. included_files.add("dialog_modify_signature.xml")
  88. included_files.add("activity_clip_square_image.xml")
  89. included_files.add("activity_clip_rectangle_image.xml")
  90. included_files.add("activity_clip_image.xml")
  91. included_files.add("activity_h5_webview.xml")
  92. included_files.add("activity_privacy_manager.xml")
  93. included_files.add("activity_person_info.xml")
  94. included_files.add("include_person_info_base.xml")
  95. included_files.add("include_person_info_form.xml")
  96. included_files.add("PersonInfoView.java")
  97. included_files.add("PersonInfoItemView.java")
  98. included_files.add("view_person_info.xml")
  99. included_files.add("include_navigate_back_and_title_white.xml")
  100. included_files.add("common_toolbar_2.xml")
  101. included_files.add("layout_teen_mode_setting.xml")
  102. included_files.add("layout_teen_mode_password.xml")
  103. included_files.add("layout_teen_mode_forget_pws.xml")
  104. included_files.add("btn_disable_22dp.xml")
  105. included_files.add("btn_enable_22dp.xml")
  106. included_files.add("bg_default_item_click_eb23c268.xml")
  107. included_files.add("SelectImageBottomDialog.java")
  108. included_files.add("dialog_select_image.xml")
  109. included_files.add("SplashActivity.java")
  110. included_files.add("SplashButton.java")
  111. included_files.add("GuideActivity.java")
  112. included_keywords.add('/com/xmcy/hykb/app/ui/setting/')
  113. included_keywords.add('/com/xmcy/hykb/app/ui/userinfo/')
  114. included_keywords.add('/com/xmcy/hykb/app/ui/accountsafe/')
  115. included_keywords.add('/com/xmcy/hykb/app/ui/teen_mode/')
  116. included_keywords.add('/com/xmcy/hykb/app/ui/netpermissioncheck/')
  117. # 开始处理
  118. replace_action(project_dir, included_files, included_pattern, included_keywords)
  119. print("任务结束-------------------------------------------\n")