clean_build_all.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import glob
  2. import os
  3. import shutil
  4. import sys
  5. class CleanBuildAll:
  6. def __init__(self, base_path=None):
  7. # 如果没有提供基准路径,使用当前文件的路径
  8. self.base_path = base_path if base_path else os.path.dirname(os.path.abspath(__file__))
  9. def clean_build_all(self):
  10. self.__remove_files(["./*.spec", "./server/*.spec"])
  11. self.__remove_directories([
  12. "./dist",
  13. "./build",
  14. "./server/dist",
  15. "./server/build",
  16. "./client/dist",
  17. "./client/release"
  18. ])
  19. print("Clean complete!")
  20. def __remove_files(self, file_patterns):
  21. for pattern in file_patterns:
  22. abs_pattern = os.path.join(self.base_path, pattern)
  23. for file_path in glob.glob(abs_pattern):
  24. if os.path.exists(file_path):
  25. os.remove(file_path)
  26. print(f"Deleted file: {file_path}")
  27. def __remove_directories(self, directory_list):
  28. for directory in directory_list:
  29. abs_dir_path = os.path.join(self.base_path, directory)
  30. if os.path.exists(abs_dir_path):
  31. shutil.rmtree(abs_dir_path)
  32. print(f"Deleted directory: {abs_dir_path}")
  33. if __name__ == "__main__":
  34. cleaner = CleanBuildAll()
  35. cleaner.clean_build_all()
  36. sys.exit()