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

Method clean_by_numbers

script/btcli.py:1140–1219  ·  view source on GitHub ↗

根据编号清理文件

(self, numbers: List[int])

Source from the content-addressed store, hash-verified

1138 print(f" 释放空间: {self.format_size(total_size)}")
1139
1140 def clean_by_numbers(self, numbers: List[int]):
1141 """根据编号清理文件"""
1142 if not self.scan_results:
1143 print(Colors.error("请先执行扫描"))
1144 return
1145
1146 if not self.item_index_map:
1147 print(Colors.error("请先查看扫描结果"))
1148 return
1149
1150 # 验证编号
1151 invalid_numbers = [n for n in numbers if n not in self.item_index_map]
1152 if invalid_numbers:
1153 print(Colors.error(f"无效的编号: {', '.join(map(str, invalid_numbers))}"))
1154 return
1155
1156 # 收集要清理的项目
1157 items_to_clean = []
1158 total_files = 0
1159 total_size = 0
1160
1161 for num in numbers:
1162 item = self.item_index_map[num]
1163 result = item['result']
1164
1165 if result['count'] == 0:
1166 print(Colors.warning(f"编号 {num} ({result['name']}) 没有可清理的文件,已跳过"))
1167 continue
1168
1169 items_to_clean.append({
1170 'number': num,
1171 'name': result['name'],
1172 'files': result['files'],
1173 'count': result['count'],
1174 'size': result['size']
1175 })
1176
1177 total_files += result['count']
1178 total_size += result['size']
1179
1180 if not items_to_clean:
1181 print(Colors.warning("没有可清理的文件"))
1182 return
1183
1184 # 显示即将清理的项目
1185 print(Colors.info("\n准备清理以下项目:"))
1186 for item in items_to_clean:
1187 print(f" [{item['number']}] {item['name']}: {item['count']} 个文件, {self.format_size(item['size'])}")
1188
1189 print(Colors.header(f"\n总计:"))
1190 print(f" 文件数量: {total_files}")
1191 print(f" 释放空间: {self.format_size(total_size)}")
1192
1193 # 二次确认
1194 confirm = input(Colors.warning("\n确认清理以上项目? [y/N]: "))
1195 if confirm.lower() != 'y':
1196 print("已取消")
1197 return

Callers 1

disk_clean_menuMethod · 0.80

Calls 10

format_sizeMethod · 0.95
clean_filesMethod · 0.95
mapFunction · 0.85
headerMethod · 0.80
errorMethod · 0.45
joinMethod · 0.45
warningMethod · 0.45
appendMethod · 0.45
infoMethod · 0.45
successMethod · 0.45

Tested by

no test coverage detected