MCPcopy Create free account
hub / github.com/aaPanel/BaoTa / clean_all

Method clean_all

script/btcli.py:1221–1271  ·  view source on GitHub ↗

清理所有分类

(self, enabled_only: bool = True)

Source from the content-addressed store, hash-verified

1219 print(f" 释放空间: {self.format_size(total_size)}")
1220
1221 def clean_all(self, enabled_only: bool = True):
1222 """清理所有分类"""
1223 if not self.scan_results:
1224 print(Colors.error("请先执行扫描"))
1225 return
1226
1227 total_files = 0
1228 total_size = 0
1229
1230 # 统计总量
1231 for category_name, category_data in self.scan_results.items():
1232 for rule_key, result in category_data.items():
1233 if enabled_only and not result['status']:
1234 continue
1235 total_files += result['count']
1236 total_size += result['size']
1237
1238 if total_files == 0:
1239 print(Colors.warning("没有可清理的文件"))
1240 return
1241
1242 # 显示清理信息
1243 print(Colors.info("\n准备清理所有分类"))
1244 print(f" 文件数量: {total_files}")
1245 print(f" 释放空间: {self.format_size(total_size)}")
1246
1247 # 确认
1248 confirm = input(Colors.warning("\n确认清理所有文件? [y/N]: "))
1249 if confirm.lower() != 'y':
1250 print("已取消")
1251 return
1252
1253 print(Colors.info("\n开始清理..."))
1254
1255 # 逐个分类清理
1256 for category_name in self.scan_results.keys():
1257 category_data = self.scan_results[category_name]
1258 rule_keys = [key for key, data in category_data.items()
1259 if (not enabled_only or data['status']) and data['count'] > 0]
1260
1261 if rule_keys:
1262 print(f"\n{Colors.header(f'[ {category_name.upper()} ]')}")
1263
1264 for rule_key in rule_keys:
1265 result = category_data[rule_key]
1266 print(f"\n 清理 {Colors.info(result['name'])}...")
1267 success, failed = self.clean_files(result['files'], show_progress=True)
1268 print(f" {Colors.success(f'成功: {success}')} | {Colors.error(f'失败: {failed}')}")
1269
1270 print(Colors.success(f"\n✓ 全部清理完成!"))
1271 print(f" 总计释放空间: {self.format_size(total_size)}")
1272
1273
1274# ============================================

Callers 1

mainFunction · 0.95

Calls 9

format_sizeMethod · 0.95
clean_filesMethod · 0.95
headerMethod · 0.80
errorMethod · 0.45
itemsMethod · 0.45
warningMethod · 0.45
infoMethod · 0.45
keysMethod · 0.45
successMethod · 0.45

Tested by

no test coverage detected