清理指定分类
(self, category_name: str, rule_keys: List[str] = None)
| 1070 | return success, failed |
| 1071 | |
| 1072 | def clean_category(self, category_name: str, rule_keys: List[str] = None): |
| 1073 | """清理指定分类""" |
| 1074 | if category_name not in self.scan_results: |
| 1075 | print(Colors.error(f"分类不存在: {category_name}")) |
| 1076 | return |
| 1077 | |
| 1078 | category_data = self.scan_results[category_name] |
| 1079 | |
| 1080 | # 如果没有指定规则,清理所有启用的规则 |
| 1081 | if not rule_keys: |
| 1082 | rule_keys = [key for key, data in category_data.items() if data['status']] |
| 1083 | |
| 1084 | total_files = 0 |
| 1085 | total_size = 0 |
| 1086 | |
| 1087 | for rule_key in rule_keys: |
| 1088 | if rule_key not in category_data: |
| 1089 | continue |
| 1090 | |
| 1091 | result = category_data[rule_key] |
| 1092 | total_files += result['count'] |
| 1093 | total_size += result['size'] |
| 1094 | |
| 1095 | if total_files == 0: |
| 1096 | print(Colors.warning("没有可清理的文件")) |
| 1097 | return |
| 1098 | |
| 1099 | # 显示清理信息 |
| 1100 | print(Colors.info(f"\n准备清理 {category_name} 分类")) |
| 1101 | print(f" 文件数量: {total_files}") |
| 1102 | print(f" 释放空间: {self.format_size(total_size)}") |
| 1103 | |
| 1104 | # 确认 |
| 1105 | confirm = input(Colors.warning("\n确认清理? [y/N]: ")) |
| 1106 | if confirm.lower() != 'y': |
| 1107 | print("已取消") |
| 1108 | return |
| 1109 | |
| 1110 | print(Colors.info("\n开始清理...")) |
| 1111 | |
| 1112 | # 执行清理 |
| 1113 | total_success = 0 |
| 1114 | total_failed = 0 |
| 1115 | |
| 1116 | for rule_key in rule_keys: |
| 1117 | if rule_key not in category_data: |
| 1118 | continue |
| 1119 | |
| 1120 | result = category_data[rule_key] |
| 1121 | |
| 1122 | if result['count'] == 0: |
| 1123 | continue |
| 1124 | |
| 1125 | print(f"\n 清理 {Colors.info(result['name'])}...") |
| 1126 | success, failed = self.clean_files(result['files'], show_progress=True) |
| 1127 | |
| 1128 | total_success += success |
| 1129 | total_failed += failed |
no test coverage detected