|
| 1 | +import os |
| 2 | +import pandas as pd |
| 3 | + |
| 4 | +def check_files(root_dir, file_list): |
| 5 | + data = [] |
| 6 | + folders_checked = set() |
| 7 | + for projects in sconstruct_paths: |
| 8 | + if projects not in folders_checked: |
| 9 | + file_dict = {file: '✔' if os.path.isfile(os.path.join(projects, file)) else '' for file in file_list} |
| 10 | + data.append({'Folder': projects, **file_dict}) |
| 11 | + folders_checked.add(projects) |
| 12 | + df = pd.DataFrame(data) |
| 13 | + return df |
| 14 | + |
| 15 | +def find_sconstruct_paths(project_dir, exclude_paths): |
| 16 | + sconstruct_paths = [] |
| 17 | + for root, dirs, files in os.walk(project_dir): |
| 18 | + if all(exclude_path not in root for exclude_path in exclude_paths): |
| 19 | + if 'SConstruct' in files: |
| 20 | + sconstruct_paths.append(root) |
| 21 | + return sconstruct_paths |
| 22 | + |
| 23 | +def output_to_markdown(df, output_file): |
| 24 | + with open(output_file, 'w', encoding='utf-8') as file: |
| 25 | + file.write(df.to_markdown(index=False)) |
| 26 | + |
| 27 | +# 示例用法: |
| 28 | +BSP_ROOT = '.' |
| 29 | +exclude_paths = ['templates', 'doc'] |
| 30 | +files_to_check = ['rtconfig.h','rtconfig.py', '.config','Kconfig', 'template.uvprojx','template.ewp', 'README.md', 'README_ZH.md','SConscript', 'template.Uv2','template.uvproj'] |
| 31 | +sconstruct_paths = find_sconstruct_paths('.', exclude_paths) |
| 32 | +result_table = check_files(sconstruct_paths, files_to_check) |
| 33 | +print(result_table) |
| 34 | +#output_file = 'output.md' |
| 35 | +#output_to_markdown(result_table, output_file) |
| 36 | +output_file = 'output.csv' |
| 37 | +result_table.to_csv(output_file, index=False) |
0 commit comments