主函数
()
| 196 | print(f" - {rel_type}: {count}") |
| 197 | |
| 198 | def main(): |
| 199 | """主函数""" |
| 200 | parser = argparse.ArgumentParser( |
| 201 | description='分批处理管理器 - 管理菜谱处理的分批保存和断点续传', |
| 202 | formatter_class=argparse.RawDescriptionHelpFormatter, |
| 203 | epilog=""" |
| 204 | 使用示例: |
| 205 | python batch_manager.py status # 查看处理状态 |
| 206 | python batch_manager.py continue ./HowToCook-master # 继续中断的处理 |
| 207 | python batch_manager.py merge # 合并批次数据 |
| 208 | python batch_manager.py clean-progress # 清理进度文件 |
| 209 | python batch_manager.py clean-batches # 清理批次数据 |
| 210 | python batch_manager.py details # 显示所有批次详情 |
| 211 | python batch_manager.py details -b 1 # 显示指定批次详情 |
| 212 | """) |
| 213 | |
| 214 | subparsers = parser.add_subparsers(dest='command', help='可用命令') |
| 215 | |
| 216 | # status命令 |
| 217 | subparsers.add_parser('status', help='查看处理进度状态') |
| 218 | |
| 219 | # continue命令 |
| 220 | continue_parser = subparsers.add_parser('continue', help='继续中断的处理') |
| 221 | continue_parser.add_argument('recipe_dir', help='菜谱目录路径') |
| 222 | |
| 223 | # merge命令 |
| 224 | subparsers.add_parser('merge', help='合并所有批次数据') |
| 225 | |
| 226 | # clean命令 |
| 227 | subparsers.add_parser('clean-progress', help='清理进度文件') |
| 228 | subparsers.add_parser('clean-batches', help='清理所有批次数据') |
| 229 | |
| 230 | # details命令 |
| 231 | details_parser = subparsers.add_parser('details', help='显示批次详细信息') |
| 232 | details_parser.add_argument('-b', '--batch', type=int, help='指定批次编号') |
| 233 | |
| 234 | # 全局参数 |
| 235 | parser.add_argument('-o', '--output', default='./ai_output', help='输出目录路径') |
| 236 | |
| 237 | args = parser.parse_args() |
| 238 | |
| 239 | if not args.command: |
| 240 | parser.print_help() |
| 241 | return |
| 242 | |
| 243 | # 确保输出目录存在 |
| 244 | os.makedirs(args.output, exist_ok=True) |
| 245 | |
| 246 | print("🛠️ 分批处理管理器") |
| 247 | print("=" * 50) |
| 248 | |
| 249 | try: |
| 250 | if args.command == 'status': |
| 251 | show_progress_status(args.output) |
| 252 | elif args.command == 'continue': |
| 253 | continue_processing(args.recipe_dir, args.output) |
| 254 | elif args.command == 'merge': |
| 255 | merge_batches(args.output) |
no test coverage detected