1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- 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())
|