import glob import os import shutil class CleanBuildAll: def __init__(self, base_path=None): # 如果没有提供基准路径,使用当前文件的路径 self.base_path = base_path if base_path else os.path.dirname(os.path.abspath(__file__)) def clean_build_all(self): self.__remove_files(["./*.spec", "./server/*.spec"]) self.__remove_directories([ "./dist", "./build", "./server/dist", "./server/build", "./client/dist", "./client/release" ]) def __remove_files(self, file_patterns): for pattern in file_patterns: abs_pattern = os.path.join(self.base_path, pattern) for file_path in glob.glob(abs_pattern): if os.path.exists(file_path): os.remove(file_path) print(f"Deleted file: {file_path}") def __remove_directories(self, directory_list): for directory in directory_list: abs_dir_path = os.path.join(self.base_path, directory) if os.path.exists(abs_dir_path): shutil.rmtree(abs_dir_path) print(f"Deleted directory: {abs_dir_path}") if __name__ == "__main__": cleaner = CleanBuildAll() cleaner.clean_build_all()