remove_unused.py 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. import os
  2. import sys
  3. import json
  4. docs_path = sys.argv[1]
  5. def get_markdown_file(dir_config, base_path):
  6. current_files = []
  7. for row in dir_config:
  8. if row.get('path'):
  9. current_files.append(
  10. f'{base_path}/README.md' if row['path'] == './'
  11. else f'{base_path}/{row["path"]}.md'
  12. )
  13. if row.get('children'):
  14. current_files += get_markdown_file(row['children'], base_path)
  15. return current_files
  16. if __name__ == '__main__':
  17. r = open(f'{docs_path}/directory.json', 'r')
  18. directory_config = json.load(r)
  19. markdown_files = get_markdown_file(directory_config['cn'], f'{docs_path}/zh_CN')
  20. markdown_files += get_markdown_file(directory_config['en'], f'{docs_path}/en_US')
  21. for file_path, dir_list, file_list in os.walk(docs_path):
  22. for file_name in file_list:
  23. if not file_name.endswith('.md'):
  24. continue
  25. if os.path.join(file_path, file_name) not in markdown_files:
  26. print(f'Remove {os.path.join(file_path, file_name)}')
  27. os.remove(os.path.join(file_path, file_name))