clean_build_all.py 1.3 KB

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